applicationContext.xml配置介紹

 

<beans <!-- beans是xml文件的根節點 -->

xmlns="http://www.springframework.org/schema/beans"  <!-- xmlns是XML NameSpace的縮寫,因爲XML文件的標籤名稱都是自定義的,自己寫的和其他人定義的標籤很有可能會重複命名,而功能卻不一樣,所以需要加上一個namespace來區分這個xml文件和其他的xml文件,類似於java中的package -->

    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"  <!-- xsi是指xml文件遵守xml規範,xsi全名:xml schema instance -->
    xmlns:p="http://www.springframework.org/schema/p"
xmlns:aop="http://www.springframework.org/schema/aop" 
xmlns:context="http://www.springframework.org/schema/context"
xmlns:jee="http://www.springframework.org/schema/jee"
xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:cache="http://www.springframework.org/schema/cache"
xmlns:util="http://www.springframework.org/schema/util"
    xsi:schemaLocation="  <!--xsi:schemaLocation——是指具體用到的schema資源(不要看相關中文資料,看了就不明白了,schema就是schema~你把他翻譯成對文檔的限制就行了。你可能會說,dtd纔是,實際上xsd和dtd是一樣的-->
        http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-4.0.xsd
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.0.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.0.xsd
http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-4.0.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-4.0.xsd
http://www.springframework.org/schema/util
        http://www.springframework.org/schema/util/spring-util-4.0.xsd
        http://www.springframework.org/schema/cache
        http://www.springframework.org/schema/cache/spring-cache-4.0.xsd ">  


<!-- 加載數據庫屬性配置文件 -->
<context:property-placeholder location="classpath:/properties/db.properties" />
    <bean id="configProperties" class="org.springframework.beans.factory.config.PropertiesFactoryBean">
        <property name="locations">
            <list>
                <value>classpath:/properties/application.properties</value>
            </list>
        </property>
    </bean>
    <bean id="propertyConfigurer" class="org.springframework.beans.factory.config.PreferencesPlaceholderConfigurer">
        <property name="properties" ref="configProperties" />
    </bean>

<!-- 數據庫配置 -->
<bean id="dataSource" class="org.logicalcobwebs.proxool.ProxoolDataSource">
<property name="alias" value="defaultsDB" />
<property name="driver" value="${jdbc.driver}" />
<property name="driverUrl" value="${jdbc.url}" />
<property name="user" value="${jdbc.name}" />
<property name="password" value="${jdbc.password}" />
<property name="prototypeCount" value="5" />
<property name="maximumConnectionCount" value="50" />
<property name="minimumConnectionCount" value="5" />
<property name="maximumActiveTime" value="900000" />
<property name="trace" value="true" />
<property name="verbose" value="true" />
</bean>

<!-- session工廠 -->
<bean id="sessionFactory"
class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">
<property name="dataSource">
<ref bean="dataSource" />
</property>
<property name="configLocation" value="classpath:xml/hibernate.cfg.xml"/>
<!-- 自動掃描註解方式配置的hibernate類文件 -->
<property name="packagesToScan">
<list>
<value>com.douwong.entity</value>
</list>
</property>
</bean>


<!-- 配置事務管理器 -->
<bean id="transactionManager"
class="org.springframework.orm.hibernate4.HibernateTransactionManager">
<property name="sessionFactory" ref="sessionFactory" />
</bean>
<!-- 普通類調用Spring bean對象 -->
<bean id="springTool" class="com.douwong.common.SpringTool"></bean>
<!-- JDBC -->
<bean id="jdbcTemplate" class="org.springframework.jdbc.core.JdbcTemplate"
scope="prototype">
<property name="dataSource" ref="dataSource" /> 
</bean>


<!-- 配置事務通知屬性 -->
<tx:advice id="txAdvice" transaction-manager="transactionManager">
<!-- 定義事務傳播屬性 -->
<tx:attributes>
<tx:method name="insert*" propagation="REQUIRED" />
<tx:method name="update*" propagation="REQUIRED" />
<tx:method name="edit*" propagation="REQUIRED" />
<tx:method name="save*" propagation="REQUIRED" />
<tx:method name="add*" propagation="REQUIRED" />
<tx:method name="new*" propagation="REQUIRED" />
<tx:method name="set*" propagation="REQUIRED" />
<tx:method name="remove*" propagation="REQUIRED" />
<tx:method name="delete*" propagation="REQUIRED" />
<tx:method name="del*" propagation="REQUIRED" />
<tx:method name="send*" propagation="REQUIRED" />
<tx:method name="clear*" propagation="REQUIRED" />
<tx:method name="change*" propagation="REQUIRED" />
<tx:method name="get*" propagation="REQUIRED" read-only="true" />
<tx:method name="find*" propagation="REQUIRED" />
<tx:method name="load*" propagation="REQUIRED" read-only="true" />
<tx:method name="*" propagation="REQUIRED" read-only="true" />
</tx:attributes>
</tx:advice>

    <!-- 應用普通類獲取bean  
    <bean id="appContext" class="com.soanl.util.tool.ApplicationUtil"/>-->


<!-- 配置ehcache緩存 -->
<cache:annotation-driven cache-manager="cacheManager"/><!-- 啓用緩存註解開關 -->
<bean id="ehcacheManager" class="org.springframework.cache.ehcache.EhCacheManagerFactoryBean">
        <property name="configLocation" value="classpath:xml/ehcache.xml"/>
</bean>
<bean id="cacheManager" class="org.springframework.cache.ehcache.EhCacheCacheManager">
<property name="cacheManager" ref="ehcacheManager"/>
<property name="transactionAware" value="true"/>
</bean>


<!-- 配置事務切面 -->
<aop:config>
<aop:pointcut id="serviceOperation"
expression="execution(* com.douwong.manage.*.service..*.*(..)) ||execution(* com.douwong.manage.*.dao..*.*(..))||execution(* com.douwong.core.dao..*.*(..))||execution(* com.douwong.core.service..*.*(..))" />
<aop:advisor advice-ref="txAdvice" pointcut-ref="serviceOperation" />
</aop:config>


<!-- 配置掃描路徑 -->
     <context:component-scan base-package="com.douwong">
      <!-- 只掃描Service,也可以添加Repostory,但是要把Controller排除在外,Controller由spring-mvc.xml去加載 -->
      <context:include-filter type="annotation" expression="org.springframework.stereotype.Service" />
      <context:exclude-filter type="annotation" expression="org.springframework.stereotype.Controller"/>
     </context:component-scan>

</beans>




ehcache.xml配置:

<ehcache xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"  
xsi:noNamespaceSchemaLocation="http://ehcache.org/ehcache.xsd"> 
    
<diskStore path="./target/tmp"/><!-- 磁盤緩存位置 -->


<defaultCache   <!-- 默認緩存參數 -->
        maxElementsInMemory="10000"
        eternal="false"
        timeToIdleSeconds="120"
        timeToLiveSeconds="120"
        overflowToDisk="true"
        />

    <cache name="sampleCache1"
        maxElementsInMemory="10000"
        eternal="false"
        timeToIdleSeconds="300"
        timeToLiveSeconds="600"
        overflowToDisk="true"
        />

    <cache name="sampleCache2"
        maxElementsInMemory="1000"
        eternal="true"
        timeToIdleSeconds="0"
        timeToLiveSeconds="0"
        overflowToDisk="false"
        /> 


    <!-- 掃碼登錄等時間極短的緩存,時間爲70秒 -->    
<cache name="scanCache"
        maxElementsInMemory="10000"
        eternal="false"
        timeToIdleSeconds="30"
        timeToLiveSeconds="70"
        overflowToDisk="true"
        />


</ehcache>








發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章