java-如何设置基本程序包以扫描子程序包中的操作?

如何告诉Struts 2常规插件扫描包的所有子包.我尝试了这个

<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”后缀结尾.有人知道该怎么做吗?

这是我的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”后缀匹配.

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.

或者,您可以设置基本包装和定位器,使其与该包装以及该包装下的任何包装相匹配

<constant name="struts.convention.package.locators.basePackage" value="fi.fpf.mvc"/>
<constant name="struts.convention.package.locators" value="fi,fpf,mvc"/>
上一篇:java-如何使用Struts 2标签迭代Set元素


下一篇:java-如果我在项目中包含多个struts配置文件,流程顺序是什么