-3

I have a working JpaRepository as an interface, and a working Restcontroller.

They are two types currently and I like to join them to one!

This is what i have:

@Repository
@RestController("problem")
public interface ProblemsController extends JpaRepository<Problem, Integer> {

  @RequestMapping(value = "all", method = RequestMethod.GET)
  List<Problem> findAll();
}

But when i call http://localhost:8080/application/problem/all I get a 404.

What to do?

Grim
  • 1,938
  • 10
  • 56
  • 123
Peter Rader
  • 237
  • 3
  • 14

2 Answers2

2

You could use this way..but am not get what exactly your are expecting.

import java.util.List;

import org.springframework.data.repository.PagingAndSortingRepository;
import org.springframework.data.repository.query.Param;
import org.springframework.data.rest.core.annotation.RepositoryRestResource;

@RepositoryRestResource(collectionResourceRel = "people", path = "people")
public interface PersonRepository extends PagingAndSortingRepository<Person, Long> {

    List<Person> findByLastName(@Param("name") String name);

}

This is act as a Repositry and REST web service.

if you got an error. You can check UI page is prperly locating this interface or Not

1

Try Adding / to your RequestMapping not at @RestController

 @Repository
 @RestController
 public interface ProblemsController extends JpaRepository<Problem, 
 Integer> {

  @RequestMapping(value = "/problem/all", method = RequestMethod.GET)
  List<Problem> findAll();
 }

Or you can try this:

    @Repository
    @RestController
    @RequestMapping("/problem")
    public interface ProblemsController extends JpaRepository<Problem,
                Integer> {

            @RequestMapping(value = "/all", method = RequestMethod.GET)
            List<Problem> findAll();
     }
mohit sharma
  • 1,050
  • 10
  • 20