0

Hi I'm learning SpringBoot and I'm trying to make a simple Microservice using Postgresql and SpringBoot, when I make a request (GET in this case) from Insomnia I get this response body:

{
  "timestamp": "2023-08-22T16:25:43.756+00:00",
  "status": 404,
  "error": "Not Found",
  "message": "No message available",
  "path": "/postgres/all"
}

This is my method:

@Override
public List<Person> selectAll() {
    String query = "SELECT * FROM PERSON";
    return jdbcTemplate.query(query, new BeanPropertyRowMapper<>(Person.class));
}

This is my controller:

@RestController
@RequestMapping("/postgres")
public class PersonController {

    private AppService appService;


    @GetMapping(value = ("/all"), produces = {MediaType.APPLICATION_JSON_VALUE})
    public ResponseEntity<List<Person>> selectAll() {
        return new ResponseEntity<>(appService.selectAll(), HttpStatus.OK);
    }

    @PostMapping(value = ("/ins"), produces = {MediaType.APPLICATION_JSON_VALUE})
    public ResponseEntity<Person> insert(@RequestBody Person person) throws ClassNotFoundException {
        return new ResponseEntity<>(appService.insert(person), HttpStatus.OK);
    }
}

This is my connection:

@Configuration
public class Connect {
    @Value("postgres")
    String username;

    @Value("postgres")
    String password;

    @Value("jdbc:postgresql://localhost:5432/postgres")
    String url;

    public DataSource postgresConfig() {
        DriverManagerDataSource dataSource = new DriverManagerDataSource();
        dataSource.setUsername(username);
        dataSource.setPassword(password);
        dataSource.setUrl(url);

        return dataSource;
    }
}

EDIT This is my request using insomnia

enter image description here

0 Answers0