gpt4 book ai didi

java - Spring Boot |本地主机 : 8080 404 error page displayed

转载 作者:行者123 更新时间:2023-11-30 06:06:48 24 4
gpt4 key购买 nike

我创建了一个 Spring Boot Maven 项目,但是我的 RequestMapping 以及 localhost:8080 返回了 404 错误页面。我认为问题在于我的包是如何设置的,但我已经尝试了多个问题的解决方案,但我仍然无法绕过错误页面。你们能指出我如何解决这个问题的正确方向吗?也许我需要在主类上方添加 Component 注释?但是我试过这个解决方案,错误仍然存​​在。

这是我的包结构:

 /src/main/java
ControllerLayer
UsersController.java
DataAccessLayer
UsersDAL.java
ServiceLayer
UsersService.java
Main
Main.java

主要.java:

  @SpringBootApplication(scanBasePackages = { 
"/src/main/java/ControllerLayer", "/src/main/java/DataAccessLayer",
"/src/main/java/ServiceLayer" })
public class Main {

public static void main(String[] args) {
SpringApplication.run(Main.class, args);
}
}

用户 Controller .java:

 import Entities.Users;
import ServiceLayer.UsersService;

@RestController
@RequestMapping("/users")
public class UsersController {

@Autowired
private UsersService usersService;

@RequestMapping(value =
"/create/{userId}/{userPassword}/{userAge}/{userEmail}"
+ "/{userFirstName}/{userlastName}", method =
RequestMethod.POST)

public void createUser(@PathVariable("userId")String userId,
@PathVariable("userPassword")String userPassword,
@PathVariable("userAge")int userAge,
@PathVariable("userEmail")String userEmail,
@PathVariable("userFirstName")String userFirstName,
@PathVariable("userLastName")String userLastName) {

usersService.createUser(new Users(userId, userPassword,
userAge, userEmail, userFirstName, userLastName));
}
}

用户服务.java

 import DataAccessLayer.UsersDAL;
import Entities.Users;

@Service
public class UsersService {

@Autowired
private UsersDAL usersDAL;

public void createUser(Users user) {
usersDAL.createUser(user);
}
}

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>

<groupId>xProjectAlpha</groupId>
<artifactId>org.htech.xProjectAlpha</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>

<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.5.2.RELEASE</version>
</parent>

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

<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>

<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-core</artifactId>
<version>5.2.9.Final</version><!--$NO-MVN-MAN-VER$-->
</dependency>
</dependencies>

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

</project>

最佳答案

发送请求后,应返回响应。在您的情况下,您没有随响应发送任何内容,这就是您收到 404 错误(未找到页面)的原因。

关于java - Spring Boot |本地主机 : 8080 404 error page displayed,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43399196/

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