Tomcat - 不会加载我的 META-INF\services\javax.servlet.ServletContainerInitializer 文件?

发布于 2024-12-08 18:12:30 字数 725 浏览 0 评论 0原文

我有一个 Web 项目,其中有一个 \META-INF\services\javax.servlet.ServletContainerInitializer 文件,其内容指向实现 ServletContainerInitializer 接口的类的完全限定名称。我基本上遵循这里给出的示例: http://nullhaus.com/2011/03/using -servlets-3-0-servletcontainerinitializer/

我将调试行放入实现 ServletContainerInitializer 接口的类中,但它从未出现在那里。甚至不是默认的构造函数...

我的应用程序文件夹结构如下:

\MyApp
      \META-INF\services\javax.servlet.ServletContainerInitializer
      \WEB-INF\classes\
                 ... [list of classes and packages go here]

我需要检查什么?

注 1:我的 Tomcat 从包含我的应用程序的展开的外部文件夹发布

注 2:我从 Eclipse 启动了我的 Tomcat - 如果这有什么不同的话!

I have a web project that has a \META-INF\services\javax.servlet.ServletContainerInitializer file with its content pointing to the fully qualified name of a class that implements the ServletContainerInitializer interface. I basically followed the example given here: http://nullhaus.com/2011/03/using-servlets-3-0-servletcontainerinitializer/

I put debug lines in my class that implements the ServletContainerInitializer interface and it never makes it there. Not even the default constructor...

My application folder structure is as follows:

\MyApp
      \META-INF\services\javax.servlet.ServletContainerInitializer
      \WEB-INF\classes\
                 ... [list of classes and packages go here]

Any ideas what I need to check for??

Note 1: My Tomcat publishes from an exploded external folder that contains my application

Note 2: I started my Tomcat from Eclipse - if that makes a difference!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

浮华 2024-12-15 18:12:30

好吧,我认为您需要将初始值设定项类(及其与服务相关的 META-INF 目录)包装到一个单独的 *.jar 中,并将其放入 WEB-INF/lib 中。

这是一个 JAR 服务,所以我猜它可能与在 *.war 文件中发现服务的问题有关。此外,如果您将 META-INF 目录放入 WEB-INF/classes 并在您的文件中设置 unpackWAR=false,它甚至没有帮助。 Tomcat 的 server.xml

HTH。

Well, I think that you'll need to wrap your initializer class (and it's services-related META-INF directory) into a separate *.jar and put it in the WEB-INF/lib.

This is a JAR service, so I guess it could have something to do with problems with discovering services in a *.war file. Moreover, it doesn't even help if you put your META-INF directory inside WEB-INF/classes and set unpackWAR=false in your Tomcat's server.xml.

HTH.

鸠魁 2024-12-15 18:12:30

为了让 tomcat 加载 META-INF 目录,它必须位于classes 文件夹中。如果您使用的是maven项目,只需将META-INF目录放入src/main/resources目录中..在mvn包上,相同的内容将被复制到classes目录中..不需要单独的jar ..如果你喜欢 jar ,你可以使用
HandlesTypes 注释..

For tomcat to load the META-INF directory , it has to be in classes folder . If you are using maven project , just put the META-INF directory inside src/main/resources directory .. on mvn package the same will be copied to classes directory .. No need of separerate jar .. if jar is prefered you can use
HandlesTypes annotation ..

勿忘初心 2024-12-15 18:12:30

首先要检查的是您实际上使用的是 Servlet 3.0 而不是早期版本。对于 Tomcat,这意味着您必须使用 Tomcat 7.0.22

其次,确保 \META-INF\services\javax.servlet.ServletContainerInitializer 文件确实存在于展开的 war 文件中。

第三,如有疑问,请直接配置并启动 Tomcat(而不是从 Eclipse) - 我发现开发人员在使用 Eclipse 插件配置 Tomcat 时遇到了无穷无尽的问题。

The first thing to check is that you are actually using Servlet 3.0 and not an earlier version. For Tomcat, this means that you must be using Tomcat 7.0.22

Second, make sure that the \META-INF\services\javax.servlet.ServletContainerInitializer file actually exists in the exploded war file.

Third, when in doubt, configure and start Tomcat directly (not from Eclipse) - I've seen developers have endless problems with configuration of Tomcat using the Eclipse plugin.

荆棘i 2024-12-15 18:12:30

我想引用 Mark Thomas <[email protected] 的一些很好的解释Tomcat的用户邮件列表上给出了>

服务文件由类加载器从 META-INF/services 加载
目录。

*.jar!/META-INF/services

*.war/WEB-INF/classes/META-INF/services
对类加载器可见

*.war!/META-INF/services
不是。

servlet 专家组最近在以下背景下讨论了 WAR 与 JAR
Java 9 和多版本 JAR。结论是(我正在解释)
WAR 不是 JAR 的特殊形式,虽然它们共享一个
通用格式 JAR 可用的功能不会自动
除非 Servlet 规范(Java EE 规范)明确指出,否则可用于 WAR
另有说明。

如果容器愿意,可以自由添加容器特定的扩展
但它们带有常见的(缺乏)互操作性警告。

http://mail-archives.apache.org/mod_mbox/tomcat -users/201808.mbox/

I would like to quote some good explanation from Mark Thomas <[email protected]> given on the user mailing list of Tomcat:

Service files are loaded by class loaders from the META-INF/services
directory.

*.jar!/META-INF/services
and
*.war/WEB-INF/classes/META-INF/services
are visible to class loaders

*.war!/META-INF/services
is not.

The servlet expert group recently discussed WAR vs JAR in the context of
Java 9 and mutli-version JARs. The conclusion was (I'm paraphrasing)
that WARs are not a specialised form of JAR and while they share a
common format a feature that is available to a JAR is NOT automatically
available to a WAR unless the Servlet spec (of Java EE spec) explicitly
states otherwise.

Containers are free to add container specific extensions if they wish
but they come with the usual (lack of) interoperability warnings.

http://mail-archives.apache.org/mod_mbox/tomcat-users/201808.mbox/

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文