1

Situation

I have a modular Spring Boot application, which currently consists of the applicationProject, that includes the first sub module moduleA as dependencies (maven).

This allows the applicationProject to be a single java class, which initializes the Spring application, where as the actual functionality is delivered by the modules defined as dependencies.

All my modules and also the applicationProject are underneath the base package com.mycompany.myproduct.

My applicationProject java class looks as simple as this:

@SpringBootApplication(scanBasePackages ="com.mycompany.myproduct")
public class MyApp {

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

In my moduleA project I do not use any @ComponentScan annotation or extension of it.

Issue

When I start my application this way I get a UnsatisfiedDependencyException, while Spring tries to initialize a bean ServiceA that it self depends on another bean RepositoryA both defined in moduleA.

This makes me assume that Spring does detect the beans, but does not build the dependency tree correctly resulting in a bad bean instantiation order.

When adding

@EnableJpaRepositories(basePackages = "com.mycompany.myproduct")
@EntityScan(basePackages = "com.mycompany.myproduct")

to the initializing MyApp class, the spring loads the beans correctly and the application runs successfully.

To me this seems like a workaround or why would I need to declare the base package again for @EnableJpaRepositories and @EntityScan when I already declare the base package in the SpringBootApplication annotation?

Or is this even a flaw due the independent spring projects?

Herr Derb
  • 4,977
  • 5
  • 34
  • 62
  • how does your Repository class look like . DO you have `@Repository` annotation – pvpkiran Mar 14 '18 at 14:46
  • Yes, my repository class is configured the correct way with the `@Repository` annotation and also works perfectly on test inside `moduleA`. – Herr Derb Mar 14 '18 at 14:48

0 Answers0