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 class path.
ApplicationContext context = new ClassPathXmlApplicationContext("classpath*:**/applicationContext*.xml");
applicationContext.xml entry as follows,
<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,Abi
Do you really need the
classpath*:
prefix on that location? (Is that*
legal?) I would have expected something more like:This should work, I just created the 2 projects and checked.
Project A (standard Maven project created with STS) has
applicationContext.xml
in src/main/resources.pom.xml:
applicationContext.xml:
Project B:
pom.xml: same as A, except A is added as dependency:
Start.java in project B:
mvn install A first, then run Start in project B.