Spring-Boot : Referencing another Spring Boot Project - spring-boot

I created two spring boot projects, one is with JPA and the other with Web. I initially combined both of them into one project and everything works perfectly.
I now want to separate the JPA portion from the Web. So I added the JPA project as a dependency of the Web. But spring-boot is unable to detect the beans on JPA.
Is there any examples on how to implement this?
I am getting the exception when I tried to autowire the beans from the JPA project.
BeanCreationException: Could not autowire field:

The #EntityScan and #EnableRestRepository by default only scan the sub packages of the current project so if you want to have two projects you should implicitly set the path of the other project to be scanned.

Related

Springboot application getting Conflicting persistence unit definition for name default

In my spring boot application, I am using some jar files which have inner jars.Those inner jars have separate persistence.xml file and using default as persistence unit name. Now while I am trying to run my spring boot application, I am getting conflicting persistence unit definition for name default. Does somebody know how to resolve this?

How to autowire datasource from dependent spring boot app in another spring boot jar project?

I have Spring boot web app let's name it A and jar spring boot project let's name it B. There is dependency to jar B in pom file of Spring boot app A. DataSource is defined in app A. The question now is as follows: Is there possibility to autowire DataSource from app A in jar B?
When I try to autowire there is warning: "Could not autowire. No beans of "DataSource" type found". Is there possibility to point spring boot in jar B, to autowire DataSource from dependent app? Any suggestions will be very helpful. Thank's a lot!
You can do that just add the #ComponentScan annotation and include package of the first app to be scanned by Spring in the second app.
Here is something that you should do in the second app:
#ComponentScan("foo.bar")
#SpringBootApplication

How to add class with #resource annotation from a dependancy JAR to spring-boot application

i have two projects one for cache and other to use it. I have added the dependency of cache project as jar in my spring-boot application. but the classes mentioned with #Resouce i am not able to access in my spring boot application. how to resolve it?

Spring: Injecting services from a different project

In the project our team's working on, we currently have 3 separate Spring projects which utilizes the same services. To avoid redunancy and code copy-pasting, we're planning to create a "common" project wherein all the three projects would be dependent on the common project. In this instance, is it possible to inject these services (perhaps using the #Service annotation) to the Controllers of the Spring projects?
EDIT:
I tried implementing this on my own and what I basically did was I configured the pom.xml to get the Spring Context 3.1.1 dependency (which are also being used by my Spring projects) for my "common" project. With that, I was able to annotate my service with #Service. Afterwards, on my Spring project, I set the component-scan to a level wherein my two projects would meet. On my Spring controller, I #Autowired the service from the "common" project. I ran the Spring project and apparently it worked. Is this the best way to do this?
That's absolutely fine, and standard. Spring (unlike CDI) couldn't care less whether your beans come from the current project or from an imported jar.

Spring autowiring classes between 2 distinct project

I'm trying to autowire classes between 2 projects with spring (using eclipse IDE). So I added to the first project the second project to the build path. The imports are resolved correctly but when I launch the app the log tells me that he can't find the class which I'm trying to wire to.
The classpath have solved the problem.

Resources