Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Where do I place the applicationContext.xml file within Spring project directory

I am trying to learn about the Spring framework for Java and I am not sure where about's I am supposed to put the applicationContext.xml file for configuring the spring beans. My directory structure is as follows:

Spring directory layout

Do I put in .settings? Or should it be put at the top level within springapp?

Thanks for the help.

like image 952
dickturnip Avatar asked Jan 20 '14 21:01

dickturnip


People also ask

Where will you place the file Spring XML?

In essence the Spring configuration files (that can have any name by the way, not just the generic applicationContext. xml ) are treated as classpath resources and filed under src/main/resources .

Where is Spring application context file?

The basis for the context package is the ApplicationContext interface, located in the org. springframework. context package. Deriving from the BeanFactory interface, it provides all the functionality of BeanFactory .

What is the use of ApplicationContext .XML in Spring?

Applicationcontext. xml - It is standard spring context file which contains all beans and the configuration that are common among all the servlets. It is optional file in case of web app. Spring uses ContextLoaderListener to load this file in case of web application.


1 Answers

Put into directory WebContent/WEB-INF.

Resources placed into WEB-INF folder are not accessible from web, they are application internal resources. This is good, because your applicationContext.xml shouldn't be accessible from web.

Other good options are WebContent/WEB-INF/classes or just src (both are equal).

Files and folders with . contains Eclipse configuration files, they are internal for Eclipse - do not use them.

like image 65
MariuszS Avatar answered Sep 21 '22 19:09

MariuszS