您的位置:首页 > 数据库 > Redis

SSH中Spring以及hibernate、Redis的xml配置

2017-11-07 21:17 459 查看
<?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:tx="http://www.springframework.org/schema/tx"
xmlns:p="http://www.springframework.org/schema/p"
xmlns:context="http://www.springframework.org/schema/context" xmlns:aop="http://www.springframework.org/schema/aop"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.3.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-4.3.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-4.3.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.3.xsd" default-autowire="byName" default-lazy-init="false">

<!-- 定义受环境影响易变的变量 -->
<bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="locations">
<list>
<!-- 标准配置 -->
<value>classpath:jdbc.properties</value>
</list>
</property>
</bean>

<!-- 使用annotation 自动注册bean,并保证@Required,@Autowired的属性被注入 -->
<context:component-scan base-package="com.test.server" />
<context:annotation-config />

<bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource">
<property name="driverClass" value="
com.mysql.jdbc.Driver" />
<property name="jdbcUrl" value="
jdbc:mysql:///test?
useUnicode=true&characterEncoding=UTF-8&
1autoReconnect=true" />
<property name="user" value="root" /> <property name="password" value="1234" /> <property name="initialPoolSize" value="10" /> <!--连接空闲时间(秒) --> <property name="maxIdleTime" value="200" /> <property name="maxPoolSize" value="50" /> <property name="minPoolSize" value="10" /> <!--获取新连接的等待时间(毫秒)0一直等待 --> <property name="checkoutTimeout" value="30000" /> <!--检测空闲连接的时间间隔(秒) --> <property name="idleConnectionTestPeriod" value="150" /> <!--<property name="testConnectionOnCheckout" value="true" />--> </bean> <!-- Hibernate配置 --> <bean id="sessionFactory" class="org.springframework.orm.hibernate4.LocalSessionFactoryBean"> <property name="dataSource" ref="dataSource" /> <property name="hibernateProperties"> <props> <prop key="hibernate.dialect">org.hibernate.dialect.MySQLDialect</prop> <prop key="hibernate.show_sql">true</prop> <prop key="hibernate.connection.release_mode">auto</prop> <prop key="hibernate.hbm2ddl.auto">update</prop>
</props> </property>
<!-- 配置扫描bean value:配置bean包 -->
 <property name="packagesToScan" value="com.test.server.data" /> </bean> <!--配置Redis--> <bean id="redisPoolConfig" class="redis.clients.jedis.JedisPoolConfig"> <property name="maxIdle" value="100"/> <property name="maxTotal" value="300" /> <property name="maxWaitMillis" value="60000" /> <property name="testOnBorrow" value="false" /> <property name="testOnReturn" value="false" /> <property name="timeBetweenEvictionRunsMillis" value="60000" /> <property name="minEvictableIdleTimeMillis" value="120000" /> <property name="numTestsPerEvictionRun" value="-1" /> </bean> <bean id="jedisConnectionFactory" class="org.springframework.data.redis.connection.jedis.JedisConnectionFactory" p:hostName="${redis.hostName}" p:port="${redis.port}" p:password="${redis.password}" p:usePool="true" p:poolConfig-ref="redisPoolConfig"/> <bean id="redisTemplate" class="org.springframework.data.redis.core.RedisTemplate" p:connectionFactory-ref="jedisConnectionFactory"/> <!-- 事务管理器配置,单数据源事务 --> <bean id="txManager" class="org.springframework.orm.hibernate4.HibernateTransactionManager"> <property name="sessionFactory" ref="sessionFactory" /> </bean> <tx:advice id="txAdvice" transaction-manager="txManager"> <tx:attributes> <tx:method name="get*" read-only="true" /> <tx:method name="find*" read-only="true" /> <tx:method name="query*" read-only="true" /> <tx:method name="is*" read-only="true" /> <tx:method name="*" propagation="REQUIRED" /> </tx:attributes> </tx:advice> <!-- 使用annotation定义事务 --> <tx:annotation-driven transaction-manager="txManager" proxy-target-class="true"/> <aop:config proxy-target-class="true"> <aop:advisor pointcut="execution(* com.test.server.service..*Manager.*(..))" advice-ref="txAdvice" /> <aop:advisor pointcut="execution(* com.test.server.dao..*Dao.*(..))" advice-ref="txAdvice" /> </aop:config></beans>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  ssh spring hibernate xml 框架
相关文章推荐