0

I am newbie in Spring. I have problem with classpath as parameter of ClassPathXmlApplicationContext. I use Netbeans. The class where I use ClassPathXmlApplicationContext is in package cz.ryska.helloworld in Source Packages folder. Configuration XML file, name as Beans.xml is in WEB-INF folder.

enter image description here

But I don't know what way I can use. I try use f.e "WEB-INF\Beans.xml" or "/WEB-INF/Beans.xml" but file is not found. What way I can use or where I must move xml file? Thanks

1 Answer 1

2

The project appears to be a J2EE web application, so you shouldn't need to create a new DI container with ClassPathXmlApplicationContext. Instead import beans.xml in your applicationContext.xml file, if it is already registered in web.xml.

In web.xml include:

<context-param>
    <param-name>contextConfigLocation</param-name>
    <param-value>/WEB-INF/applicationContext.xml</param-value>
</context-param>

In applicationContext.xml include:

<import resource="Beans.xml"/>

This will cause the Beans.xml configuration to be added to the DI container.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.