我面临的问题是我无法在点击URL-> http://localhost:9293/hello时获得任何响应
我尝试测试此简约功能时没有问题,没有错误或任何日志,但是没有运气。任何建议或线索都是最欢迎的!
如果您需要进一步的信息,请告诉我!
春季版:2.1.5。发布
OpenJDK版本:11.0.2
application.properties
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>
EDIT-1:添加我的项目结构->
最佳答案
您可以尝试将spring.mvc.servlet.path
更改为server.servlet.context-path
吗?
检查此链接的change
更新
根据您的项目结构,控制器不会按应用程序类进行扫描。因此,您可以将Application移到com.sample.springboot
包中。