I would like to load inside my Spring MVC web application (in the form of a WAR) some Spring beans framework annotated with @Service from an external jar that responds to database access and located in the classpath under / WEB -INF / lib. If possible, it would be advisable to download them automatically using the @Autowired annotation.
I successfully executed the solution in link1 :
this.ctx = new ClassPathXmlApplicationContext("services-context.xml"); this.myAService = ctx.getBean("myAService");
However, this solution uses the Spring getBean API function , which is considered bad practice (see link2 ).
I also tried, with no luck, two more things to load the external jar's applicationContext:
WAR's appContext.xml:
<import resource="classpath*:/WEB-INF/lib/pathToExternalJar/applicationContext.xml">
WAR's web xml -> download the appContext jar as described here ( link3 ). (e.g. * applicationContext.xml):
<context-param> <param-name>contextConfigLocation</param-name> <param-value> classpath:localSpringContext.xml classpath:*applicationContext.xml </param-value> </context-param>
What is the best approach to loading these beans and how to do it?
source share