我面临的问题是,我无法在点击URL时得到任何回应-> http://localhost:9293/hello
在尝试测试此简约功能时没有问题,没有错误或任何日志,但是没有运气。任何建议或线索都是最欢迎的!
如果您需要有关此问题的更多信息,请告诉我!
春季版本: 2.1.5.RELEASE
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>
答案 0 :(得分:1)
您可以尝试将spring.mvc.servlet.path
更改为server.servlet.context-path
吗?
在此链接中查看change
已更新
根据您的项目结构,控制器不会按应用程序类进行扫描。因此,您可以将Application移至com.sample.springboot
包中。
答案 1 :(得分:0)
请修改您的application.properties。
server.port=9293
server.servlet.context-path=/
server.error.whitelabel.enabled=false
提供了错误的上下文属性键
spring.mvc.servlet.path
第二,您必须扩展
org.springframework.boot.web.servlet.support.SpringBootServletInitializer
public class SpringBootJwtApplication extends SpringBootServletInitializer