Ullas
Ullas

Reputation: 837

ClasspathXMLApplicationContext working in spring

I am new to Spring, i am trying to understand the statement "ClassPathXMLApplication context searches for xml in all jars in classpath".

So in an application

ApplicationContext context = new ClassPathXmlApplicationContext("myBeans.xml"); 

will it search in all the dependent jars for this myBeans.xml?

Upvotes: 1

Views: 696

Answers (2)

Pavan
Pavan

Reputation: 1289

Here is the link to understand how to pass the application bean context using constructors.

http://docs.spring.io/spring/docs/current/javadoc-api/org/springframework/context/support/ClassPathXmlApplicationContext.html

ApplicationContext context = new ClassPathXmlApplicationContext("myBeans.xml"); 

works fine if placed under src/resources/myBeans.xml , because

The classpath root is WEB-INF/classes, and src/main/resources goes there, together with src/main/java

Upvotes: 0

amit2091
amit2091

Reputation: 356

It will work , but you are not giving path of file right , since it is in a jar in classpath , you have to give something like this

ApplicationContext context = new ClassPathXmlApplicationContext("classpath*:**/myBeans.xml"); 

Hope this will help.

Upvotes: 1

Related Questions