在类路径上未检测到 Spring WebApplicationInitializer 类型

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/16321819/
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-09-08 05:55:39  来源:igfitidea点击:

No Spring WebApplicationInitializer types detected on classpath

springmodel-view-controllertomcatservletsspring-mvc

提问by Raevik

My Eclipse project is suddenly no longer deploying properly. I can't trace it to any particular change I've made to the environment.

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

I have tested with multiple source-controlled projects and they are all behaving the same way:

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

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

This seems like the key component: INFO: No Spring WebApplicationInitializer types detected on classpath.

这似乎是关键组件:信息:在类路径上未检测到 Spring WebApplicationInitializer 类型。

I've tried cleaning the projects, redefining the servers, and even creating whole new workspaces. I've clearly missed the mark.

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

Any tips on getting this cleaned up would be greatly appreciated.

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

采纳答案by Raevik

This turned out to be a stupid error. My log4j wasn't configured to capture my error output. I was throwing configuration errors in the background and once I fixed those I was good to go and my request mappings worked fine.

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

回答by Adrian Smith

I spent hours on this, and the solution was:

我花了几个小时在这上面,解决方案是:

  • Stop Tomcat
  • "Project" menu -> Clean -> Clean all projects
  • Servers tab -> Tomcat -> Right click -> Clean...
  • Right click on project -> Run as -> Run on server
  • 停止Tomcat
  • “项目”菜单 -> 清理 -> 清理所有项目
  • 服务器选项卡 -> Tomcat -> 右键单击​​ -> 清理...
  • 右键单击项目 -> 运行方式 -> 在服务器上运行

回答by Rafael Delbel

Watch out if you are using Maven. Your folder's structure mustbe right.

如果您使用 Maven,请当心。您的文件夹结构必须正确。

When using Maven, the WEB-INF directory must be inside webapp:

使用 Maven 时,WEB-INF 目录必须在webapp 内

src/main/webapp/WEB-INF

回答by denOfProgramming

INFO: No Spring WebApplicationInitializer types detected on classpath.

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

Can also show up if you're using Maven with Eclipse and deploying your WAR using;

如果您将 Maven 与 Eclipse 一起使用并使用以下方式部署您的 WAR,也可以显示;

(Eclipse, Kepler, with M2)

(Eclipse,开普勒,带 M2)

(right-click on your project) -> Run As -> Run on Server

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

It's down to the generation and deletion of the m2e-wtpfolder and contents.

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

Make sure, Maven Archive generated files under the build directoryis checked.

确保已选中build 目录下的 Maven Archive 生成​​的文件

Under: "Window -> preferences -> Maven -> Java EE Integration"

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

Then:

然后:

Use M2, to do your build, i.e. the usual Clean -> package or Install etc...

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

If "Project -> Build Automatically" is not selected. You can force the "m2e-wtp folder and contents" generation by doing;

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

"(right-click on your project) -> Maven -> Update Project..."

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

Note: make sure the "Clean Projects" option is un-selected.Otherwise the contents of target/classes will be deleted and you're back to square one.

注意:确保未选中“Clean Projects”选项。否则目标/类的内容将被删除,您将返回到第一个。

Also,when;

还有,什么时候;

"Project -> Build Automatically" is selected the "m2e-wtp folder and contents" is generated

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

or "Project -> Build All"

或“项目 -> 全部构建

or "(right-click on project) -> Build Project"

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

回答by Stefan

WebApplicationInitializer is an interface you can implement in one of your classes. At startup Spring is scanning for this classes, as long as you are using servlet spec 3 and have a metadata-complete="false" attribute in your web.xml. But that doesn't seem to be the problem. The only error I can figure out is the missing slf4j-log4j12.jar.

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

回答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 Karthik S

I faced this problem and finally resolved. Please make sure that your web.xml and Servlet.xml file should present in web/inf folder.

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

Also Please add spring jars into Web Deployment assembly in project properties

另外请在项目属性中将 spring jar 添加到 Web 部署程序集中

We might missed out this when setting up the project from beginning.

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

回答by Vishal jotshi

xml was not in the WEB-INF folder, thats why i was getting this error, make sure that web.xml and xxx-servlet.xml is inside WEB_INF folder and not in the webapp folder .

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

回答by John Mulhall

I got a silly error it took me an embarrassingly long to solve.... Check out my pom.xml ...

我遇到了一个愚蠢的错误,我花了很长时间才解决……查看我的 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>

Problem was my package name. It MUST be "com.outbottle" (then config/controllers/model/etc) for it to work. As you can see above, I used Maven (for the first time), Spring, 1.8 JDK and nearly had a stroke debugging this issue. All running on Glassfish (Tomcat is ok too for the above pom config). That said, I'm all happy with myself now and know Maven and Spring much better for the next step of my Spring learning curve. Hoping this helps you also!

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

回答by 8080_HouseFull

STS has a metadata folder under its workspace. You will see the actual error in .log file under C:\Users\firstname.lastname\Documents\workspace-sts-3.9.2.RELEASE.metadata

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