I have a spring application which uses component scanning and import of subsidiary context files into the main application context. While this application runs fine from within MyEclipse for Spring 8.6 when I export the project as an executable jar with the dependent libraries packaged, the beans are not found. For eg my main class has the following code
ApplicationContext context = new ClassPathXmlApplicationContext(new String[] {“applicationContext.xml”});
WIPListService wipListService = context.getBean(“WIPListService”, WIPListServiceImpl.class);
wipListService.generateEAODualRoleReport();
In the application context file I have
<import resource=”classpath:ServiceContext.xml” />
In the service context file I have
<context:component-scan base-package=”service”/>
and in the service package my bean class is annotated as
@Service(“WIPListService”)
public class WIPListServiceImpl implements WIPListService {
Similarly another bean which was referring to a bean gave an error till I actually defined the bean in the xml file.
Is there anything special I need to do while exporting the application to get it to work outside MyEcipse. I selected Export -> Runnable Jar File and package dependent libraries in jar files as the option and run the jar from the command prompt as java -jar <jarfilename>.jar