整合SSH2框架详细步骤
2010-05-25 20:25
344 查看
1. 引用struts2框架(具体步骤如下):
a) 导入struts2的6个相关包至lib目录下;
b) 导入struts与spring结合的插件包;
c) 配置web.xml文件,具体配置如下:
d) 创建或拷贝struts.xml文件,并进行配置;
2. 导入hibernate包;
3. 导入spring包:
a) 将applicationContext.xml放到web-inf目录下;
b) 配置applicationContext.xml文件,具体配置如下:
至此,ssh框架的整合算是完成。
注意点:由于hibernate中的asm.jar包与spring中的asm2.2.3.jar包冲突,应删除asm2.2.3.jar
a) 导入struts2的6个相关包至lib目录下;
b) 导入struts与spring结合的插件包;
c) 配置web.xml文件,具体配置如下:
//配置spring监听器 <listener> <listener-class> org.springframework.web.context.ContextLoaderListener </listener-class> </listener> <!--如果spring配置文件被命名为applicationContext.xml,并且放在WEB-INF目录下,则不需要配置<context-param>,因为ContextLoaderListener默认在WEB-INF目录下寻找名applicationContext.xml的文件 --> <!-- <context-param> <param-name>contextConfigLocation</param-name> <param-value>/WEB-INF/classes/applicationContext.xml</param-value> </context-param> --> <filter> <filter-name>struts</filter-name> <filter-class> org.apache.struts2.dispatcher.FilterDispatcher </filter-class> </filter> <filter-mapping> <filter-name>struts</filter-name> <url-pattern>/*</url-pattern> </filter-mapping>
d) 创建或拷贝struts.xml文件,并进行配置;
2. 导入hibernate包;
3. 导入spring包:
a) 将applicationContext.xml放到web-inf目录下;
b) 配置applicationContext.xml文件,具体配置如下:
<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: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/tx http://www.springframework.org/schema/tx/spring-tx-2.5.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.5.xsd"> //以上一段代码是为了声明式事务而引入的命名空间(spring事务处理的新特性:采用命名空间) <bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean"> <property name="configLocation" value="classpath:hibernate.cfg.xml"> </property> </bean> //定义hibernateTemplate模板 <bean id="hibernateTemplate" class="org.springframework.orm.hibernate3.HibernateTemplate"> <property name="sessionFactory" ref="sessionFactory"></property> </bean> //定义hibernate的事务管理器 <bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager"> <property name="sessionFactory" ref="sessionFactory"></property> </bean> //定义事务通知者Advice <tx:advice id="txAdvice"> <tx:attributes> <tx:method name="get*" read-only="true" /> <tx:method name="find*" read-only="true" /> <tx:method name="login*" read-only="true" /> <tx:method name="*" /> </tx:attributes> </tx:advice> //配置织入点与通知者的关系 <aop:config> <aop:pointcut id="defaultServiceOperation" expression="execution(* com.softfz.services.*Service.*(..))" /> <aop:advisor pointcut-ref="defaultServiceOperation" advice-ref="txAdvice" /> </aop:config> //定义userDao(该dao必须继承HibernateDaoSupport) <bean id="userDao" class="com.softfz.dao.UserDAOImpl"> <property name="hibernateTemplate" ref="hibernateTemplate"></property> </bean> <bean id="userService" class="com.softfz.services.UserServiceImpl"> <property name="userDAO" ref="userDao"></property> </bean> </beans>
至此,ssh框架的整合算是完成。
注意点:由于hibernate中的asm.jar包与spring中的asm2.2.3.jar包冲突,应删除asm2.2.3.jar
相关文章推荐
- JAVA中SSH三大框架整合的详细步骤_摘录于尚硅谷视频
- ssh2框架整合详细版(使用较新jar包)
- SSH三大框架整合配置详细步骤(1)
- Shiro整合SSM框架详细步骤
- SSH三大框架整合配置详细步骤(1)
- SHH框架整合详细步骤
- 三大框架整合步骤(详细)
- java的ssm框架整合详细步骤,复制粘贴,直接可用(初级)
- SSH三大框架整合配置详细步骤(2)
- Spring Struts Hibernate三大框架整合详细步骤
- SSH三大框架整合配置详细步骤(2)
- SSH三大框架整合配置详细步骤(3)
- ssh2框架整合详细版(使用较新jar包)
- SHH框架整合详细步骤
- SSH三大框架整合配置详细步骤(3)
- 一步步教你整合SSM框架(Spring MVC+Spring+MyBatis)详细教程
- SSM框架——详细整合教程(Spring+SpringMVC+MyBatis)
- SM框架——详细整合教程(Spring+SpringMVC+MyBatis)
- SSM框架——详细整合教程(Spring+SpringMVC+MyBatis)
- SSM框架——详细整合教程(Spring+SpringMVC+MyBatis)