【发布时间】:2021-10-18 07:17:25
【问题描述】:
我正在创建一个项目 Java Springboot,其中 postgreSql 连接到 AWS
一个错误: 白标错误页面 此应用程序没有配置错误视图,因此您将其视为后备。
2021 年 8 月 13 日星期五 10:46:24 UTC [a93e3797-1] 出现意外错误(类型=未找到,状态=404)。
用户控制器:
@RestController
public class UserController {
@Autowired
private userService userService;
private static final String ERROR_MAPPING = "/error";
@PostMapping(path="/employees")
public customers addEmployee(@RequestBody customers employee) {
return userService.save(employee);
}
@GetMapping(path="/employees")
public ResponseEntity<List<customers>> getAllEmployees() {
return ResponseEntity.ok(userService.listAll());
}
}
用户服务:
@Service
public class userService {
@Autowired
private userRepository repo;
public List<customers> listAll(){
return repo.findAll();
}
public customers save(customers u) {
repo.save(u);
return u;
}
}
用户存储库:
@Repository
public interface userRepository extends JpaRepository<customers, Long> {
}
用户模型:
@Entity
@Table(name = "customers")
public class customers {
private int Customer_Id;
private String First_Name;
private String Last_Name;
private int Phone_Number;
public customers(int customer_Id, String first_Name, String last_Name, int phone_Number) {
Customer_Id = customer_Id;
First_Name = first_Name;
Last_Name = last_Name;
Phone_Number = phone_Number;
}
public customers() {
}
public int getCustomer_Id() {
return Customer_Id;
}
public void setCustomer_Id(int customer_Id) {
Customer_Id = customer_Id;
}
public String getFirst_Name() {
return First_Name;
}
public void setFirst_Name(String first_Name) {
First_Name = first_Name;
}
public String getLast_Name() {
return Last_Name;
}
public void setLast_Name(String last_Name) {
Last_Name = last_Name;
}
public int getPhone_Number() {
return Phone_Number;
}
public void setPhone_Number(int phone_Number) {
Phone_Number = phone_Number;
}
}
应用程序:包 com.esdt.user;
@SpringBootApplication
@EntityScan("com.esdt.user.model.*")
@EnableJpaRepositories("com.esdt.user.repository.*")
@ComponentScan(basePackages={ "com.esdt.user.controller.*", "com.esdt.user.service.*" })
public class UserApplication {
public static void main(String[] args) {
SpringApplication.run(UserApplication.class, args);
}
}
属性:
## Spring DATASOURCE (DataSourceAutoConfiguration & DataSourceProperties)
spring.datasource.url=jdbc:postgresql://awswebsite/postgres?allowPublicKeyRetrieval=true&useSSL=false
spring.datasource.username=user
spring.datasource.password=pass
# The SQL dialect makes Hibernate generate better SQL for the chosen database
spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.PostgreSQLDialect
# Hibernate ddl auto (create, create-drop, validate, update)
spring.jpa.hibernate.ddl-auto=create
spring.jpa.hibernate.show-sql=true
【问题讨论】:
-
您点击的网址是什么样的?您复制了错误,但没有说明您是如何触发它的
-
好的,但是您没有主页的映射,而是“/employees”的映射,因此您需要调用 ec2-18-191-138-44.us-east-2.compute。 amazonaws.com:8080/employees
-
我试过 /employees 但同样的错误
-
尝试不使用“:8080”
标签: spring postgresql amazon-web-services spring-boot hibernate