今天终于把项目框架搭好了,是目前ssh最新的架构,并且跑起来了,以下是我的配置的文件及步骤,与大家分享一下:
1,把项目需要的jar全部加到项目的WEB-INF的lib文件下,下载地址:lib.jar
2,所有的配置文件只要放到src下面就可以了,下面就废话少说,直接上代码了
web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID" version="2.5">
<display-name>hp_ssh</display-name>
<welcome-file-list>
<welcome-file>index.html</welcome-file>
<welcome-file>index.htm</welcome-file>
<welcome-file>index.jsp</welcome-file>
<welcome-file>default.html</welcome-file>
<welcome-file>default.htm</welcome-file>
<welcome-file>default.jsp</welcome-file>
</welcome-file-list>
<!-- OpenSessionInViewFilter的主要功能是用来把一个Hibernate Session和一次完整的请求过程对应的线程相绑定。目的是为了实现"Open
Session in View"的模式。例如: 它允许在事务提交之后延迟加载显示所需要的对象 -->
<filter>
<filter-name>hibernateSessionFilter</filter-name>
<filter-class>
org.springframework.orm.hibernate4.support.OpenSessionInViewFilter
</filter-class>
</filter>
<filter-mapping>
<filter-name>hibernateSessionFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<!-- 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>
<!-- 负责处理由JavaBeans Introspector的使用而引起的缓冲泄露 -->
<listener>
<listener-class>
org.springframework.web.util.IntrospectorCleanupListener</listener-class>
</listener>
<!-- 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>
</web-app>
struts2.xml
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE struts PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 2.1//EN"
"http://struts.apache.org/dtds/struts-2.1.dtd">
<struts>
<constant name="struts.custom.i18n.resources" value="message" />
<package name="struts2" extends="struts-default">
<global-results>
<result name="login">/login.jsp</result>
<result name="load">/modiUser.jsp</result>
</global-results>
<action name="userLoginAction" class="userAction" method="login">
<result name="success" type="redirectAction">userListAction!findUserList</result>
</action>
<action name="userListAction" class="userAction" method="findUserList">
<result name="list">userList.jsp</result>
</action>
<action name="userAddAction" class="userAction" method="addUser">
<result name="list" type="redirectAction">userListAction!findUserList</result>
</action>
<action name="userDeleteAction" class="userAction" method="deleteUser">
<result name="list" type="redirectAction">userListAction!findUserList</result>
</action>
<action name="userLoadAction" class="userAction" method="loadUser">
<result name="load">/modiUser.jsp</result>
</action>
<action name="userUpdateAction" class="userAction" method="updateUser">
<result name="list" type="redirectAction">userListAction!findUserList</result>
</action>
</package>
</struts>
hibernate.query.substitutions = true 1, false 0, yes 'Y', no 'N'
#\u6570\u636e\u5e93\u65b9\u8a00
hibernate.dialect = org.hibernate.dialect.Oracle10gDialect
#hibernate.dialect = org.hibernate.dialect.MySQL5Dialect
hibernate.transaction.factory_class = org.hibernate.transaction.JDBCTransactionFactory
#Enable Hibernate's automatic session context management
hibernate.current_session_context_class = org.springframework.orm.hibernate4.SpringSessionContext
hibernate.show_sql = true
#hibernate.hbm2ddl.auto = update
hibernate.max_fetch_depth = 1
hibernate.default_batch_fetch_size = 30
hibernate.use_identifer_rollback = true
hibernate.jdbc.fetch_size = 25
hibernate.jdbc.batch_size = 30
hibernate.jdbc.use_scrollable_resultset = true
hibernate.jdbc.use_streams_for_binary = true
hibernate.cache.use_second_level_cache = false
hibernate.cache.provider_class = org.hibernate.cache.internal.NoCacheProvider
applicationContext.properties
# jdbc connection info
# for oracle
jdbc.connection.driver_class=oracle.jdbc.driver.OracleDriver
jdbc.connection.url=jdbc:oracle:thin:@192.168.3.83:1521:orcl
jdbc.connection.username=duyunyun
jdbc.connection.password=duyunyun
# for mysql
#jdbc.connection.driver_class=com.mysql.jdbc.Driver
#jdbc.connection.url=jdbc:mysql://127.0.0.1:3306/shwdms-base?characterEncoding=UTF-8
#jdbc.connection.username=root
#jdbc.connection.password=!QAZ2wsx#EDC
#
jdbc.pool.c3p0.acquire_increment=2
jdbc.pool.c3p0.max_size=2
jdbc.pool.c3p0.min_size=1
jdbc.pool.c3p0.preferred_test_query='SELECT 1'
jdbc.pool.c3p0.idle_connection_test_period=18000
jdbc.pool.c3p0.max_idle_time=25000
applicationContext.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:context="http://www.springframework.org/schema/context"
xmlns:jee="http://www.springframework.org/schema/jee" xmlns:p="http://www.springframework.org/schema/p"
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-3.1.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.1.xsd
http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-3.1.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.1.xsd
http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-3.1.xsd">
<!-- 获取数据库访问资源文件 -->
<bean id="propertyConfigurer"
class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="locations">
<list>
<value>classpath:applicationContext.properties</value>
</list>
</property>
</bean>
<!-- 获取数据源配置 -->
<bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource"
destroy-method="close">
<property name="driverClass" value="${jdbc.connection.driver_class}" />
<property name="jdbcUrl" value="${jdbc.connection.url}" />
<property name="idleConnectionTestPeriod" value="${jdbc.pool.c3p0.idle_connection_test_period}" />
<property name="preferredTestQuery" value="${jdbc.pool.c3p0.preferred_test_query}" />
<property name="maxIdleTime" value="${jdbc.pool.c3p0.max_idle_time}" />
<property name="properties">
<props>
<prop key="user">${jdbc.connection.username}</prop>
<prop key="password">${jdbc.connection.password}</prop>
<prop key="c3p0.acquire_increment">${jdbc.pool.c3p0.acquire_increment}</prop>
<prop key="c3p0.max_size">${jdbc.pool.c3p0.max_size}</prop>
<prop key="c3p0.min_size">${jdbc.pool.c3p0.min_size}</prop>
</props>
</property>
</bean>
<!-- connect to hibernate -->
<bean id="sessionFactory"
class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">
<!-- 连接数据库 -->
<property name="dataSource">
<ref bean="dataSource" />
</property>
<!-- hibernate 自身属性 -->
<property name="hibernateProperties">
<bean
class="org.springframework.beans.factory.config.PropertiesFactoryBean">
<property name="location">
<value>classpath:hibernate.properties</value>
</property>
</bean>
</property>
<!-- 映射文件 -->
<property name="mappingResources">
<list>
<value>com\hncst\model\User.hbm.xml</value>
</list>
</property>
</bean>
<!-- User管理 -->
<bean id="userDao" class="com.hncst.dao.impl.UserDaoImpl">
<property name="sessionFactory" ref="sessionFactory"></property>
</bean>
<bean id="userService" class="com.hncst.service.impl.UserServiceImpl">
<property name="userDao" ref="userDao"/>
</bean>
<bean id="userAction" class="com.hncst.action.UserAction" scope="prototype">
<property name="userService" ref="userService" />
</bean>
<!-- 配置事务管理器 -->
<bean id="transactionManager"
class="org.springframework.orm.hibernate4.HibernateTransactionManager">
<property name="sessionFactory">
<ref bean="sessionFactory" />
</property>
</bean>
<!--事务具体处理方式 -->
<bean id="transactionInterceptor"
class="org.springframework.transaction.interceptor.TransactionInterceptor">
<property name="transactionManager">
<ref bean="transactionManager" />
</property>
<property name="transactionAttributes">
<props>
<prop key="save*">PROPAGATION_REQUIRED</prop>
<prop key="add*">PROPAGATION_REQUIRED</prop>
<prop key="set*">PROPAGATION_REQUIRED</prop>
<prop key="update*">PROPAGATION_REQUIRED</prop>
<prop key="delete*">PROPAGATION_REQUIRED</prop>
<prop key="find*">PROPAGATION_REQUIRED,readOnly</prop>
<prop key="valid*">PROPAGATION_REQUIRED,readOnly</prop>
<prop key="get*">PROPAGATION_REQUIRED,readOnly</prop>
<prop key="query*">PROPAGATION_REQUIRED,readOnly</prop>
<prop key="summary*">PROPAGATION_REQUIRED,readOnly</prop>
</props>
</property>
</bean>
<!-- 自动创建代理: 事务处理层在业务逻辑层 -->
<bean
class="org.springframework.aop.framework.autoproxy.BeanNameAutoProxyCreator">
<property name="beanNames">
<list>
<value>*Service</value>
</list>
</property>
<property name="interceptorNames">
<value>transactionInterceptor</value>
</property>
</bean>
</beans>
项目结构
3,主要的配置文件都在了,其它功能的代码就自己按自己思路写就可以了