Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why are my Spring Data repositories not found if moved into another package of a Spring Boot application?

I created a new project in Eclipse from these helpful spring examples (Import Getting Started Content). It is called "gs-accessing-data-rest-complete"

Reference and full Code can be found: spring-guides/gs-accessing-data-rest

When leaving the example unchanged, except using WAR instead of JAR packaging, everything works well. When calling $ curl http://localhost:8080/, I'll get an exposure of usable resources.

$ curl http://localhost:8080/
{
  "_links" : {
    "people" : {
      "href" : "http://localhost:8080/name{?page,size,sort}",
      "templated" : true
    },
"profile" : {
  "href" : "http://localhost:8080/alps"
    }
  }

But when moving the PersonRepository into another package, e.g. myRepos via Eclipse's Refactor-->Move command, a resource is not accessible anymore.

The response from curl is then:

$ curl http://localhost:8080/
{
  "_links" : {
    "profile" : {
      "href" : "http://localhost:8080/alps"
    }
  }
}

As far as I understood, Spring scans for Repositories automatically. Because the main class uses @SpringBootApplication annotation, everything should be found by spring itself.

What am I missing? Do I have to add some special XML configuration file or add another Configuration Class somewhere? Or do I have to update application.properties in order to sth.?

Perhaps somebody has some useful experiences, she or he might share with me. Thank you.

like image 592
Semo Avatar asked Dec 01 '25 16:12

Semo


1 Answers

Try specifying the base package to use when scanning for repositories by using this annotation on your config class: @EnableJpaRepositories(basePackages = "your.base.repository.package")

like image 160
adam p Avatar answered Dec 03 '25 05:12

adam p