学习三大框架Struts2 、 Hibernate 、 Spring时,涉及到三大框架的配置文件以及整合。
2017-12-21 15:56
691 查看
今天就来详细写写三大框架配置文件的详细内容。
一 Spring的applicationContext.xml中的配置:
<?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"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.0.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-3.0.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-3.0.xsd">
<!-- 配置由Spring IoC容器托管对象对应的被注解的类所在的包 -->
<context:component-scanbase-package="com.leipengzj"/>
<!-- 配置通过自动生成代理类实现AOP功能 -->
<aop:aspectj-autoproxy/>
<!--DateSource 使用c3p0连接池-->
<beanid="dateSource"class="com.mchange.v2.c3p0.ComboPooledDateSource"destroy-method="close">
<propertyname="driverClass"value="com.mysql.jdbc.Driver"></property>
<propertyname="jdbcUrl"value="jdbc:mysql:/3306/leiepngzj_table"></property>
<propertyname="user"value="root"></property>
<propertyname="password"value="root"></property>
</bean>
<!-- SessionFactory 配置 配置Spring提供的支持注解ORM映射的Hibernate会话工厂-->
<beanid="sessionFactory"class="org.springframework.orm.hibernate3.annotation">
<propertyname="dateSource"ref="dateSource"></property>
<propertyname="congifLocation"value="classpath:hibernate.cfg.xml"></property>
</bean>
<!-- 配置spring基于注解的声明式事务管理 -->
<beanid="transactionManager"class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<!-- 通过setter注入Hibernate会话工厂
-->
<propertyname="sessionFactory"ref="sessionFactory"></property>
</bean>
<tx:annotation-driventransaction-manager="transactionManager"/>
</beans>
二 Hibernate.cfg.xml配置:
<?xmlversion='1.0'encoding='UTF-8'?>
<!DOCTYPEhibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<!-- Generated by MyEclipse Hibernate Tools. -->
<hibernate-configuration>
<session-factory>
<!-- 数据库连接信息 ,其他的写到了spring配置文件中去 -->
<propertyname="dialect">org.hibernate.dialect.MySQLDialect</property>
<!-- 其他配置 -->
<propertyname="show_sql">true</property>
<propertyname="hbm2ddl.auto">update</property>
<!-- 导入映射配置 -->
<mappingresource="../../.hbm.xml"/>
<mappingresource="../../.hbm.xml"/>
<mappingresource="../../.hbm.xml"/>
</session-factory>
</hibernate-configuration>
三 struts.xml中的配置文件:
<?xmlversion="1.0"encoding="UTF-8"?>
<!DOCTYPE strutsPUBLIC "-//Apache
Software Foundation//DTD Struts Configuration 2.1//EN""http://struts.apache.org/dtds/struts-2.1.dtd">
<struts>
<!-- 配置为开发模式 -->
<constantname="struts.devMode"value="true"></constant>
<!-- 配置扩展名为action -->
<constantname="struts.action.extension"value="action"></constant>
<!-- 当struts配置文件修改时,系统是否自动重新加载该文件,默认false,开发阶段最好打开 -->
<constantname="struts.configuration.xml.reload"value="true"></constant>
<!-- 全局视图 -->
<packagename="LunTanSystem"extends="struts-default">
<global-results>
<resultname="error">/error.jsp</result>
<resultname="ajax">/ajax.jsp</result>
<resultname="noLogin">/login.jsp</result>
</global-results>
<!-- 当与action整合后,class属性写的就是Spring中bean的属性 -->
<actionname="test"class="testAction">
<resultname="success">/test.jsp</result>
</action>
</package>
</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">
<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的监听器,用于初始化ApplicationContext.xml -->
<listener>
<listener-class>org.springframework.web.context.ContextLoader</listener-class>
</listener>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:applicationContext*.xml</param-value>
</context-param>
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
</web-app>
一 Spring的applicationContext.xml中的配置:
<?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"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.0.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-3.0.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-3.0.xsd">
<!-- 配置由Spring IoC容器托管对象对应的被注解的类所在的包 -->
<context:component-scanbase-package="com.leipengzj"/>
<!-- 配置通过自动生成代理类实现AOP功能 -->
<aop:aspectj-autoproxy/>
<!--DateSource 使用c3p0连接池-->
<beanid="dateSource"class="com.mchange.v2.c3p0.ComboPooledDateSource"destroy-method="close">
<propertyname="driverClass"value="com.mysql.jdbc.Driver"></property>
<propertyname="jdbcUrl"value="jdbc:mysql:/3306/leiepngzj_table"></property>
<propertyname="user"value="root"></property>
<propertyname="password"value="root"></property>
</bean>
<!-- SessionFactory 配置 配置Spring提供的支持注解ORM映射的Hibernate会话工厂-->
<beanid="sessionFactory"class="org.springframework.orm.hibernate3.annotation">
<propertyname="dateSource"ref="dateSource"></property>
<propertyname="congifLocation"value="classpath:hibernate.cfg.xml"></property>
</bean>
<!-- 配置spring基于注解的声明式事务管理 -->
<beanid="transactionManager"class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<!-- 通过setter注入Hibernate会话工厂
-->
<propertyname="sessionFactory"ref="sessionFactory"></property>
</bean>
<tx:annotation-driventransaction-manager="transactionManager"/>
</beans>
二 Hibernate.cfg.xml配置:
<?xmlversion='1.0'encoding='UTF-8'?>
<!DOCTYPEhibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<!-- Generated by MyEclipse Hibernate Tools. -->
<hibernate-configuration>
<session-factory>
<!-- 数据库连接信息 ,其他的写到了spring配置文件中去 -->
<propertyname="dialect">org.hibernate.dialect.MySQLDialect</property>
<!-- 其他配置 -->
<propertyname="show_sql">true</property>
<propertyname="hbm2ddl.auto">update</property>
<!-- 导入映射配置 -->
<mappingresource="../../.hbm.xml"/>
<mappingresource="../../.hbm.xml"/>
<mappingresource="../../.hbm.xml"/>
</session-factory>
</hibernate-configuration>
三 struts.xml中的配置文件:
<?xmlversion="1.0"encoding="UTF-8"?>
<!DOCTYPE strutsPUBLIC "-//Apache
Software Foundation//DTD Struts Configuration 2.1//EN""http://struts.apache.org/dtds/struts-2.1.dtd">
<struts>
<!-- 配置为开发模式 -->
<constantname="struts.devMode"value="true"></constant>
<!-- 配置扩展名为action -->
<constantname="struts.action.extension"value="action"></constant>
<!-- 当struts配置文件修改时,系统是否自动重新加载该文件,默认false,开发阶段最好打开 -->
<constantname="struts.configuration.xml.reload"value="true"></constant>
<!-- 全局视图 -->
<packagename="LunTanSystem"extends="struts-default">
<global-results>
<resultname="error">/error.jsp</result>
<resultname="ajax">/ajax.jsp</result>
<resultname="noLogin">/login.jsp</result>
</global-results>
<!-- 当与action整合后,class属性写的就是Spring中bean的属性 -->
<actionname="test"class="testAction">
<resultname="success">/test.jsp</result>
</action>
</package>
</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">
<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的监听器,用于初始化ApplicationContext.xml -->
<listener>
<listener-class>org.springframework.web.context.ContextLoader</listener-class>
</listener>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:applicationContext*.xml</param-value>
</context-param>
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
</web-app>
相关文章推荐
- Spring 学习日记 (四) Spring 整合Mybaits 和 struts2 框架的配置文件
- struts2,hibernate,spring三大框架整合的注册程序(xml 配置,mysql数据库)
- SSH三大框架整合的流程是怎样走的,spring在三大框架中式怎么的一个流程,hibernate是怎么的一个流程,struts2是怎么的一个流程的,
- 框架学习之spring整合struts2、hibernate-02AOP编程
- Spring4学习笔记-Spring4整合Struts2(基于配置文件的方式)
- Struts2、Spring和Hibernate三大框架整合
- Spring ,Springmvc,mybatis三大框架整合的配置文件支持
- spring整合struts2(hibernate的配置和spring配置文件综合在一起)
- Spring3.0、Hibernate3.0、Struts2整合文件配置
- 框架学习之spring整合hibernate、struts2框架-01基础配置
- JAVA_WEB项目之Struts2、Spring和Hibernate三大框架的整合
- SSH(spring、struts2、hibernate)三大框架整合
- Spring+Struts2+Hibernate 框架整合 配置文件
- 【SSH】Struts2(2.5.14)、Spring(5.0.3)、Hibernate(5.2.13)三大框架的整合项目入门示例
- Activiti5工作流框架学习之Struts2+Hibernate+Spring整合配置
- Spring整合Struts2 wel.xml中写spring核心配置文件路径问题,顺便总结下我学习SSH整合的过程
- 手动配置三大框架整合,Spring+Struts2+Hibernate
- Struts2——SSH (Spring+Struts+Hibernate)框架搭建之配置文件序列一
- Spring整合Struts2和Hibernate+Maven(二)之SSH的配置文件
- struts2、Spring、Hibernate的整合-配置文件 2017年01月05日 17:23:10 118人阅读 评论