为了直截了当,我遇到的问题是,当我使用Spring Boot运行Spring Web Application时,我在转到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'
我认为可能的问题是我正在尝试使用eclipse运行我的Maven项目,但是webapp文件夹和Maven依赖项似乎没有正确部署到目标文件夹。
我通过执行以下操作创建了项目:文件>新> Maven项目>行家-原型-快速启动
以下是目录在创建时的注意事项:
src
main
java
site
site
App.java
test
java
site
site
AppTest.java
target
pom.xml
经过一些修改,更新pom.xml并运行命令
mvn eclipse:eclipse -Dwtpversion=2.0
我的项目结构如下所示:
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
编译和运行时生成的目标目录结构如下所示:
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
也许我对在编译和运行应用程序时应该如何部署webapp和资源文件夹感到困惑,但根据我的Web部署程序集,应该发生以下情况:
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/
至于我的构建路径,它目前看起来像这样:
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
也许构建路径和Web部署程序集彼此冲突,或者我可能只是没有以正确的方式构建它?我按下Eclipse的运行按钮运行这个应用程序,并使用Spring Boot,如下所示:
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);
}
}
}
如果我的pom.xml可以使用:
<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>
我的.classpath文件夹:
<?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>
非常感谢任何帮助,因为我很乐意尽快克服这条路障。如果您需要更多信息,请告诉我们 - 谢谢!
答案 0 :(得分:0)
你可以做的事情
<welcome-file-list>
。{/ li>中的web.xml
DEBUG
日志记录spring并检查服务器启动时是否映射IndexController
控制器答案 1 :(得分:0)
结束废弃我已经实施的项目结构,并非常密切地遵循本指南:
http://www.beingjavaguys.com/2013/08/spring-maven-web-application-in-eclipse.html