如何将 Struts2 添加到没有 web.xml 的 Web 应用程序? [英] How to add Struts2 to a web application without web.xml?

查看:47
本文介绍了如何将 Struts2 添加到没有 web.xml 的 Web 应用程序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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.

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

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

推荐答案

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

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

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

内容可能为空,添加带注释的过滤器就足够了,web.xml 文件中不包含任何内容.

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

如果您想将 Struts2 与 Spring 集成,那么您应该使用 插件.

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

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

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.

这篇关于如何将 Struts2 添加到没有 web.xml 的 Web 应用程序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆