Files
MaxKey/maxkey-web-maxkey/src/main/resources/spring/maxkey-persistence.xml

121 lines
5.0 KiB
XML
Raw Normal View History

2019-04-29 23:53:10 +08:00
<?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:aop="http://www.springframework.org/schema/aop"
xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:jdbc="http://www.springframework.org/schema/jdbc"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context.xsd
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/jdbc
http://www.springframework.org/schema/jdbc/spring-jdbc.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop.xsd">
<!-- dataSource define begin -->
<!-- c3p0 configuration -->
<bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource" destroy-method="close" >
<property name="driverClass" value="#{dataSoruceConfig.driverClass}"/>
<property name="jdbcUrl" value="#{dataSoruceConfig.url}"/>
<property name="user" value="#{dataSoruceConfig.username}"/>
<property name="password" value="#{dataSoruceConfig.password}"/>
</bean>
<!-- JNDI data source configuration -->
<!-- jndiName is jndi name -->
<!-- if you don,t want use prefix 'java:comp/env/' set resourceRef to true,default is false -->
<!--
<bean id="dataSource" class="org.springframework.jndi.JndiObjectFactoryBean">
<property name="jndiName" value="jndi_maxkey_db" />
<property name="resourceRef" value="true" />
</bean> -->
<!-- dataSource define end -->
<bean id="jdbcTemplate" class="org.springframework.jdbc.core.JdbcTemplate">
<property name="dataSource" ref="dataSource"></property>
</bean>
<!-- Declare a transaction manager -->
<!-- transaction manager, use JtaTransactionManager for global tx-->
<bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<property name="dataSource" ref="dataSource" />
</bean>
<!-- Enable annotation style of managing transactions
<tx:annotation-driven transaction-manager="transactionManager" />-->
<!-- enable component scanning (beware that this does not enable mapper scanning!) -->
<context:component-scan base-package="org.maxkey.dao.service" />
<!-- enable autowire -->
<context:annotation-config />
<!-- enable transaction demarcation with annotations
<tx:annotation-driven />-->
<!--<bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">-->
<bean id="sqlSessionFactory" class="org.apache.mybatis.jpa.MyBatisSessionFactoryBean">
<property name="dataSource" ref="dataSource" />
<property name="transactionFactory">
<bean class="org.apache.ibatis.transaction.managed.ManagedTransactionFactory" />
</property>
<property name="typeAliasesPackage"
value="
org.maxkey.domain,
org.maxkey.domain.apps,
" />
<property name="timeout" value="30" />
<property name="mapperLocations" value="classpath*:org/maxkey/dao/persistence/xml/#{dataSoruceConfig.database}/*.xml" />
<property name="interceptors">
<list>
<ref bean="StatementHandlerInterceptor"/>
</list>
</property>
</bean>
<bean id="StatementHandlerInterceptor" class="org.apache.mybatis.jpa.StatementHandlerInterceptor">
<!-- dialect need bean dialect
<property name="dialect">
<bean id="dialect" class="org.apache.mybatis.jpa.dialect.MySQLDialect"/>
</property>
-->
<!-- from database type -->
<property name="dialectString" value="#{dataSoruceConfig.dialect}"/>
</bean>
<bean id="sqlSession" class="org.mybatis.spring.SqlSessionTemplate">
<constructor-arg index="0" ref="sqlSessionFactory" />
</bean>
<!-- scan for mappers and let them be autowired -->
<bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
<property name="basePackage"
value="
org.maxkey.dao.persistence,
" />
</bean>
<bean id="redisConnectionFactory" class="org.maxkey.persistence.redis.RedisConnectionFactory">
<property name="hostname" value="${config.redis.hostname}"/>
<property name="port" value="${config.redis.port}"/>
<property name="timeOut" value="${config.redis.timeout}"/>
<property name="poolConfig" >
<bean class="redis.clients.jedis.JedisPoolConfig">
<property name="maxTotal" value="${config.redis.pool.maxtotal}" />
<property name="maxIdle" value="${config.redis.pool.maxidle}" />
<property name="maxWaitMillis" value="${config.redis.pool.maxwaitmillis}" />
<property name="testOnBorrow" value="${config.redis.pool.testonborrow}" />
</bean>
</property>
</bean>
</beans>