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: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"
xsi:schemaLocation="
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">
<!-- 数据源配置 -->
<context:property-placeholder
location="classpath:dbConfig/mysql.properties" />
<bean id="dataSource"
class="com.mchange.v2.c3p0.ComboPooledDataSource">
<property name="driverClass" value="${jdbc.driverClassName}" />
<property name="jdbcUrl" value="${jdbc.url}" />
<property name="user" value="${jdbc.username}" />
<property name="password" value="${jdbc.password}" />
<property name="autoCommitOnClose" value="true" />
<property name="checkoutTimeout"
value="${cpool.checkoutTimeout}" />
<property name="initialPoolSize" value="${cpool.minPoolSize}" />
<property name="minPoolSize" value="${cpool.minPoolSize}" />
<property name="maxPoolSize" value="${cpool.maxPoolSize}" />
<property name="maxIdleTime" value="${cpool.maxIdleTime}" />
<property name="acquireIncrement"
value="${cpool.acquireIncrement}" />
<property name="maxIdleTimeExcessConnections"
value="${cpool.maxIdleTimeExcessConnections}" />
</bean>
<!-- session工厂 -->
<bean id="sessionFactory"
class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">
<property name="dataSource">
<ref bean="dataSource" />
</property>
<!-- 自动扫描注解方式配置的hibernate类文件 -->
<property name="packagesToScan">
<list>
<value>com.cdg</value>
</list>
</property>
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">${hibernate.dialect}</prop>
<prop key="hibernate.show_sql">${hibernate.show_sql}</prop>
<prop key="hibernate.format_sql">${hibernate.show_sql}</prop>
<prop key="hibernate.query.substitutions">${hibernate.query.substitutions}</prop>
<prop key="hibernate.default_batch_fetch_size">${hibernate.default_batch_fetch_size}</prop>
<prop key="hibernate.max_fetch_depth">${hibernate.max_fetch_depth}</prop>
<prop key="hibernate.generate_statistics">${hibernate.generate_statistics}</prop>
<prop key="hibernate.bytecode.use_reflection_optimizer">${hibernate.bytecode.use_reflection_optimizer}</prop>
<prop key="hibernate.cache.use_second_level_cache">${hibernate.cache.use_second_level_cache}</prop>
<prop key="hibernate.cache.use_query_cache">${hibernate.cache.use_query_cache}</prop>
<prop key="hibernate.cache.region.factory_class">${hibernate.cache.region.factory_class}</prop>
<!-- <prop key="net.sf.ehcache.configurationResourceName">/ehcache.xml</prop> -->
<prop key="hibernate.cache.use_structured_entries">${hibernate.cache.use_structured_entries}</prop>
</props>
</property>
</bean>
<!-- 配置事务管理器 -->
<bean id="transactionManager"
class="org.springframework.orm.hibernate4.HibernateTransactionManager">
<property name="sessionFactory" ref="sessionFactory" />
</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="change*" propagation="REQUIRED" />
<tx:method name="get*" propagation="REQUIRED" read-only="true" />
<tx:method name="find*" propagation="REQUIRED" read-only="true" />
<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"/>-->
<!-- 配置事务切面 -->
<aop:config>
<aop:pointcut id="serviceOperation"
expression="execution(* com.cdg.iservice..*.*(..))" />
<aop:advisor advice-ref="txAdvice" pointcut-ref="serviceOperation" />
</aop:config>
<!-- 自动加载构建bean -->
<context:component-scan base-package="com.cdg" />
</beans>
mysql.properties
jdbc.driverClassName=com.mysql.jdbc.Driver
jdbc.url=jdbc\:mysql\://localhost\:3306/mytest?characterEncoding\=UTF-8
jdbc.username=root
jdbc.password=123456
cpool.checkoutTimeout=5000
cpool.minPoolSize=20
cpool.maxPoolSize=50
cpool.maxIdleTime=7200
cpool.maxIdleTimeExcessConnections=1800
cpool.acquireIncrement=10
hibernate.dialect=org.hibernate.dialect.MySQLInnoDBDialect
hibernate.hbm2ddl.auto=none
hibernate.show_sql=false
hibernate.query.substitutions=true 1, false 0
hibernate.default_batch_fetch_size=16
hibernate.max_fetch_depth=2
hibernate.bytecode.use_reflection_optimizer=true
hibernate.cache.use_second_level_cache=true
hibernate.cache.use_query_cache=true
hibernate.cache.region.factory_class=org.hibernate.cache.EhCacheRegionFactory
net.sf.ehcache.configurationResourceName=/ehcache.xml
hibernate.cache.use_structured_entries=true
hibernate.generate_statistics=true
ehcache.xml
<?xml version="1.0" encoding="UTF-8"?>
<ehcache name="javass">
<defaultCache maxElementsInMemory="1000" eternal="false"
timeToIdleSeconds="3600" timeToLiveSeconds="3600"
overflowToDisk="false">
</defaultCache>
<!--
<cache name="com.cdg.bean.UserModel"
maxElementsInMemory="2000" eternal="false" timeToIdleSeconds="3600"
timeToLiveSeconds="3600" overflowToDisk="false">
</cache>
-->
<cache name="org.hibernate.cache.internal.StandardQueryCache"
maxElementsInMemory="5000" eternal="false" timeToLiveSeconds="3600"
overflowToDisk="false" />
<cache name="org.hibernate.cache.spi.UpdateTimestampsCache"
maxElementsInMemory="5000" eternal="true" overflowToDisk="true" />
</ehcache>
log4j.properties
log4j.rootCategory=INFO,stdout,fileout
log4j.logger.com.fiscal=INFO
log4j.logger.com.system=INFO
log4j.logger.com.ibatis=INFO
log4j.logger.com.ibatis.common.jdbc.SimpleDataSource=INFO
log4j.logger.com.ibatis.common.jdbc.ScriptRunner=INFO
log4j.logger.com.ibatis.sqlmap.engine.impl.SqlMapClientDelegate=INFO
log4j.logger.java.sql.Connection=INFO
log4j.logger.java.sql.ResultSet=INFO
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.fileout=org.apache.log4j.RollingFileAppender
log4j.appender.fileout.File=E\:\\myLogs.log
log4j.appender.fileout.MaxFileSize=10000KB
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern=[%-5p] %d{yyyy-MM-dd HH:mm:ss} :%m%n
log4j.appender.fileout.layout=org.apache.log4j.PatternLayout
log4j.appender.fileout.layout.ConversionPattern=[%-5p]_%d{yyyy-MM-dd HH:mm:ss} :%m%n
struts.xml
<?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>
<constant name="struts.action.extension" value="action" />
<constant name="struts.enable.DynamicMethodInvocation"
value="false" />
<constant name="struts.devMode" value="false" />
<constant name="struts.multipart.saveDir" value="/upload"></constant>
<!-- 加载struts2配置文件 -->
<include file="strutsConfig/zTree-action.xml" />
<package name="struts2" extends="struts-default,json-default" namespace="/">
<!-- -->
<interceptors>
<interceptor name="login"
class="com.cdg.action.LoginInterceptor">
</interceptor>
<interceptor-stack name="loginCheck">
<interceptor-ref name="login"></interceptor-ref>
<interceptor-ref name="defaultStack"></interceptor-ref>
</interceptor-stack>
</interceptors>
<default-interceptor-ref name="loginCheck"></default-interceptor-ref>
<global-results>
<!-- 下面定义的结果对所有的Action都有效 -->
<result name="error">/error.jsp</result>
<result name="login">/login.jsp</result>
</global-results>
<global-exception-mappings>
<!-- 指Action抛出Exception异常时,转入名为exception的结果。 -->
<exception-mapping result="error"
exception="java.lang.Throwable" />
</global-exception-mappings>
</package>
</struts>
web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="3.0" 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_3_0.xsd">
<display-name></display-name>
<!-- 添加对spring的支持 -->
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>
classpath:springConfig/applicationContext.xml
</param-value>
</context-param>
<listener>
<listener-class>
org.springframework.web.context.ContextLoaderListener
</listener-class>
</listener>
<!-- 添加对struts2的支持 -->
<filter>
<filter-name>struts2</filter-name>
<filter-class>
org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter
</filter-class>
</filter>
<!-- 当hibernate+spring配合使用的时候,如果设置了lazy=true,那么在读取数据的时候,当读取了父数据后,
hibernate会自动关闭session,这样,当要使用子数据的时候,系统会抛出lazyinit的错误,
这时就需要使用spring提供的 OpenSessionInViewFilter,OpenSessionInViewFilter主要是保持Session状态
知道request将全部页面发送到客户端,这样就可以解决延迟加载带来的问题 -->
<filter>
<filter-name>openSessionInViewFilter</filter-name>
<filter-class>
org.springframework.orm.hibernate4.support.OpenSessionInViewFilter
</filter-class>
<init-param>
<param-name>singleSession</param-name>
<param-value>true</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>struts2</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<filter-mapping>
<filter-name>openSessionInViewFilter</filter-name>
<url-pattern>*.do,*.action</url-pattern>
</filter-mapping>
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
<error-page>
<error-code>500</error-code>
<location>/error.jsp</location>
</error-page>
<error-page>
<error-code>404</error-code>
<location>/error.jsp</location>
</error-page>
</web-app>
LoginInterceptor.java 拦截器
package com.cdg.action;
import javax.servlet.http.HttpServletRequest;
import org.apache.struts2.ServletActionContext;
import com.opensymphony.xwork2.Action;
import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionInvocation;
import com.opensymphony.xwork2.interceptor.AbstractInterceptor;
public class LoginInterceptor extends AbstractInterceptor {
private static final long serialVersionUID = -7195381482219767316L;
@Override
public String intercept(ActionInvocation invocation) throws Exception {
// 取得请求相关的ActionContext实例
ActionContext ctx = invocation.getInvocationContext();
String user = (String)ctx.getSession().get("user");
HttpServletRequest request = (HttpServletRequest) ctx.get(ServletActionContext.HTTP_REQUEST);
System.out.println(request.getRequestURI());
// 如果没有登陆,或者登陆所有的用户名不是???,都返回重新登陆
System.out.println("test");
if (user != null) {
System.out.println("test");
return invocation.invoke();
}
ctx.put("tip", "你还没有登录");
return Action.LOGIN;
}
}
antlr-2.7.7.jar
aopalliance-1.0.jar
asm-5.0.2.jar
asm-commons-5.0.2.jar
aspectjweaver.jar
axis.jar
c3p0-0.9.1.2.jar
cglib-2.2.jar
commons-beanutils-1.9.2.jar
commons-collections4-4.0.jar
commons-dbcp-1.4.jar
commons-email-1.3.3.jar
commons-fileupload-1.3.1.jar
commons-io-2.4.jar
commons-lang3-3.3.2.jar
commons-logging-1.2.jar
commons-pool2-2.0.jar
cxf-core-3.0.2.jar
cxf-rt-bindings-soap-3.0.2.jar
cxf-rt-databinding-jaxb-3.0.2.jar
cxf-rt-frontend-jaxws-3.0.2.jar
cxf-rt-frontend-simple-3.0.2.jar
cxf-rt-transports-http-3.0.2.jar
cxf-rt-transports-http-jetty-3.0.2.jar
cxf-rt-wsdl-3.0.2.jar
directjngine.2.2.jar
dom4j-1.6.1.jar
freemarker-2.3.16.jar
gson-2.2.1.jar
guava-18.0.jar
hibernate-commons-annotations-4.0.5.Final.jar
hibernate-core-4.3.7.Final.jar
hibernate-jpa-2.1-api-1.0.0.Final.jar
javassist.jar
javassist-3.7.ga.jar
javax.wsdl_1.6.2.v201012040545.jar
jaxb-impl-2.2.1.jar
jaxrpc.jar
jta-1.1.jar
log4j-1.2.15.jar
mail-1.4.jar
mysql-connector-java-5.0.8-bin.jar
neethi-3.0.3.jar
ognl-3.0.8.jar
ojdbc14.jar
poi-3.9.jar
quartz-2.2.1.jar
quartz-jobs-2.2.1.jar
saaj.jar
shiro-all-1.2.2.jar
slf4j-api-1.7.7.jar
slf4j-simple-1.7.7.jar
spring-aop-4.1.3.RELEASE.jar
spring-beans-4.1.3.RELEASE.jar
spring-context-4.1.3.RELEASE.jar
spring-core-4.1.3.RELEASE.jar
spring-expression-4.1.3.RELEASE.jar
spring-jdbc-4.1.3.RELEASE.jar
spring-orm-4.1.3.RELEASE.jar
spring-tx-4.1.3.RELEASE.jar
spring-web-4.1.3.RELEASE.jar
spring-webmvc-4.1.3.RELEASE.jar
spring-websocket-4.1.3.RELEASE.jar
stax2-api-3.1.4.jar
struts2-convention-plugin-2.3.20.jar
struts2-core-2.3.20.jar
struts2-json-plugin-2.3.20.jar
struts2-spring-plugin-2.3.20.jar
woodstox-core-asl-4.4.1.jar
wsdl4j-1.6.3.jar
xml-resolver-1.2.jar
XmlSchema-1.4.5.jar
xmlschema-core-2.1.0.jar
xstream-1.4.7.jar
xwork-core-2.3.20.jar
yuicompressor-2.4.2.jar
commons-httpclient.jar
jboss-logging-3.1.3.GA.jar
hibernate-ehcache-4.3.6.Final.jar
ehcache-core-2.6.9.jar