有一个类似于这样的示例Spring Boot(版本3.0.3)Web应用程序:
pom.xml的一部分
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>3.0.3</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.example</groupId>
<artifactId>demo</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>demo</name>
<description>Demo project for Spring Boot</description>
<properties>
<start-class>matin.example.demo.DemoApplication</start-class>
<java.version>17</java.version>
</properties>
<dependencies>
<!--<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>-->
<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>
</dependencies>
并且
package matin.example.demo;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.ComponentScan;
@SpringBootApplication
public class DemoApplication {
public static void main(String[] args) {
SpringApplication.run(DemoApplication.class, args);
}
}
并且
package matin.example.demo.api;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
@RestController
public class FController {
@GetMapping(value = "/re")
public String viewHomePage(/*Model model, HttpServletRequest request*/) {
/*request.getSession().setAttribute("onlineUser", request.getSession().getAttribute("onlineUser") == null ? 1 : Integer.valueOf(request.getSession().getAttribute("onlineUser").toString()) + 1);
System.out.println(request.getSession().getAttribute("onlineUser") + "<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<");*/
return "index";
}
}
当我请求localhost:8080/re
时,我收到了404未找到的错误,但是当我将Spring Boot的版本降级为2.7.7时,它成功地工作了。
在3.x版本中发生了什么变化,我该怎么做?