【问题标题】:No Spring WebApplicationInitializer types detected on classpath在类路径上未检测到 Spring WebApplicationInitializer 类型
【发布时间】:2013-04-25 16:01:25
【问题描述】:

我的 Eclipse 项目突然不再正确部署。我无法追踪到我对环境所做的任何特定更改。

我已经对多个源代码控制项目进行了测试,它们的行为方式都相同:

May 01, 2013 12:00:45 PM org.apache.catalina.core.AprLifecycleListener init
INFO: The APR based Apache Tomcat Native library which allows optimal performance in     production environments was not found on the java.library.path: C:\Program Files   (x86)\Java\jdk1.7.0_11\bin;C:\Windows\Sun\Java\bin;C:\Windows\system32;C:\Windows;C:\Program Files (x86)\NVIDIA     Corporation\PhysX\Common;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows \System32\WindowsPowerShell\v1.0\;.
May 01, 2013 12:00:45 PM org.apache.tomcat.util.digester.SetPropertiesRule begin
WARNING: [SetPropertiesRule]{Server/Service/Engine/Host/Context} Setting property 'source' to 'org.eclipse.jst.jee.server:fismacm' did not find a matching property.
May 01, 2013 12:00:45 PM org.apache.coyote.AbstractProtocol init
INFO: Initializing ProtocolHandler ["http-bio-8080"]
May 01, 2013 12:00:45 PM org.apache.coyote.AbstractProtocol init
INFO: Initializing ProtocolHandler ["ajp-bio-8009"]
May 01, 2013 12:00:45 PM org.apache.catalina.startup.Catalina load
INFO: Initialization processed in 296 ms
May 01, 2013 12:00:45 PM org.apache.catalina.core.StandardService startInternal
INFO: Starting service Catalina
May 01, 2013 12:00:45 PM org.apache.catalina.core.StandardEngine startInternal
INFO: Starting Servlet Engine: Apache Tomcat/7.0.35
May 01, 2013 12:00:46 PM org.apache.catalina.core.ApplicationContext log
INFO: No Spring WebApplicationInitializer types detected on classpath
May 01, 2013 12:00:48 PM org.apache.catalina.startup.TaglibUriRule body
INFO: TLD skipped. URI: http://java.sun.com/jstl/core is already defined
May 01, 2013 12:00:48 PM org.apache.catalina.startup.TaglibUriRule body
INFO: TLD skipped. URI: http://java.sun.com/jstl/sql_rt is already defined
May 01, 2013 12:00:48 PM org.apache.catalina.startup.TaglibUriRule body
INFO: TLD skipped. URI: http://java.sun.com/jsp/jstl/sql is already defined
May 01, 2013 12:00:48 PM org.apache.catalina.startup.TaglibUriRule body
INFO: TLD skipped. URI: http://java.sun.com/jstl/core_rt is already defined
May 01, 2013 12:00:48 PM org.apache.catalina.startup.TaglibUriRule body
INFO: TLD skipped. URI: http://java.sun.com/jsp/jstl/core is already defined
May 01, 2013 12:00:48 PM org.apache.catalina.startup.TaglibUriRule body
INFO: TLD skipped. URI: http://java.sun.com/jsp/jstl/functions is already defined
May 01, 2013 12:00:48 PM org.apache.catalina.startup.TaglibUriRule body
INFO: TLD skipped. URI: http://java.sun.com/jstl/fmt is already defined
May 01, 2013 12:00:48 PM org.apache.catalina.startup.TaglibUriRule body
INFO: TLD skipped. URI: http://jakarta.apache.org/taglibs/standard/permittedTaglibs is already defined
May 01, 2013 12:00:48 PM org.apache.catalina.startup.TaglibUriRule body
INFO: TLD skipped. URI: http://java.sun.com/jstl/xml is already defined
May 01, 2013 12:00:48 PM org.apache.catalina.startup.TaglibUriRule body
INFO: TLD skipped. URI: http://jakarta.apache.org/taglibs/standard/scriptfree is already defined
May 01, 2013 12:00:48 PM org.apache.catalina.startup.TaglibUriRule body
INFO: TLD skipped. URI: http://java.sun.com/jstl/fmt_rt is already defined
May 01, 2013 12:00:48 PM org.apache.catalina.startup.TaglibUriRule body
INFO: TLD skipped. URI: http://java.sun.com/jsp/jstl/fmt is already defined
May 01, 2013 12:00:48 PM org.apache.catalina.startup.TaglibUriRule body
INFO: TLD skipped. URI: http://java.sun.com/jsp/jstl/xml is already defined
May 01, 2013 12:00:48 PM org.apache.catalina.startup.TaglibUriRule body
INFO: TLD skipped. URI: http://java.sun.com/jstl/xml_rt is already defined
May 01, 2013 12:00:48 PM org.apache.catalina.startup.TaglibUriRule body
INFO: TLD skipped. URI: http://java.sun.com/jstl/sql is already defined
May 01, 2013 12:00:48 PM org.apache.catalina.startup.TaglibUriRule body
INFO: TLD skipped. URI: http://www.springframework.org/tags/form is already defined
May 01, 2013 12:00:48 PM org.apache.catalina.startup.TaglibUriRule body
INFO: TLD skipped. URI: http://www.springframework.org/tags is already defined
May 01, 2013 12:00:48 PM org.apache.catalina.startup.TaglibUriRule body
INFO: TLD skipped. URI: http://www.springframework.org/security/tags is already defined
May 01, 2013 12:00:48 PM org.apache.catalina.core.ApplicationContext log
INFO: No Spring WebApplicationInitializer types detected on classpath
May 01, 2013 12:00:48 PM org.apache.catalina.core.ApplicationContext log
INFO: No Spring WebApplicationInitializer types detected on classpath
May 01, 2013 12:00:48 PM org.apache.catalina.core.ApplicationContext log
INFO: Set web app root system property: 'webapp.root' =     [X:\workspace\.metadata\.plugins\org.eclipse.wst.server.core\tmp0\wtpwebapps\fismacm\]
May 01, 2013 12:00:48 PM org.apache.catalina.core.ApplicationContext log
INFO: Initializing log4j from [X:\workspace\.metadata\.plugins\org.eclipse.wst.server.core\tmp0\wtpwebapps\fismacm\WEB-    INF\log4j.properties]
May 01, 2013 12:00:48 PM org.apache.catalina.core.ApplicationContext log
INFO: Initializing Spring root WebApplicationContext
SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
SLF4J: Defaulting to no-operation (NOP) logger implementation
SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details.
May 01, 2013 12:00:49 PM org.apache.coyote.AbstractProtocol start
INFO: Starting ProtocolHandler ["http-bio-8080"]
May 01, 2013 12:00:49 PM org.apache.coyote.AbstractProtocol start
INFO: Starting ProtocolHandler ["ajp-bio-8009"]
May 01, 2013 12:00:49 PM org.apache.catalina.startup.Catalina start
INFO: Server startup in 3898 ms

这似乎是关键组件:INFO: No Spring WebApplicationInitializer types detected on classpath。

我尝试过清理项目、重新定义服务器,甚至创建全新的工作区。我显然错过了目标。

任何有关清理此问题的提示将不胜感激。

【问题讨论】:

  • 您尝试在 Eclipse 中启动您的应用程序吗?它是一个 Maven 项目吗?如果是,您的 maven 依赖项是否被导出到 WEB-INF/lib? (属性->部署程序集)
  • 我在 Eclipse 中运行该应用程序。这不是一个 Maven 项目,尽管在经历了这次挫折之后,我倾向于朝那个方向发展。
  • 你能添加更多细节,比如 web.xml 吗?

标签: spring model-view-controller tomcat servlets spring-mvc


【解决方案1】:

我为此花了几个小时,解决方案是:

  • 停止 Tomcat
  • “项目”菜单 -> 清理 -> 清理所有项目
  • 服务器选项卡 -> Tomcat -> 右键单击​​ -> 清理...
  • 项目右键->运行方式->在服务器上运行

【讨论】:

  • +1 这对我有用。昨天我的服务器正在工作,今天我收到“没有找到弹簧 WebApplicationInitializer”错误。执行此步骤解决了它。
【解决方案2】:

结果证明这是一个愚蠢的错误。我的 log4j 未配置为捕获我的错误输出。我在后台抛出配置错误,一旦我修复了这些错误,我就可以开始了,我的请求映射工作正常。

【讨论】:

  • 你还记得你做了什么来修复错误输出配置吗?我想我也有同样的问题
【解决方案3】:

如果您使用的是 Maven,请注意。您的文件夹结构必须正确。

使用Maven时,WEB-INF目录必须在webapp里面:

src/main/webapp/WEB-INF

【讨论】:

    【解决方案4】:

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

    如果您在 Eclipse 中使用 Maven 并使用 WAR 部署,也可以显示;

    (Eclipse,开普勒,带 M2)

    (右键单击您的项目)-> 运行方式-> 在服务器上运行

    这取决于m2e-wtp文件夹和内容的生成和删除。

    确保选中构建目录下的Maven存档生成文件

    在:“窗口 -> 首选项 -> Maven -> Java EE 集成”下

    然后:

    使用 M2 进行构建,即通常的 Clean -> package 或 Install 等...

    如果未选择“项目 -> 自动构建”。 您可以通过执行强制“m2e-wtp 文件夹和内容”生成;

    (右键单击您的项目)-> Maven -> 更新项目...

    注意:确保未选中“清理项目”选项。 否则目标/类的内容将被删除,你又回到了原点。

    还有,什么时候;

    选择“Project -> Build Automatically”,生成“m2e-wtp文件夹和内容”

    或 "项目 -> 全部构建"

    或 "(右击项目)->构建项目"

    【讨论】:

      【解决方案5】:

      WebApplicationInitializer 是您可以在其中一个类中实现的接口。只要您使用 servlet 规范 3 并且在 web.xml 中有 metadata-complete="false" 属性,Spring 在启动时就会扫描此类。但这似乎不是问题。我能弄清楚的唯一错误是缺少 slf4j-log4j12.jar。

      【讨论】:

        【解决方案6】:

        我遇到了这个问题,终于解决了。请确保您的 web.xml 和 Servlet.xml 文件应该出现在 web/inf 文件夹中。

        另外请在项目属性的Web部署程序集中添加spring jars

        从一开始就设置项目时,我们可能会错过这一点。

        【讨论】:

          【解决方案7】:

          在我的情况下,它也变成了一个多小时的调试会话。尝试设置更详细的日志记录完全是徒劳的,因为问题是我的应用程序甚至没有启动。这是我的context.xml

          <?xml version='1.0' encoding='utf-8'?>
          <Context path="/rc2" docBase="rc2" antiResourceLocking="false" >
              <JarScanner>
                  <JarScanFilter
                      tldScan="spring-webmvc*.jar, spring-security-taglibs*.jar, jakarta.servlet.jsp.jstl*.jar"
                      tldSkip="*.jar"
                      <!-- my-own-app*.jar on the following line was missing! -->
                      pluggabilityScan="${tomcat.util.scan.StandardJarScanFilter.jarsToScan}, my-own-app*.jar"
                      pluggabilitySkip="*.jar"/>
              </JarScanner>
          </Context>
          

          问题在于,为了加快应用程序的启动速度,我开始跳过对许多 JAR 的扫描,不幸的是包括我自己的应用程序。

          【讨论】:

            【解决方案8】:

            xml 不在 WEB-INF 文件夹中,这就是我收到此错误的原因, 确保 web.xml 和 xxx-servlet.xml 在 WEB_INF 文件夹中,而不是在 webapp 文件夹中。

            【讨论】:

            • 我已修改部署程序集以在部署程序集中包含 webapp 文件夹。谢谢,
            • 否:WebApplicationInitializer 的全部意义在于您不需要需要 web.xml。添加 web.xml 并不能解决问题(过时的 Java 1.5 jars),它只是掩盖了症状:(
            【解决方案9】:

            我遇到了一个愚蠢的错误,我花了很长时间才解决……查看我的 pom.xml……

            <?xml version="1.0" encoding="UTF-8"?>
            <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
            <modelVersion>4.0.0</modelVersion>
            
            <groupId>com.outbottle</groupId>
            <artifactId>PersonalDetailsMVC</artifactId>
            <version>1.0-SNAPSHOT</version>
            <packaging>war</packaging>
            
            <name>PersonalDetailsMVC</name>
            
            <properties>
                <endorsed.dir>${project.build.directory}/endorsed</endorsed.dir>
                <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
                <spring.version>4.0.1.RELEASE</spring.version>
                <jstl.version>1.2</jstl.version>
                <javax.servlet.version>3.0.1</javax.servlet.version>
            </properties>
            
            <dependencies>
                <dependency>
                    <groupId>javax</groupId>
                    <artifactId>javaee-web-api</artifactId>
                    <version>7.0</version>
                    <scope>provided</scope>
                </dependency>
            
                <dependency>
                    <groupId>org.springframework</groupId>
                    <artifactId>spring-core</artifactId>
                    <version>${spring.version}</version>
                </dependency>
            
                <dependency>
                    <groupId>org.springframework</groupId>
                    <artifactId>spring-web</artifactId>
                    <version>${spring.version}</version>
                </dependency>
            
                <dependency>
                    <groupId>org.springframework</groupId>
                    <artifactId>spring-webmvc</artifactId>
                    <version>${spring.version}</version>
                </dependency>
            
                <dependency>
                    <groupId>javax.servlet</groupId>
                    <artifactId>javax.servlet-api</artifactId>
                    <version>${javax.servlet.version}</version>
                    <scope>provided</scope>
                </dependency>
            
                <dependency>
                    <groupId>jstl</groupId>
                    <artifactId>jstl</artifactId>
                    <version>${jstl.version}</version>
                </dependency>
            
            </dependencies>
            
            <build>
                <plugins>
                    <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-compiler-plugin</artifactId>
                        <version>3.1</version>
                        <configuration>
                            <source>1.8</source>
                            <target>1.8</target>
                            <compilerArguments>
                                <endorseddirs>${endorsed.dir}</endorseddirs>
                            </compilerArguments>
                        </configuration>
                    </plugin>
                    <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-war-plugin</artifactId>
                        <version>2.3</version>
                        <configuration>
                            <failOnMissingWebXml>false</failOnMissingWebXml>
                        </configuration>
                    </plugin>
                    <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-dependency-plugin</artifactId>
                        <version>2.6</version>
                        <executions>
                            <execution>
                                <phase>validate</phase>
                                <goals>
                                    <goal>copy</goal>
                                </goals>
                                <configuration>
                                    <outputDirectory>${endorsed.dir}</outputDirectory>
                                    <silent>true</silent>
                                    <artifactItems>
                                        <artifactItem>
                                            <groupId>javax</groupId>
                                            <artifactId>javaee-endorsed-api</artifactId>
                                            <version>7.0</version>
                                            <type>jar</type>
                                        </artifactItem>
                                    </artifactItems>
                                </configuration>
                            </execution>
                        </executions>
                    </plugin>
                </plugins>
            </build>
            

            问题是我的包名。它必须是“com.outbottle”(然后是 config/controllers/model/etc)才能工作。正如您在上面看到的,我使用了 Maven(第一次)、Spring、1.8 JDK,并且几乎中风了调试这个问题。全部在 Glassfish 上运行(Tomcat 对于上述 pom 配置也可以)。也就是说,我现在对自己很满意,并且在我的 Spring 学习曲线的下一步中更了解 Maven 和 Spring。希望这对您也有帮助!

            【讨论】:

              【解决方案10】:

              STS 在其工作区下有一个元数据文件夹。您将在 .log 文件中看到实际错误 C:\Users\firstname.lastname\Documents\workspace-sts-3.9.2.RELEASE.metadata

              【讨论】:

                【解决方案11】:

                tomcat-maven-plugin 在测试中

                Tomcat 通常不会将src/test/java 中的类添加到类路径中。如果您在范围测试中运行 tomcat,它们会丢失。要命令 tomcat 尊重测试中的类,请使用 -Dmaven.tomcat.useTestClasspath=true 或添加

                <properties>
                   <maven.tomcat.useTestClasspath>true</maven.tomcat.useTestClasspath>
                </properties>
                

                致您的pom.xml

                【讨论】:

                  【解决方案12】:

                  我今天花了一整天的时间调查这个问题,但没有一个答案有帮助。这是我的场景。在我的例子中,WebApplicationInitializer 类型在 jar 文件中。我们有一个多模块 gradle web 项目,其中每个模块都打包为 jar 并包含在 web 工件中。问题是 Apache tomcat 的类加载器不是在 WEB-INF/lib 中寻找 WebApplicationIntializer 的实现,而是直接在 WEB-INF/classes 文件夹下寻找那些类型。

                  这是我最终为将来遇到此问题的任何人所做的事情。

                  我自己实现了一个 ServletContainerInitializer 并将该类名添加到 META-INF/services/javax.servlet.ServletContainerInitializer

                  在实现中,我从 SpringServletContainerInitializer 中复制代码并使用反射找到实现 CustomWebApplicationInitializer 接口的类,我没有使用 Spring 的 WebApplicationInitializer 接口以避免任何冲突。基本上我有与 WebApplicationInitializer 相同的合同,但名称不同。现在在启动时,我的容器初始化程序被调用,我将调用委托给我的所有 CustomWebApplicationInitializers。

                  根据我的搜索,我还发现用于 tomcat 的加载程序可以更新以使其在 WEB-INF/lib 中搜索,但我对部署我的应用程序的 tomcat 几乎没有控制权,因此采用上述解决方案。希望这对某人有所帮助。

                  【讨论】:

                    【解决方案13】:

                    如果您使用的是 Eclipse IDE 并发现问题 INFO: No Spring WebApplicationInitializer types detected on classpath 请检查“Web App Libraries”的定义,如图所示。 它在那里吗?如果没有,则“添加库->Web 应用程序库” 然后清理并构建并重新启动服务器

                    Look at the class path as in the picture.

                    【讨论】:

                      猜你喜欢
                      • 2014-05-21
                      • 2016-06-19
                      • 2018-11-30
                      • 2014-08-28
                      • 2019-09-06
                      • 2017-06-02
                      • 1970-01-01
                      • 2021-08-31
                      相关资源
                      最近更新 更多