【发布时间】:2020-01-24 10:47:25
【问题描述】:
当升级我的应用程序以使用 Spring Boot 版本 2.1.8.RELEASE + struts2-convention-plugin 和 Struts2-core 版本 2.5.20 时,操作不会映射正确,我收到错误
com.opensymphony.xwork2.config.ConfigurationException: 没有 为命名空间 [/] 映射的操作和关联的操作名称 [home] 上下文路径 []。
如果我对struts.xml 中的操作进行标记,它们会完美运行。
下面是我目前的配置,为什么没有映射?
我尝试了许多不同的配置,但似乎没有任何效果,StrutsPrepareAndExecuteFilter 正在触发但未找到任何操作,就好像 Spring 没有扫描它们一样。这可能是依赖版本问题吗?
application.yaml
server:
port: 8080
servlet:
context-path: /
Struts2.xml
<struts>
<constant name="struts.devMode" value="false" />
<constant name="struts.convention.action.packages" value="com.myactions.action" />
<constant name="struts.convention.action.includeJars" value=".*?/myjar.*?jar(!/)?,.*?/myjar*?jar(!/)?" />
<constant name="struts.objectFactory" value="spring" />
<constant name="struts.objectFactory.spring.autoWire" value="name" />
<constant name="struts.multipart.maxSize" value="100000000" />
<constant name="struts.convention.default.parent.package" value="struts-default"/>
## THIS WORKS
<!-- <package name="home" extends="struts-default">-->
<!-- <action name="actionHome" class="com.myactions.action.HomeController" method="actionHome">-->
<!-- <result name="success">home.jsp</result>-->
<!-- </action>-->
<!-- </package>-->
</struts>
控制器
@Namespace("/")
public class HomeController extends BaseController {
@Action("home")
public String actionHome() throws Exception {
return SUCCESS;
}
}
主要
@SpringBootApplication
@ServletComponentScan
public class Application extends SpringBootServletInitializer {
@Override
protected SpringApplicationBuilder configure(SpringApplicationBuilder springApplicationBuilder) {
return springApplicationBuilder.sources(Application.class);
}
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}
}
Struts2 过滤器
@WebFilter("/*")
public class Struts2Filter extends StrutsPrepareAndExecuteFilter {
}
更新
【问题讨论】:
-
@Roman C:该帖子中提到的依赖项都存在(请参阅更新)
-
@cID 你有进步吗?我尝试将 Struts 核心和插件降级到 2.3.37,但无济于事:我仍然无法摆脱 struts.xml。
-
此外,如果您将应用程序打包为 WAR 并将其部署在外部 Tomcat 中,则它可以在没有 struts.xml 的情况下正常工作。
-
@Marc Tarin;不走运,我尝试了许多 struts2-convention-plugin 和 spring 版本的组合,扫描时似乎没有任何效果
标签: java spring-boot struts2 struts2-convention-plugin