【问题标题】:Manage struts actions (which configured by convention plugin) with spring使用 spring 管理 struts 动作(由约定插件配置)
【发布时间】:2014-03-26 13:09:28
【问题描述】:

我们正在使用 Struts 2 + Spring 4,我们想设置 spring 来管理我们的 struts 2 动作。

spring bean 是由注解定义的。

struts 动作位于约定插件中,因此struts.xml 文件中没有任何动作。

动作如下:

//It is located in action folder so it will be located by convention plugin
package foo.bar.actions.usermanager

@Named //This will be used by Spring to located and manage this Bean
public class EditUser(){

    @Action(className="editUser") // Should I defined class name here ?!
    public String execute() {

    }
}

上面的代码有效。但是我想看看是否有更好的方法,所以我们可以省略 className (这正是动作名称的骆驼转换)

有可能吗?!

【问题讨论】:

    标签: java spring struts2 spring-annotations struts2-convention-plugin


    【解决方案1】:

    默认情况下,className 属性包含约定插件在从注释创建操作配置时找到该操作的类的名称。如果您构建一个普通的 Struts 操作配置,则不需要它。但是,如果您想将构建和管理操作委托给 Spring,则与 spring 插件结合使用,您必须提供此类属性。它与基于 xml 的操作配置中的 class 相同,并且这些名称按约定与 spring 插件一起使用。请参阅Initializing Action from SpringAlternative - Have Spring Manage Creation Of ActionSupport Class 相关文档。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2011-07-23
      • 2021-05-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-03-07
      • 1970-01-01
      相关资源
      最近更新 更多