Struts2注释替代struts.xml的标记结果类型

时间:2017-06-17 10:24:17

标签: java jsp struts2 annotations tiles

我尝试使用常见的页眉,页脚和正文创建新的struts2应用程序(基于注释的配置),其中单击菜单上的正文更改。所以我提到了这个链接,上面写着If you are using annotations alone and no struts.xml, then you have to create a minimal one for this because there's no annotation available to define a custom result type

我还需要为结果类型标记创建struts.xml吗? 我正在尝试用户瓷砖3.并收到此错误

Jun 17, 2017 3:26:20 PM org.apache.catalina.core.StandardContext filterStart
SEVERE: Exception starting filter struts2
Unable to load configuration. - [unknown location]
    at org.apache.struts2.dispatcher.Dispatcher.init(Dispatcher.java:499)
    at org.apache.struts2.dispatcher.InitOperations.initDispatcher(InitOperations.java:75)
    at org.apache.struts2.dispatcher.filter.StrutsPrepareAndExecuteFilter.init(StrutsPrepareAndExecuteFilter.java:63)
    at org.apache.catalina.core.ApplicationFilterConfig.initFilter(ApplicationFilterConfig.java:279)
    at org.apache.catalina.core.ApplicationFilterConfig.getFilter(ApplicationFilterConfig.java:260)
    at org.apache.catalina.core.ApplicationFilterConfig.<init>(ApplicationFilterConfig.java:105)
    at org.apache.catalina.core.StandardContext.filterStart(StandardContext.java:4590)
    at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5233)
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
    at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1419)
    at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1409)
    at java.util.concurrent.FutureTask.run(Unknown Source)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
    at java.lang.Thread.run(Unknown Source)
Caused by: Unable to load configuration. - [unknown location]
    at com.opensymphony.xwork2.config.ConfigurationManager.getConfiguration(ConfigurationManager.java:70)
    at org.apache.struts2.dispatcher.Dispatcher.getContainer(Dispatcher.java:906)
    at org.apache.struts2.dispatcher.Dispatcher.init_PreloadConfiguration(Dispatcher.java:445)
    at org.apache.struts2.dispatcher.Dispatcher.init(Dispatcher.java:486)
    ... 14 more
Caused by: The Result type [tiles] which is defined in the Result annotation on the class [class org.iibf.crf.action.LoginAction] or determined by the file extension or is the default result type for the PackageConfig of the action, could not be found as a result-type defined for the Struts/XWork package [org.iibf.crf.action#convention-default#/] - [unknown location]
    at org.apache.struts2.convention.DefaultResultMapBuilder.createResultConfig(DefaultResultMapBuilder.java:443)
    at org.apache.struts2.convention.DefaultResultMapBuilder.createFromAnnotations(DefaultResultMapBuilder.java:414)
    at org.apache.struts2.convention.DefaultResultMapBuilder.createResultsFromAnnotations(DefaultResultMapBuilder.java:222)
    at org.apache.struts2.convention.DefaultResultMapBuilder.build(DefaultResultMapBuilder.java:192)
    at org.apache.struts2.convention.PackageBasedActionConfigBuilder.createActionConfig(PackageBasedActionConfigBuilder.java:948)
    at org.apache.struts2.convention.PackageBasedActionConfigBuilder.buildConfiguration(PackageBasedActionConfigBuilder.java:700)
    at org.apache.struts2.convention.PackageBasedActionConfigBuilder.buildActionConfigs(PackageBasedActionConfigBuilder.java:336)
    at org.apache.struts2.convention.ClasspathPackageProvider.loadPackages(ClasspathPackageProvider.java:53)
    at com.

如果您需要我提供更多详细信息,请告诉我。谢谢你的帮助。

1 个答案:

答案 0 :(得分:1)

默认的父包应该不是 convention-default,而是tiles-default。如果将tile插件添加到类路径并将@ParentPackage("tiles-default")注释设置为action类,则可以区分此项。您可以将此注释放在保留策略应用的类或包中。

另请注意,您可以全局定义父包,而不仅仅是上一个示例中的自定义操作类。即,如果您的配置中包default扩展了tiles-default并且您想要全局配置

<constant name="struts.convention.default.parent.package" value="default"/>