我看到白色标签错误页面,状态为404,而不是字符串"所有电影!" 我在http://localhost:8080/api/v1/movies上发出GET请求
我的控制器
package pl.krywion.movies.app;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
@RestController
@RequestMapping("/api/v1/movies")
public class MovieController {
@GetMapping
public String allMovies() {
return "All Movies!";
}
}
我的主要班级
package pl.krywion.movies;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
public class MoviesApplication {
public static void main(String[] args) {
SpringApplication.run(MoviesApplication.class, args);
}
}
my pom.xml file
<?xml version="1.0" encoding="UTF-8"?>
<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 https://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>3.0.3</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>pl.krywion</groupId>
<artifactId>movies</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>movies</name>
<description>movies</description>
<properties>
<java.version>17</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-mongodb</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<scope>runtime</scope>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>me.paulschwarz</groupId>
<artifactId>spring-dotenv</artifactId>
<version>2.5.4</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<excludes>
<exclude>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
</exclude>
</excludes>
</configuration>
</plugin>
</plugins>
</build>
</project>
我的应用程序.属性
spring.data.mongodb.database=${env.MONGO_DATABSE}
spring.data.mongodb.uri=mongodb+srv://${env.MONGO_USER}:${env.MONGO_PASSWORD}@${env.MONGO_CLUSTER}
我的日志(log)在调试后运行并发出请求
2023-02-26T19:45:33.142+01:00 DEBUG 8118 --- [nio-8080-exec-2] o.s.web.servlet.DispatcherServlet : Detected StandardServletMultipartResolver
2023-02-26T19:45:33.142+01:00 DEBUG 8118 --- [nio-8080-exec-2] o.s.web.servlet.DispatcherServlet : Detected AcceptHeaderLocaleResolver
2023-02-26T19:45:33.142+01:00 DEBUG 8118 --- [nio-8080-exec-2] o.s.web.servlet.DispatcherServlet : Detected FixedThemeResolver
2023-02-26T19:45:33.142+01:00 DEBUG 8118 --- [nio-8080-exec-2] o.s.web.servlet.DispatcherServlet : Detected org.springframework.web.servlet.view.DefaultRequestToViewNameTranslator@26512192
2023-02-26T19:45:33.142+01:00 DEBUG 8118 --- [nio-8080-exec-2] o.s.web.servlet.DispatcherServlet : Detected org.springframework.web.servlet.support.SessionFlashMapManager@1c16475
2023-02-26T19:45:33.143+01:00 DEBUG 8118 --- [nio-8080-exec-2] o.s.web.servlet.DispatcherServlet : enableLoggingRequestDetails='false': request parameters and headers will be masked to prevent unsafe logging of potentially sensitive data
2023-02-26T19:45:33.143+01:00 INFO 8118 --- [nio-8080-exec-2] o.s.web.servlet.DispatcherServlet : Completed initialization in 2 ms
2023-02-26T19:45:33.147+01:00 DEBUG 8118 --- [nio-8080-exec-2] o.s.web.servlet.DispatcherServlet : GET "/api/v1/movies", parameters={}
2023-02-26T19:45:33.152+01:00 DEBUG 8118 --- [nio-8080-exec-2] o.s.w.s.handler.SimpleUrlHandlerMapping : Mapped to ResourceHttpRequestHandler [classpath [META-INF/resources/], classpath [resources/], classpath [static/], classpath [public/], ServletContext [/]]
2023-02-26T19:45:33.157+01:00 DEBUG 8118 --- [nio-8080-exec-2] o.s.w.s.r.ResourceHttpRequestHandler : Resource not found
2023-02-26T19:45:33.157+01:00 DEBUG 8118 --- [nio-8080-exec-2] o.s.web.servlet.DispatcherServlet : Completed 404 NOT_FOUND
2023-02-26T19:45:33.161+01:00 DEBUG 8118 --- [nio-8080-exec-2] o.s.web.servlet.DispatcherServlet : "ERROR" dispatch for GET "/error", parameters={}
2023-02-26T19:45:33.162+01:00 DEBUG 8118 --- [nio-8080-exec-2] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped to org.springframework.boot.autoconfigure.web.servlet.error.BasicErrorController#error(HttpServletRequest)
2023-02-26T19:45:33.179+01:00 DEBUG 8118 --- [nio-8080-exec-2] o.s.w.s.m.m.a.HttpEntityMethodProcessor : Using 'application/json', given [*/*] and supported [application/json, application/*+json]
2023-02-26T19:45:33.179+01:00 DEBUG 8118 --- [nio-8080-exec-2] o.s.w.s.m.m.a.HttpEntityMethodProcessor : Writing [{timestamp=Sun Feb 26 19:45:33 CET 2023, status=404, error=Not Found, message=No message available, (truncated)...]
2023-02-26T19:45:33.197+01:00 DEBUG 8118 --- [nio-8080-exec-2] o.s.web.servlet.DispatcherServlet : Exiting from "ERROR" dispatch, status 404
我不知道怎么修,我是春天的初学者
我try 使用@ComponentScan注释,并将MovieApplication Java类移动到上面的包中,或者将其移动到与控制器相同的包中