I have a SpringBoot
application that uses @Component
annotations to create beans rather than the old XML-based applicationContext
files.
I need to use a library that uses XML-based beans. I need those beans initialized and available in my application, otherwise I'd end up rewriting quite a bit of code.
I've tried using @ComponentScan to find them, which as expected does not work as the classes are not annotated with @Component. I've tried using @ImportResource, as described here but no luck.
So the question is, how can I instantiate the beans in a jar dependency, which are defined in the XML style while my app does not use XML applicationContext
files and then use them in my application?
Note:
The library I need to import is quite old and the chance of having it use component annotations is pretty much 0. Whatever I change has to be in my project.
I am aware that starting to use applicationContexts
might work, but I really want to move away from XML-based beans.
Here's the SpringBootApplication class in case it might be useful:
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
import org.springframework.boot.web.support.SpringBootServletInitializer;
@SpringBootApplication
@EnableAutoConfiguration(exclude={DataSourceAutoConfiguration.class})
public class MyApp extends SpringBootServletInitializer {
public static void main(final String[] args) {
SpringApplication.run(MyApp.class, args);
}
}