Run spring boot without @SpringBootApplication annotation as jar library in another project
I'm trying to use @autowired annotation in a spring boot project that's not started by main method with @SpringBootApplication annotation. Instead, i did created a jar of that spring project and i'm using that jar as an external jar in a legacy project (non-spring project). As result i can't get ApplicationContext and all beans managed by spring when you run application from main method are null.
Is that possible to use Spring boot project as a .jar without run main method??
public class RetrieveSubscriberType {
public RetrieveSubscriberType() {
ApplicationContext appCtx = ApplicationContextUtils
.getApplicationContext();
this.subscriber = (SubscriberDAOImpl)appCtx.getBean("subscriber");
}
appCtx always null
@Configuration
public class ApplicationContextUtils implements ApplicationContextAware {
private static ApplicationContext ctx;
@Override
public void setApplicationContext(ApplicationContext appContext)
throws BeansException {
ctx = appContext;
}
public static ApplicationContext getApplicationContext() {
return ctx;
}
}
ApplicationContextUtils where method setApplicationContext is not called
from Recent Questions - Stack Overflow https://ift.tt/3uqg5SV
https://ift.tt/eA8V8J
Comments
Post a Comment