框架SSH整合的配置文件
2017-02-24 10:43
531 查看
1.web.xml的配置文件
<?xmlversion="1.0"encoding="UTF-8"?>
<web-appversion="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/javaeehttp://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"> <display-name></display-name>
<!--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>
<!--Spring配置-->
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:bean.xml</param-value>
</context-param>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
</web-app>
2.Spring的总配置文件
<?xmlversion="1.0"encoding="UTF-8"?>
<beansxmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:p="http://www.springframework.org/schema/p"
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/beanshttp://www.springframework.org/schema/beans/spring-beans.xsdhttp://www.springframework.org/schema/contexthttp://www.springframework.org/schema/context/spring-context.xsdhttp://www.springframework.org/schema/aophttp://www.springframework.org/schema/aop/spring-aop.xsdhttp://www.springframework.org/schema/txhttp://www.springframework.org/schema/tx/spring-tx.xsd">
<!--引入其他配置文件-->
<importresource="config/bean-base.xml"/>
<importresource="config/bean-dao.xml"/>
<importresource="config/bean-service.xml"/>
<importresource="config/bean-action.xml"/>
</beans>
3.Spring的基础配置文件
<?xmlversion="1.0"encoding="UTF-8"?>
<beansxmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:p="http://www.springframework.org/schema/p"
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/beanshttp://www.springframework.org/schema/beans/spring-beans.xsdhttp://www.springframework.org/schema/contexthttp://www.springframework.org/schema/context/spring-context.xsdhttp://www.springframework.org/schema/aophttp://www.springframework.org/schema/aop/spring-aop.xsdhttp://www.springframework.org/schema/txhttp://www.springframework.org/schema/tx/spring-tx.xsd">
<!--所有配置的公共部门-->
<!--1)连接池实例-->
<beanid="dataSource"class="com.mchange.v2.c3p0.ComboPooledDataSource">
<propertyname="driverClass"value="com.mysql.jdbc.Driver"></property>
<propertyname="jdbcUrl"value="jdbc:mysql://localhost:3306/test"></property>
<propertyname="user"value="root"></property>
<propertyname="password"
4000
value="root"></property>
<propertyname="initialPoolSize"value="3"></property>
<propertyname="maxPoolSize"value="6"></property>
</bean>
<!--2)SessionFactory实例创建-->
<!--所有的配置都由spring维护(项目中不需要hibernate.cfg.xml啦)-->
<beanid="sessionFactory"class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<!--a.连接池-->
<propertyname="dataSource"ref="dataSource"></property>
<!--b.hibernate常用配置:方言、显示sql、自动建表等-->
<propertyname="hibernateProperties">
<props>
<propkey="hibernate.dialect">org.hibernate.dialect.MySQLDialect</prop>
<propkey="hibernate.show_sql">true</prop>
<propkey="hibernate.hbm2ddl.auto">update</prop>
</props>
</property>
<!--c.映射配置-->
<propertyname="mappingLocations">
<list>
<value>classpath:wge/learn/entity/*.hbm.xml</value>
</list>
</property>
</bean>
<!--3)事务配置-->
<!--#事务管理器-->
<beanid="txManager"class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<propertyname="sessionFactory"ref="sessionFactory"></property>
</bean>
<!--#事务增强-->
<tx:adviceid="txAdvice"transaction-manager="txManager">
<tx:attributes>
<tx:methodname="*"read-only="false"/>
</tx:attributes>
</tx:advice>
<!--#AOP配置-->
<aop:config>
<aop:pointcutexpression="execution(*wge.learn.service.impl.*.*(..))"id="pt"/>
<aop:advisoradvice-ref="txAdvice"pointcut-ref="pt"/>
</aop:config>
</beans>
4.Spring-各层的配置文件
<!--Dao注入SessionFactory-->
<beanid="deptDao"class="wge.learn.dao.impl.DeptDao">
<propertyname="sessionFactory"ref="sessionFactory"></property>
</bean>
<beanid="employeeDao"class="wge.learn.dao.impl.EmployeeDao">
<propertyname="sessionFactory"ref="sessionFactory"></property>
</bean>
5.Hibernate的实体配置文件
<hibernate-mappingpackage="wge.learn.entity">
<classname="Dept"table="t_dept">
<idname="id"column="deptId">
<generatorclass="native"></generator>
</id>
<propertyname="name"column="deptName"></property>
</class>
</hibernate-mapping>
6.Struts2的配置文件
<?xmlversion="1.0"encoding="UTF-8"?>
<!DOCTYPEstrutsPUBLIC
"-//ApacheSoftwareFoundation//DTDStrutsConfiguration2.3//EN"
"http://struts.apache.org/dtds/struts-2.3.dtd">
<struts>
<packagename="emp"extends="struts-default">
<actionname="emp_*"class="employeeAction"method="{1}">
<!--列表展示-->
<resultname="success">/WEB-INF/list.jsp</result>
<resultname="add">/WEB-INF/add.jsp</result>
<resultname="list">/WEB-INF/list.jsp</result>
<resultname="edit">/WEB-INF/edit.jsp</result>
<!--添加成功,进入列表(防止刷新就多一条记录问题,所以用重定向)-->
<resultname="listAction"type="redirectAction">emp_list</result>
</action>
</package>
</struts>
<?xmlversion="1.0"encoding="UTF-8"?>
<web-appversion="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
<!--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>
<!--Spring配置-->
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:bean.xml</param-value>
</context-param>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
</web-app>
2.Spring的总配置文件
<?xmlversion="1.0"encoding="UTF-8"?>
<beansxmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:p="http://www.springframework.org/schema/p"
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
<!--引入其他配置文件-->
<importresource="config/bean-base.xml"/>
<importresource="config/bean-dao.xml"/>
<importresource="config/bean-service.xml"/>
<importresource="config/bean-action.xml"/>
</beans>
3.Spring的基础配置文件
<?xmlversion="1.0"encoding="UTF-8"?>
<beansxmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:p="http://www.springframework.org/schema/p"
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
<!--所有配置的公共部门-->
<!--1)连接池实例-->
<beanid="dataSource"class="com.mchange.v2.c3p0.ComboPooledDataSource">
<propertyname="driverClass"value="com.mysql.jdbc.Driver"></property>
<propertyname="jdbcUrl"value="jdbc:mysql://localhost:3306/test"></property>
<propertyname="user"value="root"></property>
<propertyname="password"
4000
value="root"></property>
<propertyname="initialPoolSize"value="3"></property>
<propertyname="maxPoolSize"value="6"></property>
</bean>
<!--2)SessionFactory实例创建-->
<!--所有的配置都由spring维护(项目中不需要hibernate.cfg.xml啦)-->
<beanid="sessionFactory"class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<!--a.连接池-->
<propertyname="dataSource"ref="dataSource"></property>
<!--b.hibernate常用配置:方言、显示sql、自动建表等-->
<propertyname="hibernateProperties">
<props>
<propkey="hibernate.dialect">org.hibernate.dialect.MySQLDialect</prop>
<propkey="hibernate.show_sql">true</prop>
<propkey="hibernate.hbm2ddl.auto">update</prop>
</props>
</property>
<!--c.映射配置-->
<propertyname="mappingLocations">
<list>
<value>classpath:wge/learn/entity/*.hbm.xml</value>
</list>
</property>
</bean>
<!--3)事务配置-->
<!--#事务管理器-->
<beanid="txManager"class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<propertyname="sessionFactory"ref="sessionFactory"></property>
</bean>
<!--#事务增强-->
<tx:adviceid="txAdvice"transaction-manager="txManager">
<tx:attributes>
<tx:methodname="*"read-only="false"/>
</tx:attributes>
</tx:advice>
<!--#AOP配置-->
<aop:config>
<aop:pointcutexpression="execution(*wge.learn.service.impl.*.*(..))"id="pt"/>
<aop:advisoradvice-ref="txAdvice"pointcut-ref="pt"/>
</aop:config>
</beans>
4.Spring-各层的配置文件
<!--Dao注入SessionFactory-->
<beanid="deptDao"class="wge.learn.dao.impl.DeptDao">
<propertyname="sessionFactory"ref="sessionFactory"></property>
</bean>
<beanid="employeeDao"class="wge.learn.dao.impl.EmployeeDao">
<propertyname="sessionFactory"ref="sessionFactory"></property>
</bean>
<!--Service需要注入Dao-->
<beanid="deptService"class="wge.learn.service.impl.DeptService">
<propertyname="deptDao"ref="deptDao"></property>
</bean>
<beanid="employeeService"class="wge.learn.service.impl.EmployeeService">
<propertyname="employeeDao"ref="employeeDao"></property>
</bean>
<beanid="employeeAction"class="wge.learn.action.EmployeeAction">
<propertyname="employeeService"ref="employeeService"></property>
<propertyname="deptService"ref="deptService"></property>
</bean>
5.Hibernate的实体配置文件
<hibernate-mappingpackage="wge.learn.entity">
<classname="Dept"table="t_dept">
<idname="id"column="deptId">
<generatorclass="native"></generator>
</id>
<propertyname="name"column="deptName"></property>
</class>
</hibernate-mapping>
6.Struts2的配置文件
<?xmlversion="1.0"encoding="UTF-8"?>
<!DOCTYPEstrutsPUBLIC
"-//ApacheSoftwareFoundation//DTDStrutsConfiguration2.3//EN"
"http://struts.apache.org/dtds/struts-2.3.dtd">
<struts>
<packagename="emp"extends="struts-default">
<actionname="emp_*"class="employeeAction"method="{1}">
<!--列表展示-->
<resultname="success">/WEB-INF/list.jsp</result>
<resultname="add">/WEB-INF/add.jsp</result>
<resultname="list">/WEB-INF/list.jsp</result>
<resultname="edit">/WEB-INF/edit.jsp</result>
<!--添加成功,进入列表(防止刷新就多一条记录问题,所以用重定向)-->
<resultname="listAction"type="redirectAction">emp_list</result>
</action>
</package>
</struts>
相关文章推荐
- 三大框架SSH(struts2+spring+hibernate)整合时相关配置文件的模板
- 框架 day39-42 SSH整合练习项目CRM(配置文件,增删改查,ajax,上传/下载,分页,BaseDao/Action,MD5)
- ssh三大框架整合配置文件及测试代码
- SSH三大框架整合使用的配置文件 注解实现
- SSH三大框架整合后的配置文件详解
- 三大框架(ssh)整合之配置文件
- 三大框架SSH(struts2+spring+hibernate)整合时相关配置文件的模板
- 关于SSH三大框架整合——配置文件方式、配置文件+注解方式
- 三大框架SSH(struts2+spring+hibernate)整合时相关配置文件的模板
- SSH之三大框架整合配置文件
- 三大框架整合文件配置
- ssh三大框架整合的配置
- SSH:SSH(Struts1 + Spring + hibernate)整合之配置文件
- SSH三大框架整合配置详细步骤(1)
- Struts2——SSH (Spring+Struts+Hibernate)框架搭建之配置文件序列一
- SSH整合之配置文件
- Hibernate——SSH (Spring+Struts+Hibernate)框架搭建之配置文件序列四
- SSH整合之配置文件
- SSH三大框架整合配置详细步骤(3)
- Spring——SSH (Spring+Struts+Hibernate)框架搭建之配置文件序列二