Spring+Struts2+Hibernate 框架整合 配置文件
来源:互联网 发布:淘宝代运营怎么找客户 编辑:程序博客网 时间:2024/05/29 04:44
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> <welcome-file-list> <welcome-file>index.jsp</welcome-file> </welcome-file-list> <!--1) 读取spring配置文件; 如果放在WEB-INF/目录下无需配置--> <context-param> <param-name>contextConfigLocation</param-name> <param-value>classpath:applicationContext.xml</param-value> </context-param> <!-- 2)监听spring容器启动 --> <listener> <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class> </listener> <!-- 3)OpenSessionInView --> <filter> <filter-name>OpenSessionInViewFilter</filter-name> <filter-class>org.springframework.orm.hibernate4.support.OpenSessionInViewFilter</filter-class> </filter> <filter-mapping> <filter-name>OpenSessionInViewFilter</filter-name> <url-pattern>*.do,*.action</url-pattern> </filter-mapping> <!-- 4) 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> <!-- struts2必须写入 请求,转发; --> <dispatcher>REQUEST</dispatcher> <dispatcher>FORWARD</dispatcher> </filter-mapping></web-app>
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:p="http://www.springframework.org/schema/p"xmlns:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx"xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.1.xsdhttp://www.springframework.org/schema/aophttp://www.springframework.org/schema/aop/spring-aop-3.1.xsdhttp://www.springframework.org/schema/txhttp://www.springframework.org/schema/tx/spring-tx-3.1.xsd"><bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource"><property name="driverClassName" value="oracle.jdbc.driver.OracleDriver"></property><property name="url" value="jdbc:oracle:thin:@localhost:1521:ORCL"></property><property name="username" value="scott"></property><property name="password" value="tiger"></property></bean><bean id="sessionFactory"class="org.springframework.orm.hibernate4.LocalSessionFactoryBean"><property name="dataSource"><ref bean="dataSource" /></property><property name="hibernateProperties"><props><prop key="hibernate.dialect">org.hibernate.dialect.Oracle9Dialect</prop><!-- -必须手动配置 --><prop key="hibernate.show_sql">true</prop><prop key="hibernate.format_sql">true</prop><prop key="hibernate.hbm2ddl.auto">update</prop></props></property><property name="mappingResources"><list><value>com/hlx/entity/Mydept.hbm.xml</value></list></property></bean><!-- 程序员做的事 --><!-- hibernateTemplate must di sessionFactory --><bean id="hibernateTemplate" class="org.springframework.orm.hibernate4.HibernateTemplate"><property name="sessionFactory" ref="sessionFactory" /></bean><!-- basedao abstract="true"配置抽象类 must di hibernateTemplate --><bean id="basedao" class="com.hlx.util.BaseDaoImpl" abstract="true"><property name="hibernateTemplate" ref="hibernateTemplate" /></bean><!-- dao 必须指定parent="basedao"父亲 --><bean id="mydeptDao" class="com.hlx.dao.impl.MydeptDaoImpl"parent="basedao"></bean><!-- biz 必须注入mydeptDao --><bean id="mydeptBiz" class="com.hlx.biz.impl.MydeptBizImpl"><property name="dao" ref="mydeptDao" /></bean><!-- action scope="prototype"必须是多列模式; 必须注入mydeptBiz --><bean id="mydeptAction" class="com.hlx.action.MydeptAction" scope="prototype"><property name="biz" ref="mydeptBiz" /></bean><!-- spring容器做的事 --><!-- 事务管理对象 必须注入sessionFactory --><bean id="transactionManager"class="org.springframework.orm.hibernate4.HibernateTransactionManager"><property name="sessionFactory" ref="sessionFactory" /></bean><!-- aop通知 --><aop:config><!-- 切入点 --><aop:pointcut expression="execution(* com.hlx.biz.*.*(..))"id="mycut" /><!-- advice --><aop:advisor advice-ref="myAdvice" pointcut-ref="mycut"/></aop:config><!-- 事务 --><tx:advice id="myAdvice" transaction-manager="transactionManager"> <tx:attributes> <tx:method name="all" propagation="SUPPORTS" read-only="true"/> <tx:method name="*find*" propagation="SUPPORTS" read-only="true"/> <tx:method name="*" /> </tx:attributes></tx:advice></beans>
log4j.properties:
# rootLogger\u662F\u6240\u6709\u65E5\u5FD7\u7684\u6839\u65E5\u5FD7,\u4FEE\u6539\u8BE5\u65E5\u5FD7\u5C5E\u6027\u5C06\u5BF9\u6240\u6709\u65E5\u5FD7\u8D77\u4F5C\u7528
# \u4E0B\u9762\u7684\u5C5E\u6027\u914D\u7F6E\u4E2D,\u6240\u6709\u65E5\u5FD7\u7684\u8F93\u51FA\u7EA7\u522B\u662Finfo,\u8F93\u51FA\u6E90\u662Fconsole
log4j.rootLogger=info,console
# \u5B9A\u4E49\u8F93\u51FA\u6E90\u7684\u8F93\u5165\u4F4D\u7F6E\u662F\u63A7\u5236\u53F0
log4j.appender.console=org.apache.log4j.ConsoleAppender
# \u5B9A\u4E49\u8F93\u51FA\u65E5\u5FD7\u7684\u5E03\u5C40\u91C7\u7528\u7684\u7C7B
log4j.appender.console.layout=org.apache.log4j.PatternLayout
# \u5B9A\u4E49\u65E5\u5FD7\u8F93\u51FA\u5E03\u5C40
log4j.appender.console.layout.ConversionPattern=%d %p [%c] - %m%n
- Spring+Struts2+Hibernate 框架整合 配置文件
- struts2+hibernate+spring框架整合
- Struts2+Hibernate+spring框架整合
- hibernate+struts2+spring框架整合
- spring-struts2-hibernate整合通用配置文件
- struts2+spring+hibernate整合的配置文件
- struts2、Spring、Hibernate的整合-配置文件
- 学习三大框架Struts2 、 Hibernate 、 Spring时,涉及到三大框架的配置文件以及整合。
- SSH框架整合(Spring整合Struts2,和Spring整合Hibernate)
- 三大框架SSH(struts2+spring+hibernate)整合时相关配置文件的模板
- 三大框架SSH(struts2+spring+hibernate)整合时相关配置文件的模板
- 三大框架SSH(struts2+spring+hibernate)整合时相关配置文件的模板
- spring和mybatis ,hibernate, struts2框架整合
- Spring+Struts2+hibernate框架整合详解
- struts2,spring,hibernate三大框架整合
- 三大框架整合(Struts2 Spring Hibernate)
- Struts2+Spring+Hibernate+Maven框架整合
- Spring整合第三方框架(Hibernate、Struts2)
- jvm的原理和优化
- java异常 运行时 非运行时异常
- 解题:解问阶段:运用——结合分析与逻辑进行推理:模块
- 1.6 10大整数加法
- 网易云课堂C++开发工程师案例-网吧收银系统(MFC+ADO)
- Spring+Struts2+Hibernate 框架整合 配置文件
- MVC5 + EF6 + Bootstrap3学习网站收集
- 算法基础篇(5)------最短路
- pat-top 1016. Uniqueness of MST (35)
- tomcat maven 环境搭建
- Matlab符号求解
- 421. Maximum XOR of Two Numbers in an Array
- 1026: [SCOI2009]windy数
- Meclispse创建Spring项目并配置框架环境