How set base package to scan subpackages for actions?

廉价感情. 提交于 2019-12-07 16:00:46

问题


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" />

and this

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

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

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>

and one action:

@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";     
    }    
}

回答1:


Try

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

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.

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.

See the 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"/>


来源:https://stackoverflow.com/questions/16959251/how-set-base-package-to-scan-subpackages-for-actions

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!