在类路径上没有检测到Spring WebApplicationInitializer类型

时间:2013-05-01 16:05:43

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

我的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:在类路径上没有检测到Spring WebApplicationInitializer类型。

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

任何有关清理这些内容的提示都将非常感激。

13 个答案:

答案 0 :(得分:14)

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

  • 停止Tomcat
  • “项目”菜单 - >清洁 - >清理所有项目
  • 服务器标签 - > Tomcat - >右键单击 - >清洁...
  • 右键点击项目 - >以 - >运行在服务器上运行

答案 1 :(得分:11)

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

答案 2 :(得分:7)

注意您是否使用Maven。您文件夹的结构必须正确。

使用Maven时,WEB-INF目录必须位于 webapp 内:

src/main/webapp/WEB-INF

答案 3 :(得分:4)

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

如果您正在使用Maven和Eclipse并使用;

部署WAR,也可以显示

(Eclipse,Kepler,M2)

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

归结为 m2e-wtp 文件夹和内容的生成和删除。

确保选中 Maven Archive生成的文件在构建目录下。

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

然后:

使用M2,进行构建,即通常的Clean - >包装或安装等...

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

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

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

此外,当;

选择“项目 - >自动构建”,生成“m2e-wtp文件夹和内容”

或 “项目 - >全部构建

或 “(右键单击项目) - >构建项目

答案 4 :(得分:2)

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

答案 5 :(得分:2)

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

也请在项目属性的Web Deployment组件中添加弹簧罐

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

答案 6 :(得分:1)

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

答案 7 :(得分:1)

就我而言,它也变成了一个数小时的调试会话。尝试设置更详细的日志记录完全是徒劳的,因为问题是我的应用程序甚至没有启动。这是我的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 :(得分:0)

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

答案 9 :(得分:0)

我遇到了一个愚蠢的错误,我花了很长时间才解决....查看我的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上运行(对于上面的pom配置,Tomcat也可以)。也就是说,我现在对自己感到高兴,并且对于我的Spring学习曲线的下一步更了解Maven和Spring。希望这也有助于你!

答案 10 :(得分:0)

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

答案 11 :(得分:0)

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 :(得分:0)

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

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

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

在实现中,我从SpringServletContainerIntializer复制了代码,并使用反射来找到实现CustomWebApplicationInitializer接口的类,但我没有利用spring的WebApplicationInitializer接口来避免任何冲突。基本上,我与WebApplicationInitializer具有相同的协定,但名称不同。现在,在启动时,将调用我的容器初始化程序,并将该调用委派给所有CustomWebApplicationInitializers。

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