Friday, October 13, 2017

Spring Boot: the client fails to find the service returning 404.


>PROBLEM

The application starts successfully, but the client fails to access the service getting 404.

Controller's original code:
@RestController
@RequestMapping("/api")
@CrossOrigin("*")
public class HelloController {

    @Autowired
    IHelloRepository helloRepository;

    @GetMapping("/hellos")
    public List getAllHellos() {
        Sort sortByCreatedAtDesc = new Sort(Sort.Direction.DESC, "createdAt");
        return helloRepository.findAll(sortByCreatedAtDesc);
    }



>SOLUTION

***WRONG:     @GetMapping("/hellos")
***RIGHT:        @GetMapping("/hellos/")

@RestController
@RequestMapping("/api")
@CrossOrigin("*")
public class HelloController {

    @Autowired
    IHelloRepository helloRepository;

    @GetMapping("/hellos/")
    public List getAllHellos() {
        Sort sortByCreatedAtDesc = new Sort(Sort.Direction.DESC, "createdAt");
        return helloRepository.findAll(sortByCreatedAtDesc);
    }


>ENV

Java 1.8
SpringBoot 1.5.6

No comments:

Post a Comment

eclipse: java: SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder" or Exception in thread "main" java.lang.NoClassDefFoundError: org/slf4j/impl/StaticLoggerBinder

  >PROBLEM Using Eclipse, you try to run a simple logging test using "org.slf4j.Logger" like the sample below: package Test; im...