How to add Struts2 to a web application without web.xml?

有些话、适合烂在心里 提交于 2019-12-02 05:33:00

问题


Can someone help me with a minimal project setup with Spring Boot and Struts2? I have already create a Spring Boot application with a H2-database. I also added a h2Configuration class, so that I'm able to access the database with localhost:8080/console.

But how can I add Struts2 to my Application without web.xml?


回答1:


Without web.xml you can only write a Struts2 filter using servlet 3.0 or higher

@WebFilter("/*")
public class Struts2Filter extends Struts2PrepareAndExecuteFilter {
}

The content could be empty, it's enough to add annotated filter without any inclusion in the web.xml file.

If you want to integrate Struts2 with Spring, then you should use a plugin.

Struts 2 provides a plugin that enables Spring to inject into the ActionSupport classes any dependent objects you've specified in the Spring configuration file. Consult Spring Plugin documentation for more information about how the plugin works.



来源:https://stackoverflow.com/questions/31415300/how-to-add-struts2-to-a-web-application-without-web-xml

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