Struts2.1&Hibernate3.2&Spring2.5集成[基于Annotation]--配置文件
2011-04-26 10:12
741 查看
web.xml:
struts.xml:
spring配置文件 spring-datasource.xml:
spring配置文件 spring-transaction.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"> <context-param> <param-name>contextConfigLocation</param-name> <param-value> classpath:org/niit/sshpopedom/config/spring-datasource.xml, classpath:org/niit/sshpopedom/config/spring-transaction.xml </param-value> </context-param> <!-- 上下文载入器监听器 --> <listener> <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class> </listener> <!-- spring解决session关闭导致延迟加载问题 --> <filter> <filter-name>OpenSessionInViewFilter</filter-name> <filter-class>org.springframework.orm.hibernate3.support.OpenSessionInViewFilter</filter-class> </filter> <filter-mapping> <filter-name>OpenSessionInViewFilter</filter-name> <url-pattern>/*</url-pattern> </filter-mapping> <!-- struts2.1 configuration --> <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> <!-- <filter-mapping> <filter-name>struts2</filter-name> <url-pattern>*.action</url-pattern> </filter-mapping> <filter-mapping> <filter-name>struts2</filter-name> <url-pattern>*.jsp</url-pattern> </filter-mapping> --> </web-app>
struts.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.i18n.encoding" value="gb2312"></constant> <constant name="struts.action.extension" value="action,html,"></constant> <constant name="struts.devMode" value="true"></constant> <package name="struts2" namespace="/" extends="struts-default"> <action name="departService" class="departService"> <result name="toDepartList">/WEB-INF/view/departList.jsp</result> </action> <action name="departWS_*" class="departService" method="{1}"> <result name="toDepartList">/WEB-INF/view/departList.jsp</result> </action> <action name="empService" class="empService"> <result name="toEmpList">/WEB-INF/view/empList.jsp</result> </action> <action name="empWS_*" class="empService" method="{1}"> <result name="toEmpList">/WEB-INF/view/empList.jsp</result> </action> </package> </struts>
spring配置文件 spring-datasource.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" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd"> <!-- 装配数据源 --> <bean class="org.apache.tomcat.dbcp.dbcp.BasicDataSource" name="dataSource"> <property name="driverClassName" value="com.mysql.jdbc.Driver"></property> <property name="url" value="jdbc:mysql://localhost:3306/crm"></property> <property name="username" value="root"></property> <property name="password" value="root"></property> </bean> <!-- 装配SessionFactory --> <bean id="sessionFactory" class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean"> <property name="dataSource" ref="dataSource"></property> <property name="hibernateProperties"> <props> <prop key="hibernate.show_sql">true</prop> <prop key="hibernate.dialect">org.hibernate.dialect.MySQL5Dialect</prop> </props> </property> <property name="annotatedClasses"> <list> <value>org.niit.sshpopedom.entities.Depart</value> <value>org.niit.sshpopedom.entities.Emp</value> <value>org.niit.sshpopedom.entities.Module</value> <value>org.niit.sshpopedom.entities.Role</value> <value>org.niit.sshpopedom.entities.Roleemp</value> <value>org.niit.sshpopedom.entities.Rolemodule</value> </list> </property> </bean> </beans>
spring配置文件 spring-transaction.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: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 http://www.springframework.org/schema/beans/spring-beans-2.5.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.5.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.5.xsd"> <!-- 开启注解和扫描指定包下的注解类 --> <context:component-scan base-package="org.niit.sshpopedom.dao,org.niit.sshpopedom.biz.impl,org.niit.sshpopedom.web.action" /> <!-- 装配Hibernate模板 --> <bean class="org.springframework.orm.hibernate3.HibernateTemplate" name="hibernateTemplate"> <property name="sessionFactory" ref="sessionFactory"></property> </bean> <!-- 装配Hibernate事务管理器 --> <bean class="org.springframework.orm.hibernate3.HibernateTransactionManager" name="transactionManager"> <!--事务管理器需要知道SessionFactory,以便获得Session操纵事务 --> <property name="sessionFactory" ref="sessionFactory"></property> </bean> <tx:advice id="txAdvice" transaction-manager="transactionManager"> <!-- 配置事务传递属性 --> <tx:attributes> <tx:method name="get*" propagation="REQUIRED"/> <tx:method name="add*" propagation="REQUIRED"/> <tx:method name="trade" propagation="REQUIRES_NEW"/> </tx:attributes> </tx:advice> <aop:config> <!--切入点--> <aop:pointcut id="myPointCut" expression="execution(* org.niit.sshpopedom.biz.impl.*.*(..))"/> <aop:advisor advice-ref="txAdvice" pointcut-ref="myPointCut"/> </aop:config> </beans>
相关文章推荐
- Struts2.1&Hibernate3.2&Spring2.5集成[基于Annotation]--代码
- Struts2.1&Hibernate3.2&Spring2.5集成[基于Annotation]--Spring2.5单元测试
- Struts2.1&Hibernate3.2&Spring2.5集成[基于Annotation]--运行效果
- Struts2.1&Hibernate3.2&Spring2.5集成[基于Annotation]--案例结构
- Struts2+hibernate+spring 配置文件中scope="prototype"的作用
- Struts+spring+hibernate集成的配置文件
- spring2.5 及 hibernate annotation 配置文件笔记
- spring(2.5或者3.2)集成hibernate3.5的配置文件
- struts1.2 + spring2.5 + hibernate3.2框架搭建二之配置文件
- SSH(struts 1.x+spring 2.5+hibernate 3.2)开发文件配置
- spring2.5 及 hibernate annotation 配置文件笔记
- struts1.2 + hibernate3.2 + Spring2.5集成配置
- 很重要!!!ssh集成的时候struts2 和 spring3集成一定要在struts.xml文件里配置!<constant name="struts.objectFactory" value="sp
- struts+hibernate+spring整合的文件配置详解
- (绝对有效)sqlserver2000链接proxool连接池,终于配置出spring整合struts,hibernate annotation(pool数据池,sqlserver2000数据库)
- 基于Annotation的Struts2.0+Hibernate3.3+Spring2.5整合开发 (2)
- spring与hibernate集成--spring配置文件applicationContext.xml的配置:
- Spring3与Hibernate4整合,Spring中配置Hibernate基于XML和annotation的sessionFactory方式。
- Spring beans——SSH (Spring+Struts+Hibernate)框架搭建之配置文件序列三
- Spring与Hibernate与Struts整合(一)配置文件