spring-boot - Springboot:控制器类没有被触发
问题描述
出于学习目的,我从 Eclipse 中的一个简单的 Spring Boot 应用程序开始。我能够在 http://localhost:8080 成功运行它。接下来我添加了一个控制器。但我看到控制器永远不会被触发。任何帮助将不胜感激。我用来访问我的控制器的 URL 是:http://localhost:8080/conference/greeting
我的项目结构:
pom.xml 依赖项:
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
源代码:
@SpringBootApplication
public class ConferenceApplication extends SpringBootServletInitializer {
public static void main(String[] args) {
SpringApplication.run(ConferenceApplication.class, args);
}
}
@Controller
public class GreetingController {
@GetMapping("greeting")
public String greeting (Map<String, Object> model) {
model.put("message", "Hello Lok");
return "greeting";
}
}
应用程序属性
spring.mvc.view.prefix=/WEB-INF/jsp/
spring.mvc.view.suffix=.jsp
问候.jsp:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Greeting</title>
</head>
<body>
<h1>${message}</h1>
</body>
</html>
解决方案
在 application.properties 中设置server.servlet.context-path=/conference
或放控制器类注解@RequestMapping("conference")
推荐阅读
- php - Laravel 政策不断允许用户
- webhooks - 如何在结帐页面显示自定义运费
- ios - (Swift)告诉我无法查询项目的原因
- java - 警告:已解决 [org.springframework.web.HttpMediaTypeNotSupportedException:不支持内容类型“应用程序/json”]
- r - 无法从 Github 安装“Velocyto.R”
- python - Pandas:合并和比较数据框
- sql - 将列(字段)中的所有值(以英尺为单位)转换为数据集的度量
- reactjs - React:如何使用 Hooks 一次将所有状态传递给子组件?
- mysql - 有没有办法在 Laravel 6 中从 Postman(API) 上传多张图片
- c++ - 使用带有 zmq 的计时器