我一直在尝试使用Gradle在Spring启动时创建具有Apache Tiles的Sample应用程序。现在我在运行时遇到错误
2017-08-29 22:58:08 [http-nio-8080-exec-3] TRACE o.s.w.s.h.BeanNameUrlHandlerMapping - No handler mapping found for [/WEB-INF/view/layout/main.jsp]
2017-08-29 22:58:08 [http-nio-8080-exec-3] TRACE o.s.web.servlet.DispatcherServlet - Testing handler map [org.springframework.web.servlet.handler.SimpleUrlHandlerMapping@5f84d53b] in DispatcherServlet with name 'dispatcherServlet'
2017-08-29 22:58:08 [http-nio-8080-exec-3] DEBUG o.s.w.s.h.SimpleUrlHandlerMapping - Matching patterns for request [/WEB-INF/view/layout/main.jsp] are [/**]
2017-08-29 22:58:08 [http-nio-8080-exec-3] DEBUG o.s.w.s.h.SimpleUrlHandlerMapping - URI Template variables for request [/WEB-INF/view/layout/main.jsp] are {}
2017-08-29 22:58:08 [http-nio-8080-exec-3] DEBUG o.s.w.s.h.SimpleUrlHandlerMapping - Mapping [/WEB-INF/view/layout/main.jsp] to HandlerExecutionChain with handler [ResourceHttpRequestHandler [locations=[ServletContext resource [/], class path resource [META-INF/resources/], class path resource [resources/], class path resource [static/], class path resource [public/]], resolvers=[org.springframework.web.servlet.resource.PathResourceResolver@51abf713]]] and 1 interceptor
2017-08-29 22:58:08 [http-nio-8080-exec-3] TRACE o.s.web.servlet.DispatcherServlet - Testing handler adapter [org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter@5c48030d]
2017-08-29 22:58:08 [http-nio-8080-exec-3] TRACE o.s.web.servlet.DispatcherServlet - Testing handler adapter [org.springframework.web.servlet.mvc.HttpRequestHandlerAdapter@47949c09]
2017-08-29 22:58:08 [http-nio-8080-exec-3] DEBUG o.s.web.servlet.DispatcherServlet - Last-Modified value for [/WEB-INF/view/layout/main.jsp] is: -1
2017-08-29 22:58:08 [http-nio-8080-exec-3] TRACE o.s.w.s.r.ResourceHttpRequestHandler - Applying "invalid path" checks to path: WEB-INF/view/layout/main.jsp
2017-08-29 22:58:08 [http-nio-8080-exec-3] TRACE o.s.w.s.r.ResourceHttpRequestHandler - Path contains "WEB-INF" or "META-INF".
2017-08-29 22:58:08 [http-nio-8080-exec-3] TRACE o.s.w.s.r.ResourceHttpRequestHandler - Ignoring invalid resource path [WEB-INF/view/layout/main.jsp]
2017-08-29 22:58:08 [http-nio-8080-exec-3] TRACE o.s.w.s.r.ResourceHttpRequestHandler - No matching resource found - returning 404
2017-08-29 22:58:08 [http-nio-8080-exec-3] DEBUG o.s.web.servlet.DispatcherServlet - Null ModelAndView returned to DispatcherServlet with name 'dispatcherServlet': assuming HandlerAdapter completed request handling
2017-08-29 22:58:08 [http-nio-8080-exec-3] TRACE o.s.web.servlet.DispatcherServlet - Cleared thread-bound request context: org.apache.catalina.core.ApplicationHttpRequest@6a0b5a41
2017-08-29 22:58:08 [http-nio-8080-exec-3] DEBUG o.s.web.servlet.DispatcherServlet - Successfully completed request
如果我用maven替换gradle项目,它一直工作正常。我创造了gradle& amp; maven构建脚本。您可以在this位置找到示例项目。我认为问题在于gradle提供的范围。
build.gradle文件,无法正常工作
// Apply the java-library plugin to add support for Java Library
apply plugin: 'java'
apply plugin: 'war'
apply plugin: 'eclipse'
configurations {
provided
}
// In this section you declare where to find the dependencies of your project
repositories {
// Use jcenter for resolving your dependencies.
// You can declare any Maven/Ivy/file repository here.
mavenCentral()
}
dependencies {
// This dependency is exported to consumers, that is to say found on their compile classpath.
compile group: 'org.springframework.boot', name: 'spring-boot-starter-web', version: '1.5.2.RELEASE'
compile group: 'org.apache.tiles', name: 'tiles-jsp', version: '3.0.7'
provided group: 'javax.servlet', name: 'jstl', version: '1.2'
//compile group: 'org.apache.tiles', name: 'tiles-jsp', version: '3.0.7'
provided 'org.springframework.boot:spring-boot-starter-tomcat:1.5.2.RELEASE'
provided 'org.apache.tomcat.embed:tomcat-embed-jasper'
}
sourceSets {
main.compileClasspath += configurations.provided
//test.compileClasspath += configurations.provided
//test.runtimeClasspath += configurations.provided
}
eclipse.classpath.plusConfigurations += [configurations.provided]
工作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>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.5.2.RELEASE</version>
</parent>
<version>1.0</version>
<packaging>war</packaging>
<name>spring-boot-web-mvc</name>
<description>
Configure spring boot starter project for Web MVC as a WAR file, still self executing.
</description>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<start-class>com.mvmlabs.springboot.Application</start-class>
<java.version>1.7</java.version>
<main.basedir>${basedir}/../..</main.basedir>
<m2eclipse.wtp.contextRoot>/</m2eclipse.wtp.contextRoot>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>jstl</artifactId>
</dependency>
<!-- Added to allow configuration as a web MVC, built as a WAR file (still
executable) -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.apache.tomcat.embed</groupId>
<artifactId>tomcat-embed-jasper</artifactId>
<scope>provided</scope>
</dependency>
<!-- Add Apache Tiles into the mix -->
<dependency>
<groupId>org.apache.tiles</groupId>
<artifactId>tiles-jsp</artifactId>
<version>3.0.4</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
<groupId>idp</groupId>
<artifactId>com.proginators.idp</artifactId>
</project>
非常感谢任何帮助或建议。
答案 0 :(得分:0)
使用gradle项目时遇到了同样的问题。
只需添加以下依赖项
即可providedRuntime'org.apache.tomcat.embed:tomcat-embed-jasper'
2017-11-29 11:44:08.302 INFO 5760 --- [nio-8081-exec-1] o.a.c.c.C. [Tomcat]。[localhost]。[/]:初始化Spring FrameworkServlet'dispatcherServlet' 2017-11-29 11:44:08.302 INFO 5760 --- [nio-8081-exec-1] o.s.web.servlet.DispatcherServlet:FrameworkServlet'dispatcherServlet':初始化已启动 2017-11-29 11:44:08.323 INFO 5760 --- [nio-8081-exec-1] o.s.web.servlet.DispatcherServlet:FrameworkServlet'dispatcherServlet':初始化完成时间为21毫秒 2017-11-29 11:47:52.678 WARN 5760 --- [nio-8081-exec-1] osweb.servlet.PageNotFound:找不到带URI的HTTP请求的映射[/ WEB-INF / jsp / layout / basic名为“dispatcherServlet”的DispatcherServlet中的.jsp]