No Spring WebApplicationInitializer types detected on classpath

前端 未结 13 1804
野的像风
野的像风 2020-11-29 08:03

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

I have tested with multiple s

相关标签:
13条回答
  • 2020-11-29 09:00

    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

    0 讨论(0)
  • 2020-11-29 09:03

    INFO: No Spring WebApplicationInitializer types detected on classpath.

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

    (Eclipse, Kepler, with M2)

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

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

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

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

    Then:

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

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

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

    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.

    Also,when;

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

    or "Project -> Build All"

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

    0 讨论(0)
  • 2020-11-29 09:06

    tomcat-maven-plugin in test

    Tomcat usually does not add classes in src/test/java to the classpath. They are missing if you run tomcat in scope test. To order tomcat to respect classes in test, use -Dmaven.tomcat.useTestClasspath=true or add

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

    To your pom.xml.

    0 讨论(0)
  • 2020-11-29 09:07

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

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

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

    0 讨论(0)
  • 2020-11-29 09:09

    I got a silly error it took me an embarrassingly long to solve.... Check out my 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!

    0 讨论(0)
  • 2020-11-29 09:10

    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.

    0 讨论(0)
提交回复
热议问题