gpt4 book ai didi

java - 如何解决: "There was an unexpected error (type=Not Found, status=404)"

转载 作者:行者123 更新时间:2023-12-01 21:22:06 26 4
gpt4 key购买 nike

我正在使用此 Controller 启动 Spring Boot 应用程序

@RestController
@RequestMapping({"/api"})
public class ProduitImmobilierController {

Logger logger = LoggerFactory.getLogger(ProduitImmobilierController.class);

@Autowired
private ProduitImmobilierService produitImmobilierService;

@RequestMapping(value = "/produitimmobilier/all/{pageSize}/{page}",
method = RequestMethod.GET,
produces = {"text/plain;charset=UTF-8", MediaType.APPLICATION_JSON_VALUE},
consumes = {"text/plain;charset=UTF-8", MediaType.APPLICATION_JSON_VALUE})
public @ResponseBody List<ProduitImmobilierDTO> findAll(@PathVariable("pageSize") int pageSize, @PathVariable("page") int page){
logger.info("CONTROLLER PRODUITIMMOBILIERSERVICE CA PASSE");
return produitImmobilierService.findAll(pageSize, page);
}

我检查应用程序是否正在监听端口 8080我尝试在 Firefox 上使用此 URL 访问此 Controller

http://localhost:8080/api/produitimmobilier/all/5/1

我收到此错误

Whitelabel Error Page

This application has no explicit mapping for /error, so you are seeing this as a fallback.
Wed Nov 13 20:48:53 CET 2019
There was an unexpected error (type=Not Found, status=404).
No message available

这是项目树

enter image description here

如何解决?

我添加了pom.xml

<?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>2.1.9.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.example</groupId>
<artifactId>demoImmobilierBack</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>demoImmobilierBack</name>
<description>Demo project for Spring Boot</description>

<properties>
<java.version>1.8</java.version>
</properties>

<dependencies>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>8.0.17</version>
</dependency>
<dependency>
<groupId>org.hibernate.hql</groupId>
<artifactId>hibernate-hql-parser</artifactId>
<version>1.5.0.Final</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<!-- https://mvnrepository.com/artifact/javax.persistence/javax.persistence-api -->
<dependency>
<groupId>javax.persistence</groupId>
<artifactId>javax.persistence-api</artifactId>
<version>2.2</version>
</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>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
<scope>test</scope>
<!-- <version>1.4.194</version> -->
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.18.10</version>
<scope>provided</scope>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>

<repositories>
<repository>
<id>spring-releases</id>
<name>Spring Releases</name>
<url>https://repo.spring.io/libs-release</url>
</repository>
<repository>
<id>org.jboss.repository.releases</id>
<name>JBoss Maven Release Repository</name>
<url>https://repository.jboss.org/nexus/content/repositories/releases</url>
</repository>
</repositories>

<pluginRepositories>
<pluginRepository>
<id>spring-releases</id>
<name>Spring Releases</name>
<url>https://repo.spring.io/libs-release</url>
</pluginRepository>
</pluginRepositories>

</project>

当我使用以下网址点击应用程序时:http://localhost:8080/api/produitimmobilier/all/5/1

2019-11-14 12:20:58.770  INFO 2998 --- [nio-8080-exec-1] o.a.c.c.C.[Tomcat].[localhost].[/]       : Initializing Spring DispatcherServlet 'dispatcherServlet'
2019-11-14 12:20:58.770 INFO 2998 --- [nio-8080-exec-1] o.s.web.servlet.DispatcherServlet : Initializing Servlet 'dispatcherServlet'
2019-11-14 12:20:58.787 INFO 2998 --- [nio-8080-exec-1] o.s.web.servlet.DispatcherServlet : Completed initialization in 17 ms

最佳答案

尝试:

@RestController
@RequestMapping("/api")
public class ProduitImmobilierController {
...
...
...
}

关于java - 如何解决: "There was an unexpected error (type=Not Found, status=404)",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58844957/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com