java - 信息 : No Spring WebApplicationInitializer types detected on classpath on tomcat 8

标签 java tomcat

我正在尝试在 tomcat 8 上部署一个 java web 应用程序。 war 建立在 jdk 1.8 上 当我看到 catalina.log 时,我看到应用程序已部署并且服务器已成功启动。 但是在 localhost.log 中我看到了消息 14-Dec-2015 12:10:42.774 INFO [localhost-startStop-1] org.apache.catalina.core.ApplicationContext.log 在类路径上未检测到 Spring WebApplicationInitializer 类型

此外,当我点击应用程序网址时,我无法启动欢迎页面。日志中没有其他错误。 如果我遗漏了什么,有人可以告诉我吗。

谢谢 阿皮特

最佳答案

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

<?xml version="1.0" encoding="UTF-8"?>

http://maven.apache.org/xsd/maven-4.0.0.xsd"> 4.0.0

<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. After checking:

a) IDE(对我来说是 Netbeans)中的运行时包名称,以查看我的运行时源是否是针对 POM 的 1.8kjdk

b) 仔细检查 POM (pom.xml) 以确保它具有用于注释 (3.0+) 和 Spring 依赖项的 Javax servlet 配置

c) 仔细检查我的 WebInitializer.java(实现 WebApplicationInitializer(而不是 web.xml))在语法上是正确的

d) 仔细检查我的 Config.java 文件以确保它正确地重载了​​ addResourceHandlers(ResourceHandlerRegistry registry) 并且 setupViewResolver() 的 bean 是正确的

e) 仔细检查我的文件夹结构以确保它是正确的并且程序流程看起来连贯

f) 删除并重新部署 Glassfish 以查看是否有任何变化

然后我发现我的问题是:

f) "com.trainer.config" is wrong! 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!

关于java - 信息 : No Spring WebApplicationInitializer types detected on classpath on tomcat 8,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34264583/

相关文章:

java - 如何使用 JAX-WS 将后端方法的异常消息解析为 SOAP 响应消息?

java - 最少调用 subArrayLeftShift 方法来排序数组(面试题)

java - 如何让函数返回 "Double"或 "Int"?

java - Tomcat 只允许我下载 servlet

security - 如何为除一个以外的所有 URL 应用 tomcat 安全角色?

java - InstantiationException 使用 Spring 注入(inject)

java - NullPointer 与 Arquillian CDI 测试

java - Java 中字符串中的转义引号

java - 如何从 Eclipse 中的验证中排除 .java 文件

java - 如何在不对 URL 进行硬编码的情况下调用我的 REST API get 方法?