Spring-4.0.1+Hibernate-4.3.2+Struts-2.3.16环境配置(包含hibernate二级缓存和spring缓存)

时间:2022-05-10 04:50:14

第一个配置文件  config.properties ,根据你使用的数据库选择不同的配置,我使用的mysql

#hibernate.dialect=sy.util.base.Oracle10gDialect
#driverClassName=oracle.jdbc.driver.OracleDriver
#validationQuery=SELECT 1 FROM DUAL
#jdbc_url=jdbc:oracle:thin:@(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=127.0.0.1)(PORT=1521))(LOAD_BALANCE=yes)(CONNECT_DATA=(SERVER=DEDICATED)(SERVICE_NAME=orcl)))
#jdbc_username=npnt
#jdbc_password=123456

hibernate.dialect=org.hibernate.dialect.MySQLInnoDBDialect
driverClassName=com.mysql.jdbc.Driver
validationQuery=SELECT 1
jdbc_url=jdbc:mysql://192.168.1.101:3306/npnt?useUnicode=true&characterEncoding=UTF-8&zeroDateTimeBehavior=convertToNull
jdbc_username=root
jdbc_password=123456
jdbc_host=192.168.1.101 
jdbc_port=3306  
jdbc_exportDatabaseName=npnt
jdbc_importDatabaseName=npnt
#
#hibernate.dialect=org.hibernate.dialect.SQLServer2008Dialect
#driverClassName=net.sourceforge.jtds.jdbc.Driver
#validationQuery=SELECT 1
#jdbc_url=jdbc:jtds:sqlserver://127.0.0.1:1433/dbName
#jdbc_username=sa
#jdbc_password=123456

#jndiName=java:comp/env/dataSourceName

hibernate.hbm2ddl.auto=update
hibernate.show_sql=true
hibernate.format_sql=true
hibernate.use_sql_comments=true

第二个配置文件 spring.xml

<?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:context="http://www.springframework.org/schema/context"
	xmlns:aop="http://www.springframework.org/schema/aop"
	xmlns:tx="http://www.springframework.org/schema/tx"
	xsi:schemaLocation="http://www.springframework.org/schema/beans 
	http://www.springframework.org/schema/beans/spring-beans.xsd
	http://www.springframework.org/schema/context
	http://www.springframework.org/schema/context/spring-context.xsd
	http://www.springframework.org/schema/aop
	http://www.springframework.org/schema/aop/spring-aop.xsd
	http://www.springframework.org/schema/tx 
	http://www.springframework.org/schema/tx/spring-tx.xsd">
	
	
	  
		<!-- 自动扫描dao和service包(自动注入) -->
	<context:component-scan base-package="com.virtue.npnt.dao,com.virtue.npnt.service" />
     <aop:aspectj-autoproxy />
<bean  class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
		<property name="locations">
			<value>classpath:config.properties</value> //由spring来管理配置的config文件
		</property>
	</bean>
</beans>


第三个配置文件 spring-hibernate.xml


<?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:c="http://www.springframework.org/schema/c" xmlns:cache="http://www.springframework.org/schema/cache" xmlns:context="http://www.springframework.org/schema/context" xmlns:jdbc="http://www.springframework.org/schema/jdbc" xmlns:jee="http://www.springframework.org/schema/jee" xmlns:lang="http://www.springframework.org/schema/lang" xmlns:mvc="http://www.springframework.org/schema/mvc" xmlns:p="http://www.springframework.org/schema/p" xmlns:task="http://www.springframework.org/schema/task" xmlns:tx="http://www.springframework.org/schema/tx" xmlns:util="http://www.springframework.org/schema/util"
	xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
		http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsd
		http://www.springframework.org/schema/cache http://www.springframework.org/schema/cache/spring-cache.xsd
		http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd
		http://www.springframework.org/schema/jdbc http://www.springframework.org/schema/jdbc/spring-jdbc.xsd
		http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee.xsd
		http://www.springframework.org/schema/lang http://www.springframework.org/schema/lang/spring-lang.xsd
		http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc.xsd
		http://www.springframework.org/schema/task http://www.springframework.org/schema/task/spring-task.xsd
		http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd
		http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util.xsd">

	

	<!-- 配置数据源 -->
	<bean name="dataSource" class="com.alibaba.druid.pool.DruidDataSource" init-method="init" destroy-method="close">
		<property name="url" value="${jdbc_url}" />
		<property name="username" value="${jdbc_username}" />
		<property name="password" value="${jdbc_password}" />

		<!-- 初始化连接大小 -->
		<property name="initialSize" value="0" />
		<!-- 连接池最大使用连接数量 -->
		<property name="maxActive" value="20" />
		<!-- 连接池最小空闲 -->
		<property name="minIdle" value="0" />
		<!-- 获取连接最大等待时间 -->
		<property name="maxWait" value="60000" />

		<!-- <property name="poolPreparedStatements" value="true" /> <property name="maxPoolPreparedStatementPerConnectionSize" value="33" /> -->

		<property name="validationQuery" value="${validationQuery}" />
		<property name="testOnBorrow" value="false" />
		<property name="testOnReturn" value="false" />
		<property name="testWhileIdle" value="true" />

		<!-- 配置间隔多久才进行一次检测,检测需要关闭的空闲连接,单位是毫秒 -->
		<property name="timeBetweenEvictionRunsMillis" value="60000" />
		<!-- 配置一个连接在池中最小生存的时间,单位是毫秒 -->
		<property name="minEvictableIdleTimeMillis" value="25200000" />

		<!-- 打开removeAbandoned功能 -->
		<property name="removeAbandoned" value="true" />
		<!-- 1800秒,也就是30分钟 -->
		<property name="removeAbandonedTimeout" value="1800" />
		<!-- 关闭abanded连接时输出错误日志 -->
		<property name="logAbandoned" value="true" />

		<!-- 监控数据库 -->
		<!-- <property name="filters" value="mergeStat" /> -->
		<property name="filters" value="stat" />
	</bean>
 
	

	<!-- 配置hibernate session工厂 -->
	<bean id="sessionFactory" class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">
		<property name="dataSource" ref="dataSource" />
		<property name="hibernateProperties">
			<props>
				<prop key="hibernate.hbm2ddl.auto">${hibernate.hbm2ddl.auto}</prop>
				<prop key="hibernate.dialect">${hibernate.dialect}</prop>
				<prop key="hibernate.show_sql">${hibernate.show_sql}</prop>
				<prop key="hibernate.format_sql">${hibernate.format_sql}</prop>
				<prop key="hibernate.use_sql_comments">${hibernate.use_sql_comments}</prop>
				 <prop key="hibernate.cache.use_second_level_cache">true</prop>  //开启二级缓存
       			 <prop key="hibernate.cache.region.factory_class">org.hibernate.cache.ehcache.EhCacheRegionFactory</prop>  //配置ehcache为hibernate的二级缓存
				 <prop key="hibernate.cache.use_query_cache">true</prop>  //开启查询缓存
 

			</props>
		</property>

		<!-- 自动扫描注解方式配置的hibernate类文件 -->
		<property name="packagesToScan">
			<list>
				<value>com.virtue.npnt.entity.basedata</value>
				<value>com.virtue.npnt.entity.order</value>
					<value>com.virtue.npnt.entity.scheduling</value>
					<value>com.virtue.npnt.entity.supplies</value>
					<value>com.virtue.npnt.entity.maintain</value>
					<value>com.virtue.npnt.entity.transport</value>
					<value>com.virtue.npnt.entity.npc</value>
					<value>com.virtue.npnt.entity.approvecertificate</value>
					<value>com.virtue.npnt.entity.companystandard</value>
					<value>com.virtue.npnt.entity.examine</value>
					<value>com.virtue.npnt.entity.quality</value>
					<value>com.virtue.npnt.entity.checkplan</value>
					<value>com.virtue.npnt.entity.work</value>
					<value>com.virtue.npnt.entity.alertor</value>
					<value>com.virtue.npnt.entity.drug</value>
					<value>com.virtue.npnt.entity.easywork</value>
					<value>com.virtue.npnt.entity.ordermanager</value>
						<value>com.virtue.npnt.entity.i125</value>
			</list>
		</property>



    
   
		<!-- 自动扫描hbm方式配置的hibernate文件和.hbm文件 -->
		<!-- <property name="mappingDirectoryLocations"> <list> <value>classpath:sy/hbm</value> </list> </property> -->
	</bean>



	<!-- 配置事务管理器 -->
	<bean name="transactionManager" class="org.springframework.orm.hibernate4.HibernateTransactionManager">
		<property name="sessionFactory" ref="sessionFactory"></property>
	</bean>

	<!-- 注解方式配置事物 -->
	<!-- <tx:annotation-driven transaction-manager="transactionManager" /> -->

	<!-- 拦截器方式配置事物 -->
	<tx:advice id="transactionAdvice" transaction-manager="transactionManager">
		<tx:attributes>
			<tx:method name="save*" propagation="REQUIRED" />
			<tx:method name="add*" propagation="REQUIRED" />
			<tx:method name="update*" propagation="REQUIRED" />
			<tx:method name="saveOrUpdate*" propagation="REQUIRED" />
			<tx:method name="delete*" propagation="REQUIRED" />
			<tx:method name="grant*" propagation="REQUIRED" />
			<tx:method name="reCheck" propagation="REQUIRED" />
			<tx:method name="*O" propagation="REQUIRED" />
			<tx:method name="cancle*" propagation="REQUIRED" />
			<tx:method name="return*" propagation="REQUIRED" />

			<tx:method name="init*" propagation="REQUIRED" />

			<tx:method name="*" propagation="REQUIRED" read-only="true" />
		</tx:attributes>
	</tx:advice>
	<aop:config>
		<!-- 第一个*代表所有的返回值类型;第二个*代表所有的类;第三个*代表类所有方法;..代表子或者孙子包;最后一个..代表所有的参数 -->
		<aop:pointcut id="transactionPointcut" expression="(execution(* com.virtue.npnt.service..*Impl.*(..)))" />
		<aop:advisor pointcut-ref="transactionPointcut" advice-ref="transactionAdvice" />
	</aop:config>


</beans>

第四个配置文件 spring-ehcache.xml 
<?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:c="http://www.springframework.org/schema/c" xmlns:cache="http://www.springframework.org/schema/cache" xmlns:context="http://www.springframework.org/schema/context" xmlns:jdbc="http://www.springframework.org/schema/jdbc" xmlns:jee="http://www.springframework.org/schema/jee" xmlns:lang="http://www.springframework.org/schema/lang" xmlns:mvc="http://www.springframework.org/schema/mvc" xmlns:p="http://www.springframework.org/schema/p" xmlns:task="http://www.springframework.org/schema/task" xmlns:tx="http://www.springframework.org/schema/tx" xmlns:util="http://www.springframework.org/schema/util"
	xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
		http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsd
		http://www.springframework.org/schema/cache http://www.springframework.org/schema/cache/spring-cache.xsd
		http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd
		http://www.springframework.org/schema/jdbc http://www.springframework.org/schema/jdbc/spring-jdbc.xsd
		http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee.xsd
		http://www.springframework.org/schema/lang http://www.springframework.org/schema/lang/spring-lang.xsd
		http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc.xsd
		http://www.springframework.org/schema/task http://www.springframework.org/schema/task/spring-task.xsd
		http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd
		http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util.xsd">

	<!-- 开启spring缓存 -->
	<cache:annotation-driven cache-manager="cacheManager" />
	<bean id="cacheManagerFactory" class="org.springframework.cache.ehcache.EhCacheManagerFactoryBean" p:configLocation="classpath:ehcache.xml" p:shared="true" />
	<bean id="cacheManager" class="org.springframework.cache.ehcache.EhCacheCacheManager" p:cacheManager-ref="cacheManagerFactory" />


</beans>

第五个配置文件 ehcache.xml 

<span style="font-size:18px;"><?xml version="1.0" encoding="UTF-8"?>
<ehcache xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="ehcache.xsd" updateCheck="true" monitoring="autodetect" dynamicConfig="true">

    <diskStore path="java.io.tmpdir" />
    <!-- <diskStore path="E:/cachetmpdir" /> -->
    
    <!--  
    name:Cache的唯一标识
    maxElementsInMemory:内存中最大缓存对象数
    maxElementsOnDisk:磁盘中最大缓存对象数,若是0表示无穷大
    eternal:Element是否永久有效,一但设置了,timeout将不起作用
    overflowToDisk:配置此属性,当内存中Element数量达到maxElementsInMemory时,Ehcache将会Element写到磁盘中
    timeToIdleSeconds:设置Element在失效前的允许闲置时间。仅当element不是永久有效时使用,可选属性,默认值是0,也就是可闲置时间无穷大
    timeToLiveSeconds:设置Element在失效前允许存活时间。最大时间介于创建时间和失效时间之间。仅当element不是永久有效时使用,默认是0.,也就是element存活时间无穷大  
    diskPersistent:是否缓存虚拟机重启期数据  
    diskExpiryThreadIntervalSeconds:磁盘失效线程运行时间间隔,默认是120秒
    diskSpoolBufferSizeMB:这个参数设置DiskStore(磁盘缓存)的缓存区大小。默认是30MB。每个Cache都应该有自己的一个缓冲区
    memoryStoreEvictionPolicy:当达到maxElementsInMemory限制时,Ehcache将会根据指定的策略去清理内存。默认策略是LRU(最近最少使用)。你可以设置为FIFO(先进先出)或是LFU(较少使用)  
    
    -->

<defaultCache maxElementsInMemory="10000" eternal="false" timeToIdleSeconds="120" timeToLiveSeconds="120" overflowToDisk="true" maxElementsOnDisk="10000000" diskPersistent="false" diskExpiryThreadIntervalSeconds="120" memoryStoreEvictionPolicy="LRU" />
    
    
<!--     
  <cache name="org.hibernate.cache.internal.StandardQueryCache"
        maxElementsInMemory="50"
        eternal="false"
        timeToLiveSeconds="120"
        overflowToDisk="true" />
 
    <cache name="org.hibernate.cache.spi.UpdateTimestampsCache"
        maxElementsInMemory="5000"
        eternal="true"
        overflowToDisk="true" /> -->
      <cache name="ResourcetypeServiceCache" maxElementsInMemory="10000" maxElementsOnDisk="1000" eternal="false" overflowToDisk="true" diskSpoolBufferSizeMB="20" timeToIdleSeconds="300" timeToLiveSeconds="600" memoryStoreEvictionPolicy="LFU" /> //我自己定义的一个缓存实例

</ehcache>

</span>


第六个配置文件 spring-druid.xml 


<span style="font-size:18px;"><?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:c="http://www.springframework.org/schema/c" xmlns:cache="http://www.springframework.org/schema/cache" xmlns:context="http://www.springframework.org/schema/context" xmlns:jdbc="http://www.springframework.org/schema/jdbc" xmlns:jee="http://www.springframework.org/schema/jee" xmlns:lang="http://www.springframework.org/schema/lang" xmlns:mvc="http://www.springframework.org/schema/mvc" xmlns:p="http://www.springframework.org/schema/p" xmlns:task="http://www.springframework.org/schema/task" xmlns:tx="http://www.springframework.org/schema/tx" xmlns:util="http://www.springframework.org/schema/util"
	xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
		http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsd
		http://www.springframework.org/schema/cache http://www.springframework.org/schema/cache/spring-cache.xsd
		http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd
		http://www.springframework.org/schema/jdbc http://www.springframework.org/schema/jdbc/spring-jdbc.xsd
		http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee.xsd
		http://www.springframework.org/schema/lang http://www.springframework.org/schema/lang/spring-lang.xsd
		http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc.xsd
		http://www.springframework.org/schema/task http://www.springframework.org/schema/task/spring-task.xsd
		http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd
		http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util.xsd">

	<!-- 配置druid监控spring jdbc -->
	<bean id="druid-stat-interceptor" class="com.alibaba.druid.support.spring.stat.DruidStatInterceptor" />

	<bean id="druid-stat-pointcut" class="org.springframework.aop.support.JdkRegexpMethodPointcut" scope="prototype">
		<property name="patterns">
			<list>
				<value>com.virtue.npnt.base.service.*</value>
			</list>
		</property>
	</bean>
	<aop:config>
		<aop:advisor advice-ref="druid-stat-interceptor" pointcut-ref="druid-stat-pointcut" />
	</aop:config>

</beans>
</span>

第七个配置文件 spring-quartz.xml  这是一个定时器的配置文件,如果不需要,可以不配


<span style="font-size:18px;"><?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:context="http://www.springframework.org/schema/context"
	xmlns:aop="http://www.springframework.org/schema/aop"
	xmlns:tx="http://www.springframework.org/schema/tx"
	xsi:schemaLocation="http://www.springframework.org/schema/beans 
	http://www.springframework.org/schema/beans/spring-beans.xsd
	http://www.springframework.org/schema/context
	http://www.springframework.org/schema/context/spring-context.xsd
	http://www.springframework.org/schema/aop
	http://www.springframework.org/schema/aop/spring-aop.xsd
	http://www.springframework.org/schema/tx 
	http://www.springframework.org/schema/tx/spring-tx.xsd">
	
	
 
      
     <!-- 要调用的工作类  -->
        <bean id="quartzJob" class="com.virtue.npnt.npc.timertask.BackupPlanTask"></bean>
        <bean id="warns" class="com.virtue.npnt.action.warn.WarnAction"></bean>
        <!-- 定义调用对象和调用对象的方法-->
        <bean id="jobtask" class="org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean">
      
        <!--     调用的类-->
            <property name="targetObject">
                <ref bean="quartzJob"/>
            </property>
        <!--     调用类中的方法-->
            <property name="targetMethod">
                <value>startPlan</value>
            </property>
        </bean>
       <!--  定义触发时间  1-->
        <bean id="doTime1" class="org.springframework.scheduling.quartz.CronTriggerBean">
            <property name="jobDetail">
                <ref bean="jobtask"/>
            </property>
            <!-- cron表达式 -->
            <property name="cronExpression">
            
                <value>59 59 23 * * ?</value>
 
            </property>
        </bean>
         <!--  定义触发时间  2-->
        <bean id="doTime2" class="org.springframework.scheduling.quartz.CronTriggerBean">
            <property name="jobDetail">
                <ref bean="jobtask"/>
            </property>
            <!-- cron表达式 -->
            <property name="cronExpression">
      
                  <value>59 59 23 L * ?</value>
         
              
                
            </property>
        </bean>
           <!--  定义触发时间  3-->
        <bean id="doTime3" class="org.springframework.scheduling.quartz.CronTriggerBean">
            <property name="jobDetail">
                <ref bean="jobtask"/>
            </property>
            <!-- cron表达式 -->
            <property name="cronExpression">
            
             
                <value>59 59 23 ? * SUN </value>
                 
              
                
            </property>
        </bean>
           <!--  定义触发时间  4-->
        <bean id="doTime4" class="org.springframework.scheduling.quartz.CronTriggerBean">
            <property name="jobDetail">
                <ref bean="jobtask"/>
            </property>
            <!-- cron表达式 -->
            <property name="cronExpression">
            
           
                     <value>59 59 23 31 12 ? * </value>
              
                
            </property>
        </bean>
        <!-- 总管理类 如果将lazy-init='false'那么容器启动就会执行调度程序 -->
        <bean id="startQuertz" lazy-init="false" autowire="no" class="org.springframework.scheduling.quartz.SchedulerFactoryBean">
            <property name="triggers">
                <list>
                    <ref bean="doTime1"/>
                         <ref bean="doTime2"/>
                              <ref bean="doTime3"/>
                                   <ref bean="doTime4"/>
                </list>
            </property>
        </bean>
    
</beans>


</span>

第八个配置文件 struts.xml


<span style="font-size:18px;"><?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE struts PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 2.1//EN" "struts-2.1.dtd" >
<struts>


<!-- 指定由spring负责action对象的创建 -->
	<constant name="struts.objectFactory" value="spring" />

<!-- 允许标签中使用表达式语法 -->
	<constant name="struts.tag.altSyntax" value="true" />

	<!-- 所有匹配*.action的请求都由struts2处理 -->
	<constant name="struts.action.extension" value="action" />
  <!-- 是否启用开发模式 -->
	<constant name="struts.devMode" value="true" />
	<!-- struts配置文件改动后,是否重新加载 -->
	<constant name="struts.configuration.xml.reload" value="true" />
    <!-- 每次HTTP请求系统都重新加载资源文件,有助于开发 -->
	<constant name="struts.i18n.reload" value="true" />
	<!-- 文件上传最大值 -->
	<constant name="struts.multipart.maxSize" value="104857600" />
	<!-- 让struts2支持动态方法调用 -->
	<constant name="struts.enable.DynamicMethodInvocation" value="true" />
	<!-- 允许标签中使用表达式语法 -->
	<constant name="struts.tag.altSyntax" value="true" />
	
	<constant name="struts.objectFactory.spring.autoWire.alwaysRespect" value="true" />
<package name="NpntPackage" extends="struts-default" namespace="/">
	<interceptors>
	<!-- javamelody拦截器 -->
			<interceptor name="monitoring" class="net.bull.javamelody.StrutsInterceptor" />
			<interceptor-stack name="monitoringStack">
				<interceptor-ref name="monitoring" />
				<interceptor-ref name="defaultStack" />
			</interceptor-stack>



<!-- 字符集拦截器 -->
			<interceptor name="encodingInterceptor" class="com.virtue.npnt.interceptor.EncodingInterceptor" />
			<interceptor-stack name="encodingStack">
				<interceptor-ref name="monitoringStack"></interceptor-ref>
				<interceptor-ref name="encodingInterceptor"></interceptor-ref>
			</interceptor-stack>
			<!-- session拦截器 -->
			<interceptor name="sessionInterceptor" class="com.virtue.npnt.interceptor.SessionInterceptor" />
			<interceptor-stack name="sessionStack">
				<interceptor-ref name="encodingStack"></interceptor-ref>
				<interceptor-ref name="sessionInterceptor">
					<!-- doNotNeedSessionAndSecurity_ 开头的和doNotNeedSession_ 开头的方法不拦截 -->
					<param name="excludeMethods">doNotNeedSession*,doNotNeedSessionAndSecurity*</param>
				</interceptor-ref>
			</interceptor-stack>
			<!-- 权限拦截器 --> 
			<interceptor name="securityInterceptor" class="com.virtue.npnt.interceptor.SecurityInterceptor" />
			<interceptor-stack name="securityStack">
				<interceptor-ref name="sessionStack"></interceptor-ref>
				<interceptor-ref name="securityInterceptor">
					<!-- doNotNeedSessionAndSecurity_ 开头的和doNotNeedSecurity_ 开头的方法不拦截 -->
					<param name="excludeMethods">doNotNeedSecurity*,doNotNeedSessionAndSecurity*</param>
				</interceptor-ref>
			</interceptor-stack>


			</interceptors>
			
			
			
			<!-- 全局拦截器栈 -->
		<default-interceptor-ref name="securityStack"></default-interceptor-ref>

		<global-results>
			<!-- 没有session -->
			<result name="noSession">/error/noSession.jsp</result>
			<!-- 没有权限 -->
			<result name="noSecurity">/error/noSecurity.jsp</result>
			<!-- struts抛异常 -->
			<result name="strutsException">/error/strutsException.jsp</result>
		</global-results>

		<global-exception-mappings>
			<exception-mapping result="strutsException" exception="java.lang.Exception"></exception-mapping>
		</global-exception-mappings>

</package>
</struts>
</span>

第九个配置文件 spring-javamelody.xml   不需要可以不配

<span style="font-size:18px;"><?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:c="http://www.springframework.org/schema/c" xmlns:cache="http://www.springframework.org/schema/cache" xmlns:context="http://www.springframework.org/schema/context" xmlns:jdbc="http://www.springframework.org/schema/jdbc" xmlns:jee="http://www.springframework.org/schema/jee" xmlns:lang="http://www.springframework.org/schema/lang" xmlns:mvc="http://www.springframework.org/schema/mvc" xmlns:p="http://www.springframework.org/schema/p" xmlns:task="http://www.springframework.org/schema/task" xmlns:tx="http://www.springframework.org/schema/tx" xmlns:util="http://www.springframework.org/schema/util"
	xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
		http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsd
		http://www.springframework.org/schema/cache http://www.springframework.org/schema/cache/spring-cache.xsd
		http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd
		http://www.springframework.org/schema/jdbc http://www.springframework.org/schema/jdbc/spring-jdbc.xsd
		http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee.xsd
		http://www.springframework.org/schema/lang http://www.springframework.org/schema/lang/spring-lang.xsd
		http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc.xsd
		http://www.springframework.org/schema/task http://www.springframework.org/schema/task/spring-task.xsd
		http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd
		http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util.xsd">

	<!-- 监控dao和service的执行情况 -->
	<bean id="facadeMonitoringAdvisor" class="net.bull.javamelody.MonitoringSpringAdvisor">
		<property name="pointcut">
			<bean class="org.springframework.aop.support.JdkRegexpMethodPointcut">
				<property name="patterns">
					<array>
						<value>com\.dao\..*</value>
						<value>com\.service\..*</value>
					</array>
				</property>
			</bean>
		</property>
	</bean>

</beans>
</span>


至此完成注解配置。

另附,如果启用了hibernate的二级缓存,在要缓存的实体类中应添加

@Cache(usage=CacheConcurrencyStrategy.READ_ONLY)举例

package com.virtue.npnt.entity.approvecertificate;

import java.io.Serializable;
import java.util.Date;

import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.Table;

import org.hibernate.annotations.Cache;
import org.hibernate.annotations.CacheConcurrencyStrategy;
import org.springframework.cache.annotation.Cacheable;
@Entity
@Table(name="acrm")
<span style="font-size:18px;">@Cache(usage=CacheConcurrencyStrategy.READ_ONLY</span>)
public class ACRM implements Serializable{

	/**
	 * customer 审批转入方
	 * code 备案批准文号
	 * approveDate 批准时间
	 * returnDate 备案下发时间
	 * remark 备注
	 * status 状态
	 */
	private static final long serialVersionUID = 1L;
	@Id
	@GeneratedValue
	private Integer Id;
	private String customer;
	private String code;
	private Date approveDate;
	private Date returnDate;
	private String  remark;
	private String status;
	
	
	
	public ACRM() {
		super();
	}
	public Integer getId() {
		return Id;
	}
	public void setId(Integer id) {
		Id = id;
	}
	public String getCustomer() {
		return customer;
	}
	public void setCustomer(String customer) {
		this.customer = customer;
	}
	public String getCode() {
		return code;
	}
	public void setCode(String code) {
		this.code = code;
	}
	public Date getApproveDate() {
		return approveDate;
	}
	public void setApproveDate(Date approveDate) {
		this.approveDate = approveDate;
	}
	public Date getReturnDate() {
		return returnDate;
	}
	public void setReturnDate(Date returnDate) {
		this.returnDate = returnDate;
	}
	public String getRemark() {
		return remark;
	}
	public void setRemark(String remark) {
		this.remark = remark;
	}
	public String getStatus() {
		return status;
	}
	public void setStatus(String status) {
		this.status = status;
	}
	
	
}


如果启用了spring的缓存,应当在要缓存的实现中添加

 @Cacheable(value = "ResourcetypeServiceCache", key = "'ResourcetypeList'") 举例

package com.virtue.npnt.service.impl.basedata;

import java.util.List;



import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;




import com.virtue.npnt.entity.basedata.Resourcetype;
import com.virtue.npnt.service.basedata.ResourcetypeServiceI;
import com.virtue.npnt.service.impl.BaseServiceImpl;



/**
 * 资源类型业务逻辑
 * 
 * @author 潘超
 * 
 */
@Service
public class ResourcetypeServiceImpl extends BaseServiceImpl<Resourcetype> implements ResourcetypeServiceI {

	/**
	 * 为列表添加了缓存,查询一次过后,只要不重启服务,缓存一直存在,不需要再查询数据库了,节省了一些资源
	 * 
	 * 在ehcache.xml里面需要有对应的value
	 * 
	 * <cache name="ResourcetypeServiceCache"
	 *
	 * 
	 * key是自己设定的一个ID,用来标识缓存
	 */

	
	@Override
	 @Cacheable(value = "ResourcetypeServiceCache", key = "'ResourcetypeList'")
	public List<Resourcetype> findResourcetype() {
		return find();
	}

}



另外附带我的一个pom.xml   我的项目使用maven管理的

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <groupId>NPNTMAVEN</groupId>
  <artifactId>NPNTMAVEN</artifactId>
  <version>0.0.1-SNAPSHOT</version>
  <packaging>war</packaging>
  <name/>
  <description/>
  <properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
  </properties>
  <dependencies>

<!-- 定时器 -->
<dependency>
    <groupId>quartz</groupId>
    <artifactId>quartz</artifactId>
    <version>1.5.1</version>
</dependency>
<!-- bsh -->
<dependency>
    <groupId>bsh</groupId>
    <artifactId>bsh</artifactId>
    <version>2.0b4</version>
</dependency>
<!-- commons-beanutils -->
<dependency>
    <groupId>commons-beanutils</groupId>
    <artifactId>commons-beanutils-core</artifactId>
    <version>1.8.3</version>
</dependency>
<!-- commons-logging -->	
<dependency>
    <groupId>commons-logging</groupId>
    <artifactId>commons-logging</artifactId>
    <version>1.1.3</version>
</dependency>
<!--commons-net  -->
<dependency>
    <groupId>commons-net</groupId>
    <artifactId>commons-net</artifactId>
    <version>3.3</version>
</dependency>
  <!-- mysql驱动包 -->
   <dependency>
    <groupId>mysql</groupId>
    <artifactId>mysql-connector-java</artifactId>
    <version>5.1.28</version>
</dependency>
<!-- junit -->
<dependency>
    <groupId>junit</groupId>
    <artifactId>junit</artifactId>
    <version>4.11</version>
    <scope>test</scope>
</dependency>
<dependency>
    <groupId>log4j</groupId>
    <artifactId>log4j</artifactId>
    <version>1.2.17</version>
</dependency>
<!-- druid数据源 -->
<dependency>
    <groupId>com.alibaba</groupId>
    <artifactId>druid</artifactId>
    <version>1.0.2</version>
</dependency>
<!-- aspectj -->
<dependency>
    <groupId>org.aspectj</groupId>
    <artifactId>aspectjweaver</artifactId>
    <version>1.7.4</version>
</dependency>
<!-- fastjson -->
<dependency>
    <groupId>com.alibaba</groupId>
    <artifactId>fastjson</artifactId>
    <version>1.1.38</version>
</dependency>

		<!-- 加入slf4j依赖包 -->
		<dependency>
			<groupId>org.slf4j</groupId>
			<artifactId>slf4j-log4j12</artifactId>
			<version>1.7.5</version>
		</dependency>
<!-- 加入dom4j依赖包 -->
		<dependency>
			<groupId>dom4j</groupId>
			<artifactId>dom4j</artifactId>
			<version>1.6.1</version>
		</dependency>
		<dependency>
			<groupId>jaxen</groupId>
			<artifactId>jaxen</artifactId>
			<version>1.1.4</version>
		</dependency>
<!-- 加入jstl依赖包 -->
		<dependency>
			<groupId>javax.servlet</groupId>
			<artifactId>jstl</artifactId>
			<version>1.2</version>
		</dependency>
		<dependency>
			<groupId>javax.servlet.jsp</groupId>
			<artifactId>jsp-api</artifactId>
			<version>2.2.1-b03</version>
			<scope>provided</scope>
		</dependency>
<!-- servlet -->
<dependency>
    <groupId>javax.servlet</groupId>
    <artifactId>servlet-api</artifactId>
    <version>3.0-alpha-1</version>
</dependency>

		<!-- io包 -->
		<dependency>
			<groupId>commons-io</groupId>
			<artifactId>commons-io</artifactId>
			<version>2.4</version>
		</dependency>
		<!-- 加入fileupload依赖包 -->
		<dependency>
			<groupId>commons-fileupload</groupId>
			<artifactId>commons-fileupload</artifactId>
			<version>1.3</version>
		</dependency>
<!-- 加入POI核心依赖 -->
		<dependency>
			<groupId>org.apache.poi</groupId>
			<artifactId>poi</artifactId>
			<version>3.10-beta2</version>
		</dependency>
		<!-- 为POI支持Office Open XML -->
		<dependency>
			<groupId>org.apache.poi</groupId>
			<artifactId>poi-ooxml</artifactId>
			<version>3.10-beta1</version>
		</dependency>
		<!-- 支持Word文档的操作 -->
		<dependency>
			<groupId>org.apache.poi</groupId>
			<artifactId>poi-scratchpad</artifactId>
			<version>3.1-FINAL</version>
		</dependency>

		<!-- dbutils依赖包 -->
		<dependency>
			<groupId>commons-dbutils</groupId>
			<artifactId>commons-dbutils</artifactId>
			<version>1.5</version>
		</dependency>
<!-- 加入javamelody依赖包 -->
		<dependency>
			<groupId>net.bull.javamelody</groupId>
			<artifactId>javamelody-core</artifactId>
			<version>1.47.0</version>
		</dependency>

	
		<!-- 加入batik依赖包,用于highcharts导出图表 -->
		<dependency>
			<groupId>org.apache.xmlgraphics</groupId>
			<artifactId>batik-codec</artifactId>
			<version>1.7</version>
		</dependency>
		
		<!-- 加入CXF依赖包 -->
		<dependency>
			<groupId>org.apache.cxf</groupId>
			<artifactId>cxf-rt-frontend-jaxws</artifactId>
			<version>2.7.7</version>
		</dependency>
			<!-- ehcache需要的依赖 -->
		<dependency>
			<groupId>org.springframework</groupId>
			<artifactId>spring-context-support</artifactId>
			<version>3.2.4.RELEASE</version>
		</dependency>
		<!-- 加入ehcache -->
		<dependency>
			<groupId>net.sf.ehcache</groupId>
			<artifactId>ehcache</artifactId>
			<version>2.7.4</version>
		</dependency>
		
<!-- hibernate 4 -->
<dependency>
    <groupId>org.hibernate</groupId>
    <artifactId>hibernate-core</artifactId>
    <version>4.3.2.Final</version>
</dependency>
 <dependency>
    <groupId>org.hibernate</groupId>
    <artifactId>hibernate-ehcache</artifactId>
    <version>4.3.2.Final</version>
</dependency>
<!-- spring 4 -->
<dependency>
    <groupId>org.springframework</groupId>
    <artifactId>spring-core</artifactId>
    <version>4.0.1.RELEASE</version>
</dependency>
<dependency>
    <groupId>org.springframework</groupId>
    <artifactId>spring-context</artifactId>
    <version>4.0.1.RELEASE</version>
</dependency>
<dependency>
    <groupId>org.springframework</groupId>
    <artifactId>spring-orm</artifactId>
    <version>4.0.1.RELEASE</version>
</dependency>
<dependency>
    <groupId>org.springframework</groupId>
    <artifactId>spring-web</artifactId>
    <version>4.0.1.RELEASE</version>
</dependency>
<dependency>
    <groupId>org.springframework</groupId>
    <artifactId>spring-beans</artifactId>
    <version>4.0.1.RELEASE</version>
</dependency>
<dependency>
    <groupId>org.springframework</groupId>
    <artifactId>spring-expression</artifactId>
    <version>4.0.1.RELEASE</version>
</dependency>

<!-- 加入struts2依赖包 -->
		<dependency>
			<groupId>org.apache.struts</groupId>
			<artifactId>struts2-core</artifactId>
			<version>2.3.16</version>
			<exclusions>
				<!-- 由于hibernate里面已经包含了javassist包,跟struts2的javassist冲突,所以struts2要排除这个引用 -->
				<exclusion>
					<groupId>javassist</groupId>
					<artifactId>javassist</artifactId>
				</exclusion>
			</exclusions>
		</dependency>
		<!-- struts2整合spring插件 -->
		<dependency>
			<groupId>org.apache.struts</groupId>
			<artifactId>struts2-spring-plugin</artifactId>
			<version>2.3.16</version>
		</dependency>
		<!-- struts2注解插件 -->
		<dependency>
			<groupId>org.apache.struts</groupId>
			<artifactId>struts2-convention-plugin</artifactId>
			<version>2.3.16</version>
		</dependency>
		<!-- 可以看到struts2应用里的Action等各种资源的影射情况 -->
		<!-- 可以使用类似http://localhost:8080/npntmaven/config-browser/showConstants.action的url来访问 -->
		<dependency>
			<groupId>org.apache.struts</groupId>
			<artifactId>struts2-config-browser-plugin</artifactId>
			<version>2.3.16</version>
		</dependency>
		
	</dependencies>


 
  <build>
    <plugins>
      <plugin>
        <artifactId>maven-war-plugin</artifactId>
      </plugin>
     <plugin>
        <artifactId>maven-compiler-plugin</artifactId>
        <configuration>
          <source>1.7</source>
          <target>1.7</target>
          	<encoding>UTF-8</encoding>
        </configuration>
      </plugin>
    </plugins>
  </build>
</project>