4
回答
请问s2jh如何修改mysql数据库看demo
利用AWS快速构建适用于生产的无服务器应用程序,免费试用12个月>>>   

@S2JH 你好,想跟你请教个问题:我想在mysql数据库上演示你的prototype,如何修改数据库配置,弄了好久没有成功,能不能详细解答一下,非常的感谢。还有多项目依赖那个开发有相关资料吗,我参考一下

举报
hua_wei
发帖于3年前 4回/264阅
共有4个答案 最后回答: 3年前
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:jdbc="http://www.springframework.org/schema/jdbc" xmlns:jee="http://www.springframework.org/schema/jee"
    xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.1.xsd
    http://www.springframework.org/schema/jdbc http://www.springframework.org/schema/jdbc/spring-jdbc-3.1.xsd
    http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-3.1.xsd"
    default-lazy-init="false">

    <beans profile="development">
        <!-- 缺省PropertyPlaceholder定义 -->
        <bean class="lab.s2jh.ctx.ExtPropertyPlaceholderConfigurer">
            <property name="locations">
                <list>
                    <value>classpath:/application.properties</value>
                    <value>classpath:/application_prd.properties</value>
                </list>
            </property>
            <property name="ignoreResourceNotFound" value="true" />
            <property name="systemPropertiesModeName" value="SYSTEM_PROPERTIES_MODE_OVERRIDE" />
        </bean>

        <!-- H2文件模式数据库,实际开发替换成其他MySQL、Oracle等数据库配置即可,注意别忘了在pom.xml中添加对应数据库驱动的依赖 -->
        <bean id="dataSourceSpied" class="org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseFactoryBean">
            <property name="databaseName" value="${user.dir}/h2/prototype" />
            <property name="databaseConfigurer">
                <bean class="lab.s2jh.core.dao.h2.H2EmbeddedFileDatabaseConfigurer" />
            </property>
        </bean>

        <!-- 定制log4jdbc做一些输出SQL信息的微调 -->
        <bean id="extSlf4jSpyLogDelegator" class="lab.s2jh.core.dao.log4jdbc.ExtSlf4jSpyLogDelegator" />

        <!-- 用log4jdbc对datasouce进行包裹实现完整的SQL语句跟踪 -->
        <bean id="dataSource" class="net.sf.log4jdbc.Log4jdbcProxyDataSource" depends-on="extSlf4jSpyLogDelegator">
            <constructor-arg>
                <ref bean="dataSourceSpied" />
            </constructor-arg>
        </bean>

        <jdbc:initialize-database data-source="dataSource" ignore-failures="ALL"
            enabled="${jdbc.initialize.database.enable}">

            <jdbc:script location="classpath:sql/ddl/quartz/tables_h2.sql" encoding="UTF-8" />

            <jdbc:script location="classpath:sql/data/t_sys_data_dict.sql" encoding="UTF-8" />
            <jdbc:script location="classpath:sql/data/t_sys_menu.sql" encoding="UTF-8" />
            <jdbc:script location="classpath:sql/data/t_auth_privilege.sql" encoding="UTF-8" />
            <jdbc:script location="classpath:sql/data/t_auth_role.sql" encoding="UTF-8" />
            <jdbc:script location="classpath:sql/data/t_auth_department.sql" encoding="UTF-8" />
            <jdbc:script location="classpath:sql/data/t_auth_user.sql" encoding="UTF-8" />
            <jdbc:script location="classpath:sql/data/t_auth_user_r2_role.sql" encoding="UTF-8" />
            <jdbc:script location="classpath:sql/data/t_sys_pub_post.sql" encoding="UTF-8" />
            
            <jdbc:script location="classpath:sql/data/biz_finance_account_subject.sql" encoding="UTF-8" />
        </jdbc:initialize-database>

        <bean id="mockDataGenerator" class="lab.s2jh.biz.util.MockDataGenerator" init-method="initializeDatabase">
            <property name="enabled" value="${jdbc.initialize.database.enable}" />
            <property name="entityManagerFactory" ref="entityManagerFactory" />
            <property name="transactionManager" ref="transactionManager" />
        </bean>

        <import resource="classpath:/service/spring*.xml" />
    </beans>

    <beans profile="production">
        <!-- 缺省PropertyPlaceholder定义 -->
        <bean class="lab.s2jh.ctx.ExtPropertyPlaceholderConfigurer">
            <property name="locations">
                <list>
                    <value>classpath:/application.properties</value>
                    <value>classpath:/application_prd.properties</value>
                </list>
            </property>
            <property name="ignoreResourceNotFound" value="true" />
            <property name="systemPropertiesModeName" value="SYSTEM_PROPERTIES_MODE_OVERRIDE" />
        </bean>

        <jee:jndi-lookup id="dataSourceSpied" jndi-name="java:comp/env/jdbc/s2jh" />

        <!-- 定制log4jdbc做一些输出SQL信息的微调 -->
        <bean id="extSlf4jSpyLogDelegator" class="lab.s2jh.core.dao.log4jdbc.ExtSlf4jSpyLogDelegator" />

        <!-- 用log4jdbc对datasouce进行包裹实现完整的SQL语句跟踪 -->
        <bean id="dataSource" class="net.sf.log4jdbc.Log4jdbcProxyDataSource" depends-on="extSlf4jSpyLogDelegator">
            <constructor-arg>
                <ref bean="dataSourceSpied" />
            </constructor-arg>
        </bean>

        <jdbc:initialize-database data-source="dataSource" ignore-failures="ALL"
            enabled="${jdbc.initialize.database.enable}">

            <jdbc:script location="classpath*:sql/ddl/quartz/tables_mysql.sql" encoding="UTF-8" />

            <jdbc:script location="classpath:sql/data/t_sys_data_dict.sql" encoding="UTF-8" />
            <jdbc:script location="classpath:sql/data/t_sys_menu.sql" encoding="UTF-8" />
            <jdbc:script location="classpath:sql/data/t_auth_privilege.sql" encoding="UTF-8" />
            <jdbc:script location="classpath:sql/data/t_auth_role.sql" encoding="UTF-8" />
            <jdbc:script location="classpath:sql/data/t_auth_user.sql" encoding="UTF-8" />
            <jdbc:script location="classpath:sql/data/t_auth_user_r2_role.sql" encoding="UTF-8" />
            <jdbc:script location="classpath:sql/data/t_sys_pub_post.sql" encoding="UTF-8" />
        </jdbc:initialize-database>

        <import resource="classpath:/service/spring*.xml" />
    </beans>

    <!-- 用于Unit Test配置 -->
    <beans profile="test">
        <!-- 缺省PropertyPlaceholder定义 -->
        <bean class="lab.s2jh.ctx.ExtPropertyPlaceholderConfigurer">
            <property name="locations">
                <list>
                    <value>classpath:/application.properties</value>
                    <value>classpath:/application-test.properties</value>
                </list>
            </property>
            <property name="ignoreResourceNotFound" value="true" />
            <property name="systemPropertiesModeName" value="SYSTEM_PROPERTIES_MODE_OVERRIDE" />
        </bean>

        <!-- 嵌入式内存中数据库 -->
        <jdbc:embedded-database id="dataSourceSpied" type="H2">
            <jdbc:script location="classpath:sql/ddl/quartz/tables_h2.sql" encoding="UTF-8" />
        </jdbc:embedded-database>

        <bean id="dataSource" class="net.sf.log4jdbc.Log4jdbcProxyDataSource">
            <constructor-arg>
                <ref bean="dataSourceSpied" />
            </constructor-arg>
        </bean>
    </beans>
</beans>




<bean id="dataSourceSpied" class="org.apache.commons.dbcp.BasicDataSource"
			destroy-method="close">
			<property name="driverClassName" value="com.mysql.jdbc.Driver" />
			<property name="url" value="jdbc:mysql://localhost:3306/s2jh" />
			<property name="username" value="root" />
			<property name="password" value="root" />
			<!-- Connection Pooling Info -->
			<property name="initialSize" value="1" />
			<property name="maxActive" value="3" />
			<property name="minIdle" value="1" />
			<property name="maxIdle" value="5" />
			<property name="maxWait" value="30000" />
			<property name="removeAbandoned">
				<value>true</value>
			</property>
			<property name="removeAbandonedTimeout">
				<value>180</value>
			</property>
			<property name="poolPreparedStatements" value="false" />
			<property name="defaultAutoCommit" value="true" />

</bean>




改掉上面的配置,quartz改成mysql。差不多了



顶部