简体   繁体   中英

Maven Dependencies and webapp folder not deploying to target folder in Eclipse?

To get straight to the point, the problem I am running into is that while I am running my Spring Web Application using Spring Boot, I get the following message upon going to localhost:8080

2014-03-11 18:56:31.614  WARN 7640 --- [nio-8080-exec-3] o.s.web.servlet.PageNotFound             : No mapping found for HTTP request with URI [/WEB-INF/views/index.jsp] in DispatcherServlet with name 'dispatcherServlet'

What I think may be the problem is that I am trying to run my Maven project using eclipse, but the webapp folder and Maven Dependencies do not seem to be properly deploying to the target folder.

I created the project by doing: File > New > Maven Project > maven-archetype-quickstart

Here's how the directory looked upon creation:

src
    main
        java
            site
                site
                    App.java
    test
        java
            site
                site
                    AppTest.java
target
pom.xml

After some modifications, updating pom.xml, and running the command

mvn eclipse:eclipse -Dwtpversion=2.0

my project structure looks like the following:

src
    main
        java
            net
                site
                    config
                        Application.java
                        CoreConfig.java
                        MVCConfig.java
                        SecurityConfig.java
                    controller
                        IndexController.java
        resources
        webapp
            WEB-INF
                views
                    index.jsp
                    login.jsp
    test
        java
        resources
target
    m2e-wtp
        web-resources
            META-INF
                MANIFEST.MF
                maven
                    site
                        site
                            pom.properties
                            pom.xml
.classpath
.project
pom.xml

And the resulting target directory structure upon compiling and running looks like this:

target
    classes
        net
            site
                config
                    Application.class
                    CoreConfig.class
                    MVCConfig.class
                    SecurityConfig.class
                    WebAppInitializer.class
                controller
                    IndexController.class
    m2e-wtp
        web-resources
            META-INF
                MANIFEST.MF
                maven
                    site
                        site
                            pom.properties
                            pom.xml
    test-classes

Perhaps I'm just confused about how the webapp and resources folders should be deployed upon compiling and running the application, but according to my Web Deployment Assembly the following should happen:

Source                                  Deploy Path
/src/main/java/                   ->    /target/WEB-INF/classes/
/src/main/resources/              ->    /target/WEB-INF/classes/
/src/main/webapp/                 ->    /target/
/src/test/java/                   ->    /target/WEB-INF/classes/
/src/test/resources/              ->    /target/WEB-INF/classes/
/target/m2e-wtp/web-resources/    ->    /target/

As for my build path, it currently looks like this:

site/src/main/java
    Output folder: site/target/classes
    Included: (All)
    Excluded: (None)
    Native library location: (None)
    Ignore optional compile problems: No
site/src/main/resources
    Output folder: site/target/classes
    Included: (All)
    Excluded: **
    Native library location: (None)
    Ignore optional compile problems: No
site/src/test/java
    Output folder: site/target/test-classes
    Included: (All)
    Excluded: (None)
    Native library location: (None)
    Ignore optional compile problems: No
site/src/test/resources
    Output folder: site/target/test-classes
    Included: (All)
    Excluded: **
    Native library location: (None)
    Ignore optional compile problems: No

Perhaps the Build Path and Web Deployment Assembly are in conflict with each other, or perhaps I'm just not building it the right way? I'm running this application by pressing Eclipse's run button and am using Spring Boot as seen below:

package net.site.config;

import java.util.Arrays;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;

@Configuration
@EnableAutoConfiguration
@ComponentScan
public class Application
{
    public static void main(String[] args) throws Throwable
    {
        ApplicationContext ctx = SpringApplication.run(Application.class, args);
        System.out.println("Inspecting the beans provided by Spring Boot:");

        String[] beanNames = ctx.getBeanDefinitionNames();
        Arrays.sort(beanNames);
        for(String beanName : beanNames)
        {
            System.out.println(beanName);
        }
    }
}

In case my pom.xml can be of any use:

<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>site</groupId>
    <artifactId>site</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <packaging>war</packaging>

    <name>site</name>
    <url>http://maven.apache.org</url>

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    </properties>

    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>1.0.0.RC4</version>
    </parent>
    <dependencyManagement>
        <dependencies>
            <dependency>
                <groupId>org.springframework</groupId>
                <artifactId>spring-framework-bom</artifactId>
                <version>4.0.2.RELEASE</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>
        </dependencies>
    </dependencyManagement>
    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-security</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-actuator</artifactId>
        </dependency>
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-core</artifactId>
            <exclusions>
                <exclusion>
                    <groupId>commons-logging</groupId>
                    <artifactId>commons-logging</artifactId>
                </exclusion>
            </exclusions>
        </dependency>
        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>jcl-over-slf4j</artifactId>
        </dependency>
        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>slf4j-api</artifactId>
        </dependency>
        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>slf4j-log4j12</artifactId>
        </dependency>
        <dependency>
            <groupId>log4j</groupId>
            <artifactId>log4j</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-web</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-webmvc</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-beans</artifactId>
        </dependency>
        <dependency>
            <groupId>javax.servlet</groupId>
            <artifactId>javax.servlet-api</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.security</groupId>
            <artifactId>spring-security-web</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.security</groupId>
            <artifactId>spring-security-config</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.security</groupId>
            <artifactId>spring-security-core</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-test</artifactId>
        </dependency>
        <dependency>
            <groupId>org.mockito</groupId>
            <artifactId>mockito-all</artifactId>
            <version>1.9.5</version>
        </dependency>
    </dependencies>
    <repositories>
        <repository>
            <id>spring-milestones</id>
            <name>Spring Milestones</name>
            <url>http://repo.spring.io/milestone</url>
            <snapshots>
                <enabled>false</enabled>
            </snapshots>
        </repository>
    </repositories>
</project>

And my .classpath folder:

<?xml version="1.0" encoding="UTF-8"?>
<classpath>
    <classpathentry kind="src" output="target/classes" path="src/main/java">
        <attributes>
            <attribute name="optional" value="true"/>
            <attribute name="maven.pomderived" value="true"/>
        </attributes>
    </classpathentry>
    <classpathentry kind="src" output="target/test-classes" path="src/test/java">
        <attributes>
            <attribute name="optional" value="true"/>
            <attribute name="maven.pomderived" value="true"/>
        </attributes>
    </classpathentry>
    <classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER">
        <attributes>
            <attribute name="maven.pomderived" value="true"/>
            <attribute name="org.eclipse.jst.component.dependency" value="/WEB-INF/lib"/>
        </attributes>
    </classpathentry>
    <classpathentry excluding="**" kind="src" output="target/classes" path="src/main/resources">
        <attributes>
            <attribute name="maven.pomderived" value="true"/>
        </attributes>
    </classpathentry>
    <classpathentry excluding="**" kind="src" output="target/test-classes" path="src/test/resources">
        <attributes>
            <attribute name="maven.pomderived" value="true"/>
        </attributes>
    </classpathentry>
    <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6">
        <attributes>
            <attribute name="maven.pomderived" value="true"/>
        </attributes>
    </classpathentry>
    <classpathentry kind="output" path="target/classes"/>
</classpath>

Any help is greatly appreciated, as I'd love to get over this road bump as soon as possible. Let me know if you need any more information - thanks!

Couple of things you can do

  1. check for <welcome-file-list> in your web.xml .
  2. enable DEBUG logging for spring and check at server start up time whether IndexController controller is mapped or not

Ended up scrapping the project structure I had in place and following this guide pretty closely:

http://www.beingjavaguys.com/2013/08/spring-maven-web-application-in-eclipse.html

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM