java - OpenJDK 11.0.2 的 Spring Boot 2.0 请求映射问题
问题描述
我面临的问题是我无法在点击 URL -> http://localhost:9293/hello时得到任何响应
当我尝试测试这个极简功能时,没有任何问题、错误或任何日志,但没有运气。欢迎任何建议或线索!
如果您需要有关该问题的任何进一步信息,请告诉我!
春季版:2.1.5.RELEASE
OpenJDK 版本:11.0.2
应用程序属性
server.port=9293
spring.mvc.servlet.path=/
server.error.whitelabel.enabled=false
HelloWorldController.java 包 com.sample.springboot.jwt.controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
@RestController
public class HelloWorldController {
@RequestMapping({ "/hello" })
public String firstPage() {
System.out.println("Hello World");
return "Hello World";
}
}
我的主类,SpringBootJwtApplication 包com.sample.springboot.jwt.demo;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
public class SpringBootJwtApplication {
public static void main(String[] args) {
SpringApplication.run(SpringBootJwtApplication.class, args);
System.out.println("From the main() method...");
}
}
这是我的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>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.1.5.RELEASE</version>
<relativePath /> <!-- lookup parent from repository -->
</parent>
<groupId>com.sample.springboot.rest.jwt.app</groupId>
<artifactId>Spring-Boot-JWT</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>Spring-Boot-JWT</name>
<description>Demo project for Spring Boot using HTTP GET, POST. Securing the application with Spring Boot Security plus JWT</description>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>1.11</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
<!-- version>1.4.0.RELEASE</version -->
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
<repositories>
<repository>
<id>spring-snapshots</id>
<name>Spring Snapshots</name>
<url>https://repo.spring.io/snapshot</url>
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
<repository>
<id>spring-milestones</id>
<name>Spring Milestones</name>
<url>https://repo.spring.io/milestone</url>
<snapshots>
<enabled>false</enabled>
</snapshots>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<id>spring-snapshots</id>
<name>Spring Snapshots</name>
<url>https://repo.spring.io/snapshot</url>
<snapshots>
<enabled>true</enabled>
</snapshots>
</pluginRepository>
<pluginRepository>
<id>spring-milestones</id>
<name>Spring Milestones</name>
<url>https://repo.spring.io/milestone</url>
<snapshots>
<enabled>false</enabled>
</snapshots>
</pluginRepository>
</pluginRepositories>
</project>
解决方案
你可以尝试更改spring.mvc.servlet.path
为server.servlet.context-path
.
检查此链接以了解更改
更新
根据您的项目结构,应用程序类不会扫描控制器。因此,您可以将 Application 移动到com.sample.springboot
package 。
推荐阅读
- amazon-web-services - 如何将弹性 ip 分配给现有的 AWS 应用程序负载均衡器?
- android - 如何从我的 webview 应用程序(如 Instagram 等)打开其他应用程序?
- node.js - 一个 API 调用 vs 多个
- android - 如何从文档文件路径中获取内容 Uri?
- javascript - 转换 JavaScript 对象 - JavaScript
- excel - 为 Excel 工作表制作自动排序宏
- android - 如何使用带有 RxSupport 的新 Paging 库 3 实现 Paging 3 的 ItemKeyedDataSource,如 RxPagingSource
- javascript - 如何在 React js 中重置 img 标签?
- android - 使用多个 ViewHolder 时 RecyclerView 不显示最后一项
- amazon-web-services - 如何将 PUBLIC aws sftp 服务器转换为使用 terraform 托管的 VPC