必要包:
antlr-2.7.6.jar aspectjrt.jar aspectjweaver.jar cglib-nodep-2.1_3.jar common-annotations.jar commons-beanutils-1.7.0.jar commons-chain-1.2.jar commons-collections-3.1.jar commons-dbcp.jar commons-digester-2.0.jar commons-fileupload-1.2.2.jar commons-io-2.0.1.jar commons-lang-2.5.jar commons-logging-1.1.1.jar commons-logging-api-1.1.jar commons-logging.jar commons-pool.jar commons-validator-1.3.1.jar dom4j-1.6.1.jar ehcache-1.2.3.jar ejb3-persistence.jar freemarker-2.3.16.jar hibernate-annotations.jar hibernate-cglib-repack-2.1_3.jar hibernate-commons-annotations.jar hibernate-entitymanager.jar hibernate3.jar jta-1.1.jar log4j.jar ognl-3.0.1.jar oro-2.0.8.jar slf4j-api-1.6.1.jar slf4j-log4j12-1.6.3.jar spring.jar struts-core-1.3.10.jar struts2-core-2.2.3.1.jar struts2-spring-plugin-2.2.3.1.jar tiles-api-2.0.6.jar tiles-core-2.0.6.jar tiles-jsp-2.0.6.jar xwork-core-2.2.3.1.jar mysql-connector-java-5.1.7-bin.jar javassist-3.7.ga.jar c3p0-0.9.1.jar javassist-3.12.0.GA.jar
spring配置文件applicationContext.xml的配置c3p0为数据源:
<?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:tx="http://www.springframework.org/schema/tx" xmlns:context="http://www.springframework.org/schema/context" xsi:schemaLocation=" http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.5.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.5.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.xsd"> <context:annotation-config /> <context:component-scan base-package="wxm" /> <context:property-placeholder location="classpath:jdbc.properties" /> <bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource" destroy-method="close"> <property name="driverClass" value="${driverClassName}" /> <property name="jdbcUrl" value="${url}" /> <property name="user" value="${username}" /> <property name="password" value="${password}" /> <!-- 连接池启动时的初始值 --> <property name="initialPoolSize" value="${initialSize}" /> <!-- 最大连接数 --> <property name="maxPoolSize" value="${maxActive}" /> <!-- 释放至 --> <property name="maxIdleTime" value="${maxIdle}" /> <!-- 避免来不及申请 --> <property name="acquireIncrement" value="${minIdle}" /> </bean> <bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean"> <property name="dataSource" ref="dataSource" /> <property name="mappingDirectoryLocations"> <list> <value>classpath:/wxm/beans/</value> </list> </property> <property name="hibernateProperties"> <props> <prop key="hibernate.dialect"> org.hibernate.dialect.MySQL5Dialect </prop> <prop key="hibernate.format_sql">true</prop> <prop key="hibernate.show_sql">true</prop> <prop key="hibernate.hbm2ddl.auto">update</prop> <prop key="hibernate.cache.use_second_level_cache"> true </prop> <prop key="hibernate.cache.use_query_cache">false</prop> <prop key="hibernate.cache.provider_class"> org.hibernate.cache.EhCacheProvider </prop> </props> </property> </bean> <bean id="txManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager"> <property name="sessionFactory"> <ref bean="sessionFactory" /> </property> </bean> <tx:annotation-driven transaction-manager="txManager" /> </beans>
hibernate的缓存ehcache.xml配置文件:
<?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="d:\cache" /> <defaultCache maxElementsInMemory="1000" eternal="false" timeToIdleSeconds="120" timeToLiveSeconds="120" overflowToDisk="true" diskPersistent="false" /> <cache name="wxm.beans.Person" maxElementsInMemory="100" eternal="false" timeToIdleSeconds="300" timeToLiveSeconds="600" overflowToDisk="true" diskPersistent="false" /> </ehcache>
<?xml version="1.0" encoding="UTF-8" ?> <!DOCTYPE struts PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 2.0//EN" "http://struts.apache.org/dtds/struts-2.0.dtd"> <struts> <include file="struts-employee.xml"></include> <constant name="struts.action.extension" value="do,action" /> <!-- 指定创建对象由spring来管理--> <constant name="struts.objectFactory" value="spring" /> <!-- 当struts的配置文件修改后,系统是否自动重新加载该文件,默认值为false(生产环境下使用),开发阶段最好打开 --> <constant name="struts.configuration.xml.reload" value="true" /> <!-- 开发模式下使用,这样可以打印出更详细的错误信息 --> <constant name="struts.devMode" value="true" /> <!-- 视图主题 --> <constant name="struts.ui.theme" value="simple" /> <!-- 是否可以动态方法调用 --> <constant name="struts.enable.DynamicMethodInvocation" value="true"> </constant> </struts>
最后是web.xml:
<?xml version="1.0" encoding="UTF-8"?> <web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"> <welcome-file-list> <welcome-file>index.jsp</welcome-file> </welcome-file-list> <!-- spring实例化 --> <listener> <listener-class> org.springframework.web.context.ContextLoaderListener </listener-class> </listener> <!-- spring配置文件读取内容参数 --> <context-param> <param-name>contextConfigLocation</param-name> <param-value>classpath:applicationContext*.xml</param-value> </context-param> <!-- struts2 --> <filter> <filter-name>struts2</filter-name> <filter-class> org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter </filter-class> </filter> <filter-mapping> <filter-name>struts2</filter-name> <url-pattern>/*</url-pattern> </filter-mapping> <!-- 延迟加载问题 --> <filter> <filter-name>OpenSessionInViewFilter</filter-name> <filter-class> org.springframework.orm.hibernate3.support.OpenSessionInViewFilter </filter-class> <init-param> <param-name>singleSession</param-name> <param-value>false</param-value> </init-param> </filter> <filter-mapping> <filter-name>OpenSessionInViewFilter</filter-name> <url-pattern>/*</url-pattern> </filter-mapping> </web-app>