Tomcat - 不会加载我的 META-INF\services\javax.servlet.ServletContainerInitializer 文件?
我有一个 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
好吧,我认为您需要将初始值设定项类(及其与服务相关的 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 setunpackWAR=false
in your Tomcat'sserver.xml
.HTH.
为了让 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 ..
首先要检查的是您实际上使用的是 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.
我想引用
Mark Thomas <[email protected] 的一些很好的解释Tomcat的用户邮件列表上给出了>
: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:http://mail-archives.apache.org/mod_mbox/tomcat-users/201808.mbox/