<?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:aop="http://www.springframework.org/schema/aop" xmlns:context="http://www.springframework.org/schema/context" xmlns:tx="http://www.springframework.org/schema/tx" xmlns:task="http://www.springframework.org/schema/task" xmlns:jpa="http://www.springframework.org/schema/data/jpa" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.0.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-4.0.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-4.0.xsd http://www.springframework.org/schema/task http://www.springframework.org/schema/task/spring-task-4.0.xsd http://www.springframework.org/schema/data/jpa http://www.springframework.org/schema/data/jpa/spring-jpa.xsd"> <!-- 外在化参数配置的方式,location:表示属性文件位置,多个之间通过如逗号/分号等分隔; --> <!-- 如果location中有多个文件,将依次加载,值得注意的是如果后一个文件中有和前面某一个文件中属性名是相同的,最终取的值是后加载的值 --> <context:property-placeholder location="classpath:db.properties" /> <!-- 向 Spring 容器注册 AutowiredAnnotationBeanPostProcessor、CommonAnnotationBeanPostProcessor、 PersistenceAnnotationBeanPostProcessor 以及 RequiredAnnotationBeanPostProcessor 这 4 个BeanPostProcessor。 注册这4个 BeanPostProcessor的作用,就是为了你的系统能够识别相应的注解。 --> <context:spring-configured/> <!-- 设置自动注入bean的扫描范围,use-default-filters默认为true,会扫描所有的java类进行注入 ,--> <!-- Use-dafault-filters=”false”的情况下:<context:exclude-filter>指定的不扫描,<context:include-filter>指定的扫描 --> <!-- springmvc和application文件都需要配置,但mvc文件只扫描controller类,application扫描不是controller类 --> <context:component-scan base-package="mytest.*"> <context:exclude-filter expression="org.springframework.stereotype.Controller" type="annotation"/> </context:component-scan> <!-- c3p0配置数据源 --> <bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource"> <property name="driverClass" value="${db.className}"/> <property name="jdbcUrl" value="${db.url}"/> <property name="user" value="${db.username}"/> <property name="password" value="${db.password}"/> <!-- <property name="checkoutTimeout" value="${db.checkoutTimeout}"> </property> <property name="initialPoolSize" value="${db.minPoolSize}"> </property> <property name="minPoolSize" value="${db.minPoolSize}"> </property> <property name="maxPoolSize" value="${db.maxPoolSize}"> </property> 最大空闲时间,60秒内未使用则连接被丢弃。若为0则永不丢弃。默认值: 0 <property name="maxIdleTime" value="${db.maxIdleTime}"></property> 当连接池中的连接耗尽的时候c3p0一次同时获取的连接数。默认值: 3 <property name="acquireIncrement" value="${db.acquireIncrement}"/> 定义在从数据库获取新连接失败后重复尝试的次数。默认值: 30 ;小于等于0表示无限次 <property name="acquireRetryAttempts" value="${db.acquireRetryAttempts}"/> 重新尝试的时间间隔,默认为:1000毫秒 <property name="acquireRetryDelay" value="${db.acquireRetryDelay}" /> 每60秒检查所有连接池中的空闲连接。默认值: 0,不检查 <property name="idleConnectionTestPeriod" value="${db.idleConnectionTestPeriod}"></property> c3p0全局的PreparedStatements缓存的大小。如果maxStatements与maxStatementsPerConnection均为0,则缓存不生效,只要有一个不为0,则语句的缓存就能生效。如果默认值: 0 <property name="maxStatements" value="${db.maxStatements}"></property> maxStatementsPerConnection定义了连接池内单个连接所拥有的最大缓存statements数。默认值: 0 <property name="maxStatementsPerConnection" value="${db.maxStatementsPerConnection}"></property> --> </bean> <!-- 配置用户对象数据MEMCACHED缓存--> <bean id="userMemcachedClient" class="net.spy.memcached.spring.MemcachedClientFactoryBean"> <property name="servers" value="${cache.common.user.ip.port}"/> <property name="protocol" value="TEXT"/> <property name="transcoder"> <bean class="net.spy.memcached.transcoders.SerializingTranscoder"> <property name="compressionThreshold" value="1024"/> </bean> </property> <property name="opTimeout" value="1000"/> <property name="timeoutExceptionThreshold" value="1998"/> <!--<property name="hashAlg" value="KETAMA_HASH"/>--> <property name="hashAlg"> <value type="net.spy.memcached.DefaultHashAlgorithm">KETAMA_HASH</value> </property> <property name="locatorType" value="CONSISTENT"/> <property name="failureMode" value="Redistribute"/> <property name="useNagleAlgorithm" value="false"/> </bean> <bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean"> <property name="dataSource" ref="dataSource"/> <property name="persistenceProvider" ref="persistenceProvider"/> <property name="jpaDialect" ref="jpaDialect"/> <property name="jpaVendorAdapter" ref="jpaVendorAdapter"/> <property name="packagesToScan" value="com.mytest.pojo"/> <property name="jpaProperties"> <props> <prop key="hibernate.dialect">${hibernate.dialect}</prop> <prop key="hibernate.temp.use_jdbc_metadata_defaults">${hibernate.temp.use_jdbc_metadata_defaults} </prop> <prop key="hibernate.show_sql">${hibernate.show_sql}</prop> <prop key="hibernate.format_sql">${hibernate.format_sql}</prop> <prop key="hibernate.max_fetch_depth">${hibernate.max_fetch_depth}</prop> <prop key="hibernate.jdbc.fetch_size">${hibernate.jdbc.fetch_size}</prop> <prop key="hibernate.jdbc.batch_size">${hibernate.jdbc.batch_size}</prop> </props> </property> </bean> <bean id="jdbcTemplate" class="org.springframework.jdbc.core.JdbcTemplate"> <property name="dataSource" ref="dataSource"/> </bean> <bean id="persistenceProvider" class="org.hibernate.jpa.HibernatePersistenceProvider"/> <bean id="jpaDialect" class="org.springframework.orm.jpa.vendor.HibernateJpaDialect"/> <bean id="jpaVendorAdapter" class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter"/> <bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager"> <property name="entityManagerFactory" ref="entityManagerFactory"/> </bean> <!-- 事务装配 --> <tx:advice id="txAdvice" transaction-manager="transactionManager"> <tx:attributes> <tx:method name="add*" propagation="REQUIRED"/> <tx:method name="save*" propagation="REQUIRED"/> <tx:method name="insert*" propagation="REQUIRED"/> <tx:method name="update*" propagation="REQUIRED"/> <tx:method name="delete*" propagation="REQUIRED"/> <tx:method name="query*" propagation="NOT_SUPPORTED"/> <tx:method name="get*" propagation="NOT_SUPPORTED"/> <tx:method name="find*" propagation="NOT_SUPPORTED"/> <tx:method name="*" propagation="REQUIRED"/> </tx:attributes> </tx:advice> <aop:config> <aop:pointcut expression="execution(* mytest.*.service.*.*(..))" id="txPointcut"/> <aop:advisor advice-ref="txAdvice" pointcut-ref="txPointcut"/> </aop:config> <tx:annotation-driven transaction-manager="transactionManager"/> <aop:aspectj-autoproxy/> <jpa:repositories base-package="mytest.*" entity-manager-factory-ref="entityManagerFactory" transaction-manager-ref="transactionManager" factory-class="mytest.common.base.DefaultDaoFactoryBean"/> <task:annotation-driven/> <!-- 文件上传 --> <bean id="multipartResolver" class="org.springframework.web.multipart.commons.CommonsMultipartResolver"/> </beans>