facebook

Component scanning not working in jar files

  1. MyEclipse IDE
  2.  > 
  3. Spring Development
Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #312020 Reply

    mitab
    Member

    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

    #312022 Reply

    davemeurer
    Member

    Hello,

    Would the Adding Classes to the JAR File’s Classpath tutorial help? It seems a couple folks had similar issues, and one of the comments was the spring jar needed to be outside the app jar: Deployment as a jar forum post

    If that doesn’t help, please respond with the error messages you are seeing.

    Kind regards,
    Dave

    #312024 Reply

    mitab
    Member

    Hi,

    Thanks for the information. Based on your reply that the spring and other jar files need to be outside the application jar I regenerated the jar this time selecting to create an executable jar file with the libary jar files placed in a sub folder. This option worked and is much easier than manually specifying all the dependent library jars externally.

    Thank you so much for your help.

    #312048 Reply

    davemeurer
    Member

    Hello,

    Glad to hear it! Thanks for replying and posting what worked.

    Kind regards,
    Dave

Viewing 4 posts - 1 through 4 (of 4 total)
Reply To: Component scanning not working in jar files

You must be logged in to post in the forum log in