I am developing a spring boot/postgres application. Here's the project structure.
src/main/java
com.test.app
com.test.app.controller
com.test.app.model
com.test.app.repository
src/test/java
com.test.app
Eclipse threw a compilation error saying that "no qualifying bean of type ....repository". I had to include below annotation in the main class. What is wrong here?
@ComponentScan(basePackages = {"com.test.app.repository.AppRepository"})
Also, the mapping doesn't work for me. I have below annotations in the controller class.
@RestController
@RequestMapping("/api")
It's also Autowired repository class. http://127.0.0.1:8080/api shows whitelabel error page. Any pointers?
@RestController
@RequestMapping("/api")
public class AppController {
@Autowired
AppRepository appRepository;
@PostMapping("/order")
public ResponseEntity<AppEntity> createOrder(@RequestBody AppEntity order) {
@GetMapping("/orders")
public ResponseEntity<List<AppEntity>> getAllOrder(@RequestParam(required = false) String name) {
@GetMapping("/order/{id}")
public ResponseEntity<AppEntity> getOrderById(@PathVariable("id") long id) {
Repository class
@Repository
public interface AppRepository extends JpaRepository<AppEntity, Long>{
List<AppEntity> findByName(String name);
}
com.test.app.repository.AppRepositoryisn't a package, it's a class inside a package. (Additionally, you're probably looking for@EnableJpaRepositoriesif you have to specify a repository base, as repository interfaces aren't beans but rather instructions to generate beans at runtime.) - chrylis -cautiouslyoptimistic-