英文:
WhiteLabel error page when making GET request
问题
I get WhiteLabel error page with status 404 instead of String "All Movies!"
我收到了状态码404的WhiteLabel错误页面,而不是字符串"All Movies!"
I am making GET request on http://localhost:8080/api/v1/movies
我正在进行GET请求,访问地址是http://localhost:8080/api/v1/movies
My controller
我的控制器
My main class
我的主类
my pom.xml file
我的pom.xml文件
my application.properties
我的application.properties文件
My logs after Debug run and making a request
在进行调试运行并发出请求后,我的日志如下:
I don't know how to fix it, I am a Spring beginner
我不知道如何修复它,我是一个Spring的初学者
I tried using @ComponentScan annotation, and moving MovieApplication Java class to package above or moving it ot the same package as controller
我尝试使用@ComponentScan注解,并将MovieApplication Java类移动到上面的包或将其移动到与控制器相同的包中。
英文:
I get WhiteLabel error page with status 404 instead of String "All Movies!"
I am making GET request on http://localhost:8080/api/v1/movies
My controller
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!";
}
}
My main class
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>
my application.properties
spring.data.mongodb.database=${env.MONGO_DATABSE}
spring.data.mongodb.uri=mongodb+srv://${env.MONGO_USER}:${env.MONGO_PASSWORD}@${env.MONGO_CLUSTER}
My logs after Debug run and making a request
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
I don't know how to fix it, I am a Spring beginner
I tried using @ComponentScan annotation, and moving MovieApplication Java class to package above or moving it ot the same package as controller
答案1
得分: 1
在Spring 3.0.3中存在组件扫描的问题:https://github.com/spring-projects/spring-boot/issues/34379
问题发生在以.jar
形式运行应用程序时。如果您的项目结构包含在URL中会被编码的字符的目录元素名称,组件扫描将无法按预期工作。
您可以更改应用程序的路径以删除这些字符。或者,您可以降级到3.0.2版本或升级到自2023年3月4日起提供的3.0.4版本。
英文:
There is an issue with component scanning in spring 3.0.3: https://github.com/spring-projects/spring-boot/issues/34379
The issue occurs when running your application not as a .jar
. If your project structure has directory elements whose names contain a characters that would be encoded in a URL, component scanning will not work as expected.
You can change your application's path to remove those characters. Or you downgrade to 3.0.2 or upgrade to 3.0.4, available since March 04, 2023.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论