Send console values by REST API

0

I have a project in Spring Boot that connects to Postgresql and sends the values by console , what I'm looking for is to be able to send it through JSON in a REST query, but I do not know which part to change the project. That's what I'm looking for to generate:

{ 
    "depositarios": {
        "correo": "correo",
        "nombre": "nombre",
        "numTel": "numTel",
        "pApellido": "pApellido",
        "SApellido": "sAellido"
    }
}

This is my main class :

@SpringBootApplication

@ComponentScan("com.abner.springpostgresql.service.impl, com.abner.springpostgresql.dao.imp")
public class SpringPostgresqlApplication {

    public static void main(String[] args) {
        ApplicationContext context= SpringApplication.run(SpringPostgresqlApplication.class, args);
        depoService depoService =context.getBean(depoService.class);
        depoService.loadAllDepo();
    }
}

Only when I run it tomcat sends me an error message 404. Here is my complete project .

Update: This is my console log

    
asked by Abner Coronado 09.08.2017 в 23:23
source

2 answers

0

The main class is misconfigured. When you use @ComponentScan you must be careful not to leave out any package that contains classes to be injected. If you remove the @ComponentScan parameters for sure your service will work.

 @SpringBootApplication
    @ComponentScan
    public class SpringPostgresqlApplication {
    ...

The error is as follows: These are indicating to spring that you only look for the following packages:

  • com.abner.springpostgresql.service.impl
  • com.abner.springpostgresql.dao.imp

But the controller is in the package:

  • com.abner.springpostgresql.controller

In this link you can be very helpful:

Structuring your code

    
answered by 24.12.2017 / 06:41
source
1

But depserviceImpl is not a controller, it's a service

You need to create a class that is a controller

@RestController
public class DepoController {

@Autowired depoService mydepoService;

    @RequestMapping("enviar")
    public String enviar() {
        mydepoService.loadAllDepo();
        return ....
    }

By the way, use the java naming convention and change depoService to DepoService

    
answered by 09.08.2017 в 23:35