applicationContext.xml basic configuration

<?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">


    <!-- The way of externalized parameter configuration, location: indicates the location of the property file, which is passed between multiples such as comma / Separated by semicolons; -->
    <!-- If there are multiple files in the location, they will be loaded in sequence. It is worth noting that if the attribute name in the latter file is the same as that in the previous file, the final value will be taken. is the post-loaded value -->
    <context:property-placeholder location="classpath:db.properties" /> 
    <!-- register with the Spring container
AutowiredAnnotationBeanPostProcessor、CommonAnnotationBeanPostProcessor、
PersistenceAnnotationBeanPostProcessor and RequiredAnnotationBeanPostProcessor are four BeanPostProcessors.
The purpose of registering these four BeanPostProcessors is for your system to recognize the corresponding annotations. -->
    <context:spring-configured/>
    <!-- Set the scanning scope of automatically injected beans, use-default-filters is true by default, and will scan all java classes for injection, -->    
    <!-- Use- In the case of dafault-filters=”false”: <context:exclude-filter> specifies not to scan, <context:include-filter> specifies scan-->
    <!-- Both springmvc and application files need to be configured, but mvc The file only scans the controller class, the application scan is not the controller class -->  
    <context:component-scan base-package="mytest.*">
        <context:exclude-filter expression="org.springframework.stereotype.Controller" type=" annotation"/>
    </context:component-scan>
    <!-- c3p0 configure datasource -->
    <bean id="dataSource" class="com.mchange.v2.c3p0.
    <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> 
Maximum idle time, connections are dropped if not used within 60 seconds. If it is 0, it will never be discarded. Default: 0   
    <property name="maxIdleTime" value="${db.maxIdleTime}"></property>  
    The number of connections obtained by c3p0 at one time when the connections in the connection pool are exhausted. Default: 3   
    <property name="acquireIncrement" value="${db.acquireIncrement}"/> 
    Defines the number of times to repeat the attempt after getting a new connection from the database fails. Default: 30 ; less than or equal to 0 means infinite   
    <property name="acquireRetryAttempts" value="${db.acquireRetryAttempts}"/> 
    Retry interval, default: 1000ms   
    <property name="acquireRetryDelay" value="${db.acquireRetryDelay}" />
     Check all connection pools for idle connections every 60 seconds. Default: 0, do not check 
     <property name="idleConnectionTestPeriod" value="${db.idleConnectionTestPeriod}"></property>  
    The size of the c3p0 global PreparedStatements cache. If both maxStatements and maxStatementsPerConnection are 0, the cache will not take effect. As long as one of them is not 0, the statement cache will take effect. if default: 0   
    <property name="maxStatements" value="${db.maxStatements}"></property>  
    maxStatementsPerConnection defines the maximum number of cached statements owned by a single connection in the connection pool. Default: 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>

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325759052&siteId=291194637