使用spring管理struts操作(由convention插件配置)

时间:2014-03-26 13:09:29

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

我们正在使用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(这正是动作名称的驼峰转换)

有可能吗?!

1 个答案:

答案 0 :(得分:0)

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