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

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

Related

#ConfigurationProperties in spring boot WAR project

I want to use #ConfigurationProperties and bind some properties in application.properties to that class. When I exclude embedded tomcat dependency from pom.xml, I cant use those properties defined in #ConfigurationProperties class. How can I solve the problem when using an external tomcat?

Load beans/controller from external jar in spring boot without changing config class

I want to load a bean from a external jar into spring boot project. But I don't want to make changes to existing spring boot config file. I want same behavior like actuator. Just add dependency and bean or endpoint will be available in spring boot

Spring Boot - configure properties of a jar included as dependency into another jar

I have a Spring Boot web app A and its dependent on a Spring Boot jar library B. I have some properties that I want to configure within B and don't want the client apps (e.g. the web app A) to configure them. I have these properties files in B.
application-dev.properties
application-stage.properties
applicatino-live.properties
The issue is that these properties are not recognized when the library is added as a dependency in web app A. What is the way to achieve this?
The PropertySource annotation can be used in a Configuration class on webapp A to achieve what you're looking for:
#Configuration
#PropertySource("classpath:application-dev.properties"),
#PropertySource("classpath:application-stage.properties"),
#PropertySource("classpath:application-live.properties")
public class WebappAConfiguration {
}
I also found the order that spring boot looks for externalized configuration helpful here.

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-Boot : Referencing another Spring Boot Project

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.

Resources