我已经配置了一个 Spring Boot 应用程序,但是在启动该应用程序时,我收到如下映射错误
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
.我已经浏览了下面的链接并将我的控制器更新为包含主类的根包的一部分。 此应用程序没有 /error 的显式映射
我为我的应用程序使用了下面提到的配置/代码:
构建.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')
}
票务控制器.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");
}
}
应用程序属性
spring.mvc.view.prefix=/WEB-INF/jsp/
spring.mvc.view.suffix=.jsp
jsp路径
src/main/webapp/WEB-INF/jsp/view.jsp