Olivier4477
Olivier4477

Reputation: 21

Microservice, module and error compilation: The injection point has the following annotations:

I spent my day trying to understand but I can't understand my problem.

I have 1 spring module (https://spring.io/guides/gs/multi-module/) [I also have JPA in the sub module] and 2 microservices (A and B).

In microservice A, I arrive at @Autowired CountryRepository (which extends from JpaRepository) and which works very well, SpringBootApplication (scanBasePackages = "**") with, I access my data and I can compile.

On microservice B, I did the same thing, I manage to access my data but impossible to compile:

****************************
FAILED TO START APPLICATION
****************************

Description:

Field countryRepository in * required a bean named 'entityManagerFactory' that could not be found.

The injection point has the following annotations:
        - @ org.springframework.beans.factory.annotation.Autowired (required = true)


Action:

Consider defining a bean named 'entityManagerFactory' in your configuration.

I cannot understand or look for the error, how to unblock myself, I search again and again but I cannot understand why microservice B does not want to compile.

I use a POM Parent, and I was careful to put the following order:

<modules>
<module>sub module </module>
<module> microservice A </module>
<module> microservice B </module>
</modules>

So I hack, without understanding too much and sometimes I have different messages but always the compilation which fails

Concretely, it is possible to use the Repositories of the sub-module in microservice A and B?

Thank you for your attention and your help

Upvotes: 0

Views: 566

Answers (2)

Vishal Varshney
Vishal Varshney

Reputation: 103

I had a look at your repo and found few of the things are missing

In your CountryRepository.java class

@Repository 
public interface CountryRepository extends JpaRepository<Country, Long> {
}

@Repository annotation is missing, you need to add that

Then in your Main Class of service A and service B you have to add as below

@SpringBootApplication
@EnableJpaRepository("com.submodule.commun.modelandjpa.Repository")
public class ParentApplication {

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

}

That's all..

Upvotes: 0

Vishal Varshney
Vishal Varshney

Reputation: 103

Yes, you can use Repositories of sub-modules.

You have to use @EnableJpaRepository in your main class and give the base package name there.

That's all, This will do the trick

Upvotes: 0

Related Questions