【问题标题】:How to add Struts2 to a web application without web.xml?如何在没有 web.xml 的情况下将 Struts2 添加到 Web 应用程序?
【发布时间】:2015-07-14 19:09:55
【问题描述】:

有人可以帮助我使用 Spring Boot 和 Struts2 进行最小的项目设置吗? 我已经创建了一个带有 H2 数据库的 Spring Boot 应用程序。我还添加了一个h2Configuration 类,这样我就可以使用localhost:8080/console 访问数据库。

但是如何在没有web.xml 的情况下将 Struts2 添加到我的应用程序中?

【问题讨论】:

    标签: spring configuration struts2 annotations servlet-3.0


    【解决方案1】:

    如果没有web.xml,您只能使用 servlet 3.0 或更高版本编写 Struts2 过滤器

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

    内容可以是空的,在web.xml文件中添加注释过滤器就足够了。

    如果你想将 Struts2 与 Spring 集成,那么你应该使用plugin

    Struts 2 提供了一个插件,使 Spring 能够将您在 Spring 配置文件中指定的任何依赖对象注入到 ActionSupport 类中。有关插件如何工作的更多信息,请参阅 Spring 插件文档。

    【讨论】:

    • sprint boot 不支持 struts 2 集成吗?
    • @MSach Spring Boot 应该使用插件依赖项。
    • 自版本 2.5.20 Struts2PrepareAndExecuteFilter -> StrutsPrepareAndExecuteFilter
    • 感谢 RomanC 我的评论是基于 'Struts2PrepareAndExecuteFilter' 不存在于 struts2-core 版本 2.5.20 javadoc.io/doc/org.apache.struts/struts2-core/2.5.20
    • @Nigel 你应该知道它的发布日期和当前的 Struts 版本。
    猜你喜欢
    • 1970-01-01
    • 2020-03-27
    • 2011-03-21
    • 2016-12-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多