论坛首页 入门技术论坛

配置struts2.0.6+spring2.0.3+hibernane3备忘

浏览 36895 次
该帖已经被评为新手帖
作者 正文
   发表时间:2007-04-03  
多谢复贴,这个做法我也试过,不过我觉得这样我就需要对每个action作2次的配置(struts、spring各一次),我还是保留我的配置方法,而且对于struts2来说还会直观一点,即使不用spring,struts2的配置文件也不需要作什么修改。
0 请登录后投票
   发表时间:2007-04-03  
xugq035 写道
多谢复贴,这个做法我也试过,不过我觉得这样我就需要对每个action作2次的配置(struts、spring各一次),我还是保留我的配置方法,而且对于struts2来说还会直观一点,即使不用spring,struts2的配置文件也不需要作什么修改。

如果将struts2的action交给spring的ioc容器管理,那这个action实例能够获得springioc容器的一切优点,包括使用spring的aop系统,而且我记得在webwork2里,把action交给spring管理性能上更好一点,但struts2.0就不清楚了,毕竟人家用的是xwork2.0



Tiwen 写道

Spring配置文件添加
       <bean id="LoginAction" class="com.baseframe.action.LoginAction"/>   
       <bean id="LogoutAction" class="com.baseframe.action.LogoutAction"/> 


难道spring2.0里默认的bean实例不是单例的吗
0 请登录后投票
   发表时间:2007-04-14  
引用
xugq035 写道
多谢复贴,这个做法我也试过,不过我觉得这样我就需要对每个action作2次的配置(struts、spring各一次),我还是保留我的配置方法,而且对于struts2来说还会直观一点,即使不用spring,struts2的配置文件也不需要作什么修改。

如果将struts2的action交给spring的ioc容器管理,那这个action实例能够获得springioc容器的一切优点,包括使用spring的aop系统,而且我记得在webwork2里,把action交给spring管理性能上更好一点,但struts2.0就不清楚了,毕竟人家用的是xwork2.0

个人认为让spring管理action更好一些 也可以更灵活的处理客户端请求
0 请登录后投票
   发表时间:2007-04-15  
roundlight 写道
非常感谢 xugq035 的介绍资料,我也想搞个 struts + spring + hibernate 相结合的东西出来, 不知道 这位朋友,能不能给我做一下指导啊,再这里 先谢过了啊

  如果,有机会的话,像你学习啊


其实你可以参考appfuse啊,mvc层可以用struts,webwork,tapestry。
0 请登录后投票
   发表时间:2007-04-18  
Tiwen 写道
这样搭配似乎美中不足。既然你选择了SPRING作为IOC容器,那么你的ACTION也应该被SPRING的IOC管理


为什么要spring控制action呢,你在action中写逻辑代码 ?
0 请登录后投票
   发表时间:2007-04-18  
 <bean class="org.springframework.aop.framework.autoproxy.BeanNameAutoProxyCreator">   
        <property name="beanNames">   
            <value>*Service<value>   
        property>   
        <property name="interceptorNames">   
            <list>   
                <value>transactionInterceptor<value>   
                <!--    </span> </li> <li class="alt"><span><span class="comments">                                此处增加新的Interceptor   </span> </span></li> <li class=""><span><span class="comments">                        -->   
            list>   
        <property>   
    <bean>   


这里为什么是*Service
而不是*DAO呢???
0 请登录后投票
   发表时间:2007-04-18  
  用SPRING管理ACTION的话有一点可能要注意,就是SCOPE要设成prototype,如果也使用了struts2的UI,还是用的spring默认的scope,那么在action中提供的对象在同一浏览器中做新境、编辑时会混起来,可能出现编辑也是新增的情况,就因为默认的singleton不会再重新生成一个新的action。
  这个当时同事就遇到这个问题,我帮着调了一下,没具体使用了。
0 请登录后投票
   发表时间:2007-04-19  
原来把ACTION交给SPRING 管理 STRUTS 1.2 经常出莫名其妙的问题 WEBWORK 应该没问题
0 请登录后投票
   发表时间:2007-04-19  
action交给spring管理后,struts2的validation功能使用出现异常,点击提交表单按钮后还是返回到原先页面!

struts.xml文件中增加:
 
<constant name="objectFactory" value="spring"></constant>
[b]<action name="Login" class="login">[/b]
    <result name="input">/example/Login.jsp</result>
    <result type="redirect-action">Menu</result>
</action>


applicationContext.xml文件如下:


<beans>  
    <bean id="helloWorld" class="example.HelloWorld"></bean> 
   [b] <bean id="logon" class="example.Login"></bean>[/b]
    <bean id="index" class="example.ExampleSupport"></bean>
</beans>


Login.jsp如下:
<%@ page contentType="text/html; charset=UTF-8" %>
<%@ taglib prefix="s" uri="/struts-tags" %>
<html>
<head>
    <title>Sign On</title>
</head>

<body>
<s:form action="Login">
    <s:textfield key="username"/>
    <s:password key="password" />
    <s:submit/>
</s:form>
</body>
</html>



Login-validation.xml如下:
<!DOCTYPE validators PUBLIC
        "-//OpenSymphony Group//XWork Validator 1.0.2//EN"
        "http://www.opensymphony.com/xwork/xwork-validator-1.0.2.dtd">

<validators>
    <field name="username">
        <field-validator type="requiredstring">
            <message key="requiredstring"/>
        </field-validator>
    </field>
    <field name="password">
        <field-validator type="requiredstring">
            <message key="requiredstring"/>
        </field-validator>
    </field>
</validators>


Login.java代码就不写了,因为程序根本就没进这个Action。每次提交时进行验证,然后返回到原拉的Login界面!如果不把action交给spring管理的话就能正确提交,为什么?
0 请登录后投票
   发表时间:2007-04-21  
引用
spring的bean应该在action中调用,在LoginAction中应该包含类似如下的代码:

private EmployeeService employeeService;
public void setEmployeeService(EmployeeService employeeService) {
      this.employeeService = employeeService;
}


这个EmployeeService才是spring的bean
只要你再struts.properties文件中设定了struts.objectFactory = spring,加入struts2-spring-plugin-2.0.6.jar就可以了


是不是加了struts2-spring-plugin-2.0.6.jar之后action会自动被spring托管了?
还是其他方式,楼主能不能给解释一下?
0 请登录后投票
论坛首页 入门技术版

跳转论坛:
Global site tag (gtag.js) - Google Analytics