0
votes

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);

}
1
It's impossible to understand what and where is your problem exactly, as there is no code, nor any good hint. Please, read how to ask a question, and provide minima reproducible example. - Giorgi Tsiklauri
Do you have your main class (with @SpringBootApplicatoin) under com.test.app package? - Kumar V
com.test.app.repository.AppRepository isn't a package, it's a class inside a package. (Additionally, you're probably looking for @EnableJpaRepositories if you have to specify a repository base, as repository interfaces aren't beans but rather instructions to generate beans at runtime.) - chrylis -cautiouslyoptimistic-
yes, I do have the main class under com.test.app. - Srisfti
I doubt it is a compilation error but rather an error from the spring checks. Next to that isn't it just a false positive from eclipse? Have you simply tried running the application (Regardless of the error). - M. Deinum

1 Answers

0
votes

Check if any context path "server.servlet.contextPath=/" set in the application properties file.