1

I have the following maven project structure:

eu.arrowhead
  common
    repository
       -AJpaRepository.class
  orchestrator
    controller
       -AController.class
    OrchestratorApplication
  other_modules...

Where two of the modules are common, and orchestrator. Common is a dependency for the Orchestrator module. The JpaRepositoryClass is annotated with @Repository.

In the controller class I use the constructor autowiring to get a copy of the repository:

private final AJpaRepository serviceRepo;

  @Autowired
  public AController(AJpaRepository serviceRepo){
    this.serviceRepo = serviceRepo;
  }

And finally, in the Application class, I use scanBasePackages, to pick up the components from the common module:

@SpringBootApplication(scanBasePackages = "eu.arrowhead")
public class OrchestratorApplication {

  public static void main(String[] args) {
    SpringApplication.run(OrchestratorApplication.class, args);
  }

}

When I start the application, I get:

Description:

Parameter 0 of constructor in eu.arrowhead.orchestrator.controller.ArrowheadServiceController required a bean of type 'eu.arrowhead.common.repository.ArrowheadServiceRepo' that could not be found.


Action:

Consider defining a bean of type 'eu.arrowhead.common.repository.ArrowheadServiceRepo' in your configuration.

If I use scanBasePackages = {"eu.arrowhead.common"} then the application starts without an error, but I can not reach the endpoint in my controller class (getting the default 404 error). If I write scanBasePackages = {"eu.arrowhead.common", "eu.arrowhead.orchestrator"} it's the same as if only "eu.arrowhead" is there, I get the same error at startup.

Is this how this supposed to work? I highly doubt it.

Depencendies:

  • Common module: starter-data-jpa, starter-json, mysql-connector-java, hibernate-validator
  • Orch module: starter-web, the common module.

I also tried using @ComponentScan, but had the same result. What is the problem? Thanks.

Karol Dowbecki
  • 43,645
  • 9
  • 78
  • 111
logi0517
  • 813
  • 1
  • 13
  • 32

1 Answers1

3

You are missing @EnableJpaRepositories("eu.arrowhead") annotation to enable Spring Data JPA repository scanning.

Karol Dowbecki
  • 43,645
  • 9
  • 78
  • 111
  • So many annotations! I've put this on the application class, now I get "IllegalArgumentException: Not a managed type: class eu.arrowhead.common.dto.entity.ArrowheadService" from the repository init method. This class only has the @Entity annotation on it. I guess using this extra annotation takes away some auto-configuration maybe? – logi0517 Jul 18 '18 at 15:13
  • adding a third, @EntityScan annotation solved this too. When I only had 1 module, these were not needed :( oh well. I kinda fear that later I will find more stuff that's missing, because the auto config is not applied now. – logi0517 Jul 18 '18 at 15:20