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

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?

Related

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.

PF4J Spring - not able to load any components in the plugin other than the beans declared in configuration class

We are using plugin architecture for one of our projects and we decided to use Spring pf4j for the same.
When we load the plugin via extensions - the application context is not able to find the beans created using #component in the plugin project- but the beans declared in #configuration classes are injected properly when we configure the plugin using register method - Is there anyway to scan and load the spring components in the plugin?
#Component in plugin is registered to main ApplicationContext via SpringExtensionFactory, make sure you set it up correctly in DefaultPluginManager correctly.
If you are going to use pf4j in SpringBoot, I would suggest you take a look sbp project. It is built upon pf4j and provides better integration with SpringBoot.

Separate properties for a shared spring library contained inside a spring boot application

I created a shared library in spring that I deploy as an artifact in an artifactory. I use this shared library artifact in another spring boot application as a pom dependency. Shared library has it's own properties files under src/main/resources
I am having problems with the following:
When I try to load the spring boot application, it is not able to load the properties for the shared library and expects all the properties shared library needs in the outer spring boot application. How can fix this and have shared library always read its own properties file ?
Use #PropertySource annotation to provide the two sources for your app:
#PropertySources({
#PropertySource("classpath:yourSharedLib.properties"),
#PropertySource("classpath:youApp.properties")
})

read properties from third party jar in spring boot application

I’m adding a third party jar as a maven dependency in my spring boot application A. Third party jar is a jar of another spring-boot application B. it has its own configurations saved in conf folder "B.properties".
I have used #Import({B.class}) annotation to import the beans of application B in my application but not able to access the configuration properties of application B. Is there any way to access the configuration properties of an application from a jar?
You can create your own Config Server just add #EnableConfigServer annotation and provider configurations from service A to service B.
You can review this example:
https://spring.io/guides/gs/centralized-configuration/
UPDATED Fix adding
#PropertySource("classpath:/conf/B.properties"),

Eclipse RCP, Spring, Hibernate Class Loading Issue

I’m developing a RCP based app that uses a data access layer implemented using Spring Data JPA backed by hibernate. The annotated domain classes are in one jar/bundle, the Spring repositories and spring config to instantiate the datasource, entity manager, and transaction manager are in another bundle.These jars are used by other non-RCP apps across the project.I have all of the hibernate 3.6.8 jars and dependencies either wrapped and exposed through my own plugins or as OSGI bundles (jta, antlr, commons collections, etc) in the target platform. I’m using Eclipse Gemini Blueprint to manage the bundle spring contexts within the RCP app.
When the DAL bundle spring context is being initialized by the gemini extender, I get Hibernate related ClassDefNotFound exceptions, usually either on org.hibernate.ejb.HibernatePersistence or javax.persistence.spi.Persistenceprovider. I’ve tried putting all of the hibernate jars and dependencies in a single plugin that exports the javax and hibernate packages. I’ve tried setting Eclipse Buddy policies in the manifests of the plugins that I have control over, etc.
I haven’t been able to find any solution to this class loading issue between Spring and Hibernate under Eclipse RCP using Gemini. I’ve done past hibernate DAO projects within RCP by putting all of the hibernate jars in the same plugin as my domain and DAO classes, so only my classes are exported.
At this point I don’t think moving to a more OSGI friendly JPA provider like OpenJPA or EclipseLink is an option.
I found an answer to a slightly related question that suggested putting all of the spring jars and dependencies into a single plugin, with the hibernate jars and dependencies in another plugin with buddy policies set. This seems dirty when most of the jars involved are OSGi bundles.
I suppose I could create a plugin that holds the DAL jar, hibernate jars, and spring ORM jars, so they can all see each other.
Is there a clean way to get this to work?
The core bundle if you own it, add all the suspected bundles as registered buddies and make sure that you have defined packages or bundles are reuired otherwise sometimes buddy class loading is not going to work. If the loading is initiated from you bundle the eclipse buddy policy should cascade. Other option would be to modify the manfiest files in target bundles that are causing issues.

Resources