java白标签错误页应用程序没有/Error的显式映射
我已经配置了一个spring启动应用程序,但在启动应用程序时,我发现映射错误如下
Whitelabel Error Page
This application has no explicit mapping for /error, so you are seeing this as a fallback.
Mon Dec 24 12:46:27 IST 2018
There was an unexpected error (type=Not Found, status=404).
No message available
。我已经浏览了下面的链接,并将我的控制器更新为包含主类的根包的一部分。 This application has no explicit mapping for /error
我在我的应用程序中使用了以下提到的配置/代码:
build.gradle
buildscript {
ext {
springBootVersion = '2.1.1.RELEASE'
}
repositories {
mavenCentral()
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
}
}
apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'org.springframework.boot'
apply plugin: 'io.spring.dependency-management'
group = 'com.ticket'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = 1.8
repositories {
mavenCentral()
}
dependencies {
implementation('org.springframework.boot:spring-boot-starter-data-jpa')
implementation('javax.servlet:jstl')
implementation('org.springframework.boot:spring-boot-starter-web')
runtimeOnly('com.h2database:h2')
testImplementation('org.springframework.boot:spring-boot-starter-test')
}
TicketController.java
package com.ticket.controller;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.ModelAndView;
@RestController
public class TicketController {
static Logger log = LogManager.getLogger();
@RequestMapping(value = "/", method = RequestMethod.GET)
public ModelAndView homeScreen(ModelMap model) {
return new ModelAndView("view");
}
}
application.properties
spring.mvc.view.prefix=/WEB-INF/jsp/
spring.mvc.view.suffix=.jsp
Jsp path
src/main/webapp/WEB-INF/jsp/view.jsp
# 1 楼答案
答案很简单,如果您使用的是thymeleaf,请在pom中添加以下行。xml:
仅此而已,您必须将视图放入
src / main / resources/templates
的模板包中如果您对视图使用jsp文件,则上述操作不起作用,必须向应用程序中添加以下行。属性文件:
前面的几行表示驱动程序将在其中查找视图的文件夹,它们也必须与该文件夹结构一起存在
还有你的pom。以下几行:
***
***
总之,spring boot表明它找不到请求的资源,但根据上面已经描述的,必须解决这个问题
# 2 楼答案
默认情况下,Spring boot不提供为视图层解析Jsp的功能。 在属性下方添加到
解决了这个问题