我有一个spring-boot项目和API-REST。当我用localhost:8080 / clientes命中它时,它将返回一个包含所有客户端数据的json。但是,当我重新启动服务器或进行重新部署时,我仅获得客户端数量,但没有数据,则所有内容均为空。
因此,从根本上讲,在我们更改某些内容或重新部署之前,它一直有效。
这是在DigitalOcean小滴上运行的。 Ubuntu。
package com.gestion.backend.controllers;
import java.util.List;
import com.gestion.backend.entidades.Cliente;
import com.gestion.backend.services.ClientesService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.security.access.prepost.PreAuthorize;
@CrossOrigin(origins = "http://localhost:4200", maxAge = 3600)
@RestController
public class ClientesController {
@Autowired
ClientesService clientesService;
// Traigo todos los clientes
@GetMapping("/clientes")
@PreAuthorize("hasRole('USER') or hasRole('ADMIN') or hasRole('PM')")
public List<Cliente> getCLientes(){
return clientesService.getClientes();
}
// Traigo un usuario especifico
@GetMapping("/clientes/{id}")
@PreAuthorize("hasRole('USER') or hasRole('ADMIN') or hasRole('PM')")
public Cliente getCliente(@PathVariable Long id){
Cliente data = clientesService.getClienteById(id);
System.out.println("List<Cliente>: " + data);
return clientesService.getClienteById(id);
}
@PostMapping("/clientes")
Cliente newEmployee(@RequestBody Cliente nuevoCliente) {
return clientesService.saveCliente(nuevoCliente);
}
}
应用程序属性:
spring:
datasource:
url: jdbc:mysql://localhost:3306/gestion?useUnicode=true&useJDBCCompliantTimezoneShift=true&useLegacyDatetimeCode=false&serverTimezone=UTC&allowPublicKeyRetrieval=true&useSSL=false
username: root
password: test
driver-class-name : com.mysql.jdbc.Driver
jpa:
show-sql: true
hibernate:
ddl-auto: update
naming:
physical-strategy: org.hibernate.boot.model.naming.PhysicalNamingStrategyStandardImpl
database-platform: org.hibernate.dialect.MySQL5Dialect
我希望客户端列表包含所有数据,但只会得到一个空响应(所有字段均为空)