applicationContext.xml中配置
下面是加载外部配置文件:application.properties
- <bean
- class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
- <property name="systemPropertiesModeName" value="SYSTEM_PROPERTIES_MODE_OVERRIDE" />
- <property name="ignoreResourceNotFound" value="true" />
- <property name="locations">
- <list>
- <!-- 标准配置 -->
- <value>classpath*:/application.properties</value>
- </property>
- </bean>
多数据源配置:
- <!-- 本地数据库配置 -->
- <bean id="dataSourceContent" class="com.atomikos.jdbc.AtomikosDataSourceBean" init-method="init" destroy-method="close">
- <property name="uniqueResourceName">
- <value>jdbc/dataSourceContent</value>
- </property>
- <property name="xaDataSourceClassName">
- <value>com.mysql.jdbc.jdbc2.optional.MysqlXADataSource</value>
- </property>
- <property name="xaProperties">
- <props>
- <prop key="serverName">${jdbc.servername}</prop>
- <prop key="portNumber">${jdbc.portnumber}</prop>
- <prop key="databaseName">${jdbc.databasename}</prop>
- <prop key="user">${jdbc.username}</prop>
- <prop key="password">${jdbc.password}</prop>
- </props>
- </property>
- <property name="poolSize">
- <value>5</value>
- </property>
- <property name="maxPoolSize">
- <value>15</value>
- </property>
- <property name="testQuery">
- <value>select 1</value>
- </property>
- </bean>
- <bean id="dataSourceIndex" class="com.atomikos.jdbc.AtomikosDataSourceBean" init-method="init" destroy-method="close">
- <property name="uniqueResourceName">
- <value>jdbc/dataSourceIndex</value>
- </property>
- <property name="xaDataSourceClassName">
- <value>com.mysql.jdbc.jdbc2.optional.MysqlXADataSource</value>
- </property>
- <property name="xaProperties">
- <props>
- <prop key="serverName">${jdbc.servername_index}</prop>
- <prop key="portNumber">${jdbc.portnumber_index}</prop>
- <prop key="databaseName">${jdbc.databasename_index}</prop>
- <prop key="user">${jdbc.username_index}</prop>
- <prop key="password">${jdbc.password_index}</prop>
- </props>
- </property>
- <property name="poolSize">
- <value>5</value>
- </property>
- <property name="maxPoolSize">
- <value>15</value>
- </property>
- <property name="testQuery">
- <value>select 1</value>
- </property>
- </bean>
Hibernate sessionFactory配置:
- <!-- Hibernate配置 -->
- <!-- 本地数据库Hibernate配置 -->
- <bean id="sessionFactoryContent" class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
- <property name="dataSource" ref="dataSourceContent" />
- <property name="namingStrategy">
- <bean class="org.hibernate.cfg.ImprovedNamingStrategy" />
- </property>
- <property name="hibernateProperties">
- <props>
- <prop key="hibernate.dialect">org.hibernate.dialect.MySQL5InnoDBDialect</prop>
- <prop key="hibernate.show_sql">${hibernate.show_sql}</prop>
- <prop key="hibernate.format_sql">${hibernate.format_sql}</prop>
- <prop key="hibernate.cache.provider_class">org.hibernate.cache.EhCacheProvider</prop>
- <prop key="hibernate.cache.provider_configuration_file_resource_path">ehcache/ehcache-hibernate-local.xml</prop>
- </props>
- </property>
- <property name="packagesToScan" value="com.wiseweb.pom.entity" />
- </bean>
- <!-- 远程数据库Hibernate配置 -->
- <bean id="sessionFactoryIndex" class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
- <property name="dataSource" ref="dataSourceIndex" />
- <property name="namingStrategy">
- <bean class="org.hibernate.cfg.ImprovedNamingStrategy" />
- </property>
- <property name="hibernateProperties">
- <props>
- <prop key="hibernate.dialect">org.hibernate.dialect.MySQL5InnoDBDialect</prop>
- <prop key="hibernate.show_sql">${hibernate.show_sql}</prop>
- <prop key="hibernate.format_sql">${hibernate.format_sql}</prop>
- <prop key="hibernate.cache.provider_class">org.hibernate.cache.EhCacheProvider</prop>
- <prop key="hibernate.cache.provider_configuration_file_resource_path">ehcache/ehcache-hibernate-local.xml</prop>
- </props>
- </property>
- <property name="packagesToScan" value="com.wiseweb.pom.entity" />
- </bean>
事务管理器配置:
- <!-- 事务管理器配置,多数据源JTA事务-->
- <bean id="atomikosTransactionManager" class="com.atomikos.icatch.jta.UserTransactionManager" init-method="init" destroy-method="close">
- <property name="forceShutdown"><value>true</value></property>
- </bean>
- <bean id="atomikosUserTransaction" class="com.atomikos.icatch.jta.UserTransactionImp">
- <property name="transactionTimeout" value="300"/>
- </bean>
- <bean id="transactionManager" class="org.springframework.transaction.jta.JtaTransactionManager">
- <property name="transactionManager" ref="atomikosTransactionManager" />
- <property name="userTransaction" ref="atomikosUserTransaction"/>
- </bean>
- <!-- 使用annotation定义事务 -->
- <tx:annotation-driven transaction-manager="transactionManager"
- proxy-target-class="true" />
application.properties文件:
- jdbc.driver=com.mysql.jdbc.Driver
- jdbc.servername=host
- jdbc.portnumber=port
- jdbc.databasename=databasename
- jdbc.url=jdbc\:mysql\://host\:port/databaseName?useUnicode\=true&zeroDateTimeBehavior\=convertToNull&characterEncoding\=utf-8
- jdbc.username=username
- jdbc.password=password
- hibernate.dialect=org.hibernate.dialect.MySQL5InnoDBDialect
- #mysql version database setting
- jdbc.servername_index=host
- jdbc.portnumber_index=port
- jdbc.databasename_index=databaseName
- jdbc.url_index=jdbc\:mysql\://host\:port/databaseName?useUnicode\=true&zeroDateTimeBehavior\=convertToNull&characterEncoding\=utf-8
- jdbc.username_index=username
- jdbc.password_index=password
- #hibernate settings
- hibernate.show_sql=false
- hibernate.format_sql=false
- hibernate.use_second_level_cache=false
- hibernate.use_query_cache=false
- #dbcp settings
- dbcp.maxIdle=5
- dbcp.maxActive=40
- com.atomikos.icatch.service=com.atomikos.icatch.standalone.UserTransactionServiceFactory
- com.atomikos.icatch.console_file_name = sm.out
- com.atomikos.icatch.log_base_name = smlog.log
- com.atomikos.icatch.tm_unique_name = com.atomikos.spring.jdbc.tm
- com.atomikos.icatch.serializable_logging=false