如何设置基础包来扫描子包的动作? [英] How set base package to scan subpackages for actions?

查看:145
本文介绍了如何设置基础包来扫描子包的动作?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何告诉Struts 2约定插件扫描包的所有子包。我试过这个

How can I tell to Struts 2 convention plugin to scan all subpackages of a package. I tried with this

<constant name="struts.convention.action.suffix" value="Controller" /> 
<constant name="struts.convention.package.locators.basePackage" value="fi.fpf.mvc" />

<constant name="struts.convention.action.suffix" value="Controller" /> 
<constant name="struts.convention.package.locators.basePackage" value="fi.fpf.mvc.*" />

但它们不起作用。我的行为以Controller后缀结束。有人知道怎么做吗?

but they don't work. my actions end with "Controller" suffix. Someone knows how to do it?

这是我的 struts.xml

here's my struts.xml:

<struts>

    <constant name="struts.convention.exclude.parentClassLoader" value="true"/>
    <constant name="struts.convention.action.fileProtocols" value="jar,vfs,vfsfile,vfszip"/>
<constant name="struts.convention.action.suffix" value="Controller" /> 
    <constant name="struts.convention.package.locators.basePackage" value="fi.fpf.mvc" />


    <package name="fpf-default" extends="struts-default">
        <result-types>
            <result-type name="tiles" class="org.apache.struts2.views.tiles.TilesResult" />
        </result-types>
    </package>
</struts>

和一个操作:

@Action("indexController")
public class IndexController extends ActionSupport{

    private static final long serialVersionUID = -2613425890762568273L;


    @Action(value="loadIndex", results={
            @Result(name="indexView", location = "indexView", type="tiles")
    })
    public String loadIndex() {
        return "indexView";     
    }    
}


推荐答案

尝试

<constant name="struts.convention.action.packages" value="fi.fpf.mvc.*"/>

如果您使用的是约定插件,那么您应该遵循类和包名称约定。为什么不将基础包命名为struts或struts2,并使用默认的包定位器。此类的名称应与Action后缀相匹配。

if you are using convention plugin, then you should follow the class and package name conventions. Why not just name a base package to "struts" or "struts2" and with the default package locators it will be located. Also the classes should have names that matches "Action" suffix.


您可以告诉Convention插件忽略使用
属性的某些包 struts.convention.exclude .packages 。您还可以使用
属性 struts.convention.package.locators 告诉
插件使用不同的字符串来查找根软件包。最后,您可以使用属性
struts.convention.action.packages 告诉
插件搜索特定的 root 包。 。

You can tell the Convention plugin to ignore certain packages using the property struts.convention.exclude.packages. You can also tell the plugin to use different strings to locate root packages using the property struts.convention.package.locators. Finally, you can tell the plugin to search specific root packages using the property struts.convention.action.packages.

参见 docs

或者,您可以设置与此包匹配的基本包和定位器和基础下的任何包

Alternatively, you could set the base package and locator that match this package and any package under the base

<constant name="struts.convention.package.locators.basePackage" value="fi.fpf.mvc"/>
<constant name="struts.convention.package.locators" value="fi,fpf,mvc"/>

这篇关于如何设置基础包来扫描子包的动作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆