`

struts2.0.14+spring2.5+hibernate3.2整合方法二

 
阅读更多
struts2.0.14+spring2.5+hibernate3.2整合方法二
spring写bean,并在配置文件写注入;action的class写bean的名称

applicationContext-beans.xml
<?xml version="1.0" encoding="GBK"?>
<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/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">
	<bean id="userService" class="demo.service.UserServiceImpl">
		<property name="userDao" ref="userDao"></property>
	</bean>
	<bean id="userDao" class="demo.dao.UserDaoImpl"></bean>

	<bean id="loginAction" class="demo.action.LoginAction" scope="prototype">
		<property name="userService" ref="userService"></property>
	</bean>
</beans>

struts.xml
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE struts PUBLIC
    "-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
    "http://struts.apache.org/dtds/struts-2.0.dtd">

<struts>
    <!-- 已经导入了struts-spring-plugin包所以在struts.xml里面不需要再配置这个常量 
     <constant name="struts.objectFactory" value="org.apache.struts2.spring.StrutsSpringObjectFactory" />-->
   <package name="struts2" extends="struts-default">
        <action name="Login" class="loginAction"  method="Login">
            <result name="success"  type="redirect">listUser.action</result>
            <result name="input">/login.jsp</result>
        </action>
         <action name="addUser" class="loginAction" method="addUser">
            <result name="success">/addUser.jsp</result>
        </action>
        <action name="saveUser" class="loginAction" method="saveUser">
            <result name="success"  type="redirect">listUser.action</result>
        </action>
        <action name="listUser" class="loginAction" method="listUser">
            <result name="success" >/listUser.jsp</result>
        </action>
         <action name="securityCodeImage" class="loginAction" method="securityCodeImage">
            <result name="success" >/listUser.jsp</result>
        </action>
   </package>
    
</struts>

其实文件看struts2.0.14+spring2.5+hibernate3.2整合方法一
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics