Java 信息:在类路径上未检测到 Spring WebApplicationInitializer 类型

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/22938689/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-13 19:27:47  来源:igfitidea点击:

INFO: No Spring WebApplicationInitializer types detected on classpath

javaspringspring-mvctomcat7

提问by Aron Elias Herrera Ponte

I have a spring project that runs fine on my tomcat7 server when I deploy from eclipse: Run As >> Run on server. In the eclipse tab "Servers" I see:

当我从 Eclipse 部署时,我有一个在我的 tomcat7 服务器上运行良好的 spring 项目:运行方式>>在服务器上运行。在 Eclipse 选项卡“服务器”中,我看到:

Servers
 Tomcat v7.0 Server at localhost [Started, Synchronized]
   my_project [Synchronized]
     spring-web-3.2.4-RELEASE.jar

My project:

我的项目:

  • does not use web.xml, I use javaconf @ annotations.
  • does not use maven, I use a User Library
  • 不使用web.xml,我使用javaconf@annotations。
  • 不使用 maven,我使用用户库

I see that the project is in:

我看到该项目在:

/srv/applications/workspace/.metadata/.plugins/org.eclipse.wst.server.core/tmp0

And, I also see the folders: conf,logs,temp,webapps,work,wtpwebapps

而且,我还看到了文件夹:conf,logs,temp,webapps,work,wtpwebapps

I confirm that all runs fine on my tomcat7 server when I deploy from eclipse!

当我从 Eclipse 部署时,我确认一切都在我的 tomcat7 服务器上运行良好!

In eclipse console I get:

在 Eclipse 控制台中,我得到:

Apr 08, 2014 3:26:59 PM org.apache.tomcat.util.digester.SetPropertiesRule begin
WARNING: [SetPropertiesRule]{Server/Service/Engine/Host/Context} Setting property 'source' to 'org.eclipse.jst.j2ee.server:my_project' did not find a matching property.
Apr 08, 2014 3:27:00 PM org.apache.coyote.AbstractProtocol init
INFO: Initializing ProtocolHandler ["http-bio-8888"]
Apr 08, 2014 3:27:00 PM org.apache.coyote.AbstractProtocol init
INFO: Initializing ProtocolHandler ["http-bio-8843"]
Apr 08, 2014 3:27:01 PM org.apache.catalina.startup.Catalina load
INFO: Initialization processed in 3215 ms
Apr 08, 2014 3:27:01 PM org.apache.catalina.core.StandardService startInternal
INFO: Starting service Catalina
Apr 08, 2014 3:27:01 PM org.apache.catalina.core.StandardEngine startInternal
INFO: Starting Servlet Engine: Apache Tomcat/7.0.26
Apr 08, 2014 3:27:11 PM org.apache.catalina.core.ApplicationContext log
INFO: Spring WebApplicationInitializers detected on classpath: [my_project.web.context.WebApplicationInitializer@3599e94c]
Apr 08, 2014 3:27:12 PM org.apache.catalina.core.ApplicationContext log
INFO: Initializing Spring root WebApplicationContext
Apr 08, 2014 3:27:24 PM org.apache.catalina.core.ApplicationContext log
INFO: Initializing Spring FrameworkServlet 'dispatcher'
Apr 08, 2014 3:27:24 PM org.apache.coyote.AbstractProtocol start
INFO: Starting ProtocolHandler ["http-bio-8888"]
Apr 08, 2014 3:27:24 PM org.apache.coyote.AbstractProtocol start
INFO: Starting ProtocolHandler ["http-bio-8843"]
Apr 08, 2014 3:27:24 PM org.apache.catalina.startup.Catalina start
INFO: Server startup in 23821 ms

Now: The problem It is when I deploy the same app (using a file .war) in the same tomcat7 server /var/lib/tomcat7/webapps

现在:问题是当我在同一个 tomcat7 服务器 /var/lib/tomcat7/webapps 中部署同一个应用程序(使用文件 .war)时

I can open the my initial page web BUT without data,

我可以在没有数据的情况下打开我的初始页面网页,

I see in the log:

我在日志中看到:

INFO: No Spring WebApplicationInitializer types detected on classpath

When I restart tomcat7 I get in the log file:

当我重新启动 tomcat7 时,我进入了日志文件:

INFO: Destroying ProtocolHandler ["http-bio-8843"]
Apr 8, 2014 3:25:30 PM org.apache.tomcat.util.digester.SetPropertiesRule begin
WARNING: [SetPropertiesRule]{Server/Service/Engine/Host/Context} Setting property 'source' to 'org.eclipse.jst.j2ee.server:my_project' did not find a matching property.
Apr 8, 2014 3:25:30 PM org.apache.coyote.AbstractProtocol init
INFO: Initializing ProtocolHandler ["http-bio-8888"]
Apr 8, 2014 3:25:31 PM org.apache.coyote.AbstractProtocol init
INFO: Initializing ProtocolHandler ["http-bio-8843"]
Apr 8, 2014 3:25:31 PM org.apache.catalina.startup.Catalina load
INFO: Initialization processed in 1664 ms
Apr 8, 2014 3:25:31 PM org.apache.catalina.core.StandardService startInternal
INFO: Starting service Catalina
Apr 8, 2014 3:25:31 PM org.apache.catalina.core.StandardEngine startInternal
INFO: Starting Servlet Engine: Apache Tomcat/7.0.26
Apr 8, 2014 3:25:38 PM org.apache.coyote.AbstractProtocol start
INFO: Starting ProtocolHandler ["http-bio-8888"]
Apr 8, 2014 3:25:38 PM org.apache.coyote.AbstractProtocol start
INFO: Starting ProtocolHandler ["http-bio-8843"]
Apr 8, 2014 3:25:38 PM org.apache.catalina.startup.Catalina start
INFO: Server startup in 7576 ms

回答by oleh.kovaliuk

This is common error, make sure that your file.war is built correctly. Just open .war file and check that your WebApplicationInitializer is there.

这是常见错误,请确保您的 file.war 构建正确。只需打开 .war 文件并检查您的 WebApplicationInitializer 是否在那里。

回答by Aron Elias Herrera Ponte

I found the error: I have a library that it was built using jdk 1.6. The Spring main controller and components are in this library. And how I use jdk 1.7, It does not find the classes built in 1.6.

我发现了错误:我有一个使用 jdk 1.6 构建的库。Spring 主控制器和组件都在这个库中。以及我如何使用 jdk 1.7,它没有找到 1.6 中内置的类。

The solution was built all using "compiler compliance level: 1.7" and "Generated .class files compatibility: 1.6", "Source compatibility: 1.6".

该解决方案全部使用“编译器合规性级别:1.7”和“生成的 .class 文件兼容性:1.6”、“源兼容性:1.6”构建。

I setup this option in Eclipse: Preferences\Java\Compiler.

我在 Eclipse 中设置了这个选项:Preferences\Java\Compiler。

Thanks everybody.

谢谢大家。

回答by Akshay

I also had the same problem. My maven had tomcat7 plugin but the JRE environment was 1.6. I changed my tomcat7 to tomcat6 and the error was gone.

我也有同样的问题。我的 maven 有 tomcat7 插件,但 JRE 环境是 1.6。我将我的 tomcat7 更改为 tomcat6,错误消失了。

回答by berhauz

I had this info message "No Spring WebApplicationInitializer types detected on classpath" while deploying a WAR with spring integration beans in WebLogic server. Actually, I could observe that the servlet URL returned 404 Not Found and beside that info message with a negative tone "No Spring ...etc" in Server logs, nothing else was seemingly in error in my spring config; no build or deployment errors, no complaints. Indeed, I suspected that the beans.xml (spring context XML) was actually not picked up at all and that was bound to the very specific organizing of artefacts in Oracle's jDeveloper. The solution is to play carefully with the 'contributors' and 'filters' for the WEB-INF/classes category when you edit your deployment profile under the 'deployment' topic in project properties.

在 WebLogic 服务器中部署带有 spring 集成 bean 的 WAR 时,我收到了此信息消息“在类路径上未检测到 Spring WebApplicationInitializer 类型”。实际上,我可以观察到 servlet URL 返回 404 Not Found 并且除了服务器日志中带有否定语气“No Spring ...etc”的信息消息之外,我的 spring 配置中似乎没有其他任何错误;没有构建或部署错误,没有投诉。事实上,我怀疑 beans.xml(spring 上下文 XML)实际上根本没有被选中,这与 Oracle 的 jDeveloper 中非常具体的人工制品组织有关。解决方案是在项目属性中的“部署”主题下编辑部署配置文件时,仔细使用 WEB-INF/类类别的“贡献者”和“过滤器”。

Precisely, I would advise to name your spring context by the jDeveloper default "beans.xml" and place it side by side to the WEB-INF subdirectory itself (under your web Apllication source path, e.g. like <...your project path>/public_html/). Then in the WEB-INF/classes category (when editing the deployment profile) your can check the Project HTML root directory in the 'contributor' list, and then select the beans.xml in filters, and then ensure your web.xml features a context-param value like classpath:beans.xml.

准确地说,我建议将您的 spring 上下文命名为 jDeveloper 默认的“beans.xml”,并将其并排放置到 WEB-INF 子目录本身(在您的 web 应用程序源路径下,例如 <...your project path> /public_html/)。然后在 WEB-INF/classes 类别中(编辑部署配置文件时)您可以检查“贡献者”列表中的项目 HTML 根目录,然后在过滤器中选择 beans.xml,然后确保您的 web.xml 具有上下文参数值,如 classpath:beans.xml。

Once that was fixed, I was able to progress and after some more bean config changes and implementations, the message "No Spring WebApplicationInitializer types detected on classpath" came back! Actually, I did not notice when and why exactly it came back. This second time, I added a

一旦解决了这个问题,我就能够继续前进,并且在进行了更多 bean 配置更改和实现之后,消息“在类路径上未检测到 Spring WebApplicationInitializer 类型”又回来了!实际上,我没有注意到它何时以及为什么回来。第二次,我添加了一个

public class HttpGatewayInit implements WebApplicationInitializer { ... }

which implements empty inherited methods, and the whole application works fine!

它实现了空的继承方法,整个应用程序工作正常!

...If you feel that java EE development has been getting a bit too crazy with cascades of XML configuration files (some edited manually, others through wizards) intepreted by cascades of variant initializers, let me insist that I fully share your point.

...如果您觉得 Java EE 开发对于由级联变体初始值设定项解释的级联 XML 配置文件(有些是手动编辑的,有些是通过向导进行编辑的)变得有点过于疯狂,那么让我坚持我完全同意您的观点。

回答by Sabry Shawally

Make sure that your log4j is configured correctly, there's probably an exception that is being thrown, but you're only seeing half of the picture.

确保您的 log4j 配置正确,可能会抛出异常,但您只看到图片的一半。

Please see https://stackoverflow.com/a/16817018/1249304

请参阅https://stackoverflow.com/a/16817018/1249304

回答by user5720758

For eclipse users: solution is simple just change the nature of project Spring Tools->add spring project nature

对于 eclipse 用户:解决方案很简单,只需更改项目的性质 Spring Tools->add spring project nature

done.

完毕。

回答by Anand Rockzz

My silly reason was: Build Automaticallywas disabled!

我愚蠢的原因是:自动构建被禁用了!

回答by neeranzan

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-compiler-plugin</artifactId>          
    <configuration>
        <source>1.8</source>
        <target>1.8</target>
    </configuration>
 </plugin>

This is the important plugin that should be in pom.xml. I spent my two days debugging and researching. This was the solution. This is Apache plugin to tell maven to use the the given Compiler.

这是应该在 pom.xml 中的重要插件。我花了两天时间调试和研究。这就是解决方案。这是告诉 Maven 使用给定编译器的 Apache 插件。

回答by Antoine

I had similar problem with Tomcat 8 embedded in java7 application.

我与嵌入在 java7 应用程序中的 Tomcat 8 有类似的问题。

When I launched Tomcat in my application, it worked. But when I launched it through Maven for integration test purpose, I got this error : "No Spring WebApplicationInitializer types detected on classpath".

当我在我的应用程序中启动 Tomcat 时,它工作正常。但是当我为了集成测试目的通过 Maven 启动它时,我收到了这个错误:“在类路径上没有检测到 Spring WebApplicationInitializer 类型”。

I fixed it by upgrading org.apache.tomcat.embed:tomcat-embed-*dependencies from version 8.0.29 to 8.0.47.

我通过将org.apache.tomcat.embed:tomcat-embed-*依赖项从版本 8.0.29升级到 8.0.47 来修复它。