Results 1 to 2 of 2

Thread: Loading spring application context files that are inside a jar in Java Build Path

  1. #1
    Join Date
    Apr 2009
    Posts
    4

    Question Loading spring application context files that are inside a jar in Java Build Path

    Hi all,

    I am trying to use ClassPathXmlApplicationContext in my java standalone code to load applicationContext.xml that is inside a jar file which is in my Java Build Path in Eclipse.

    applicationContext.xml entry as follows,
    Code:
     ApplicationContext context = new ClassPathXmlApplicationContext("classpath*:**/applicationContext*.xml");
    And the bean definition in applicationContext.xml is as follows,
    Code:
      <bean id="myAdder" class="com.foo.bar.MyAdder">
           <property name="floatAdder" ref="floatAdder"/>        
       </bean>
    And, when I try to load a bean that way I am getting NoSuchBeanException. Can't a bean by loaded in this way?

    The jar file is added to my classpath as a maven dependency. When I see the Java Build Path in Eclipse for this project, I see this jar linked as M2_REPO/.../..

    I was assuming I can load the bean inside the jar file as the jar is in classpath this way. Am I missing something?

    Thanks,
    J

  2. #2

    Default

    I would recommend:

    1. being specific about which Spring configuration you want to load instead of using wild cards (e.g. META-INF/conf/SpecificSpringConfiguration.xml). Just cuz you might end up loading some other Spring confs that you really don't intend, unless you are sure you want to load all confs from the resulting wild card path.

    2. You are already using ClassPathXmlApplication context so you don't need to add the "classpath:" prefix on the constructor arg. Just do for example:
    Code:
    new ClassPathXmlApplicationContext( "META-INF/conf/applicationContextYouWantToLoad.xml" )
    Which bean is it not founding? "myAdder" or "floatAdder" or some other?


    nicolas.loriente

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •