2

I am trying to figure out where to put the spring application context XML file (mapping Service Beans) in a IntelliJ generated Spring MVC template. If I put it in the WEB-INF folder, it complains when I import the XML in the dispatcher servlet XML file. If i put it in the webapp folder, tomcat complains that it can't find it in the WEB-INF folder. So where do I actually put it?

The template generated by IntelliJ for a Spring MVC application has a 'pages' folder inside webapp dir. Do I have to put my jsps there or in the WEB-INF folder as in Eclipse? How is the root context path mapped to this folder when deployed in Tomcat?

spring application XML

3 Answers 3

2

In the web.xml you mention contextConfigLocation which mentions the locations and names of the resources which the context reads. This element should contain the path and name of the XML files.

<context-param> <param-name>contextConfigLocation</param-name> <param-value> classpath:com/some/path/applicationContext.xml classpath:dbContext.xml </param-value> </context-param> 

Now the dbcontext.xml is directly under the classpath whereas applicationContext is in the classpath in the folder heirarchy com/some/path

When the application gets built, the classess generally go into WEB-INF/classes directory. So if a war is made with above config, dbContext will be under classes dir. Generally, it could be a good idea to create another source folder in your project. Name it something like resources or config and put your configuration files there.

Does this help?

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

Comments

0

You can keep it in classpath and have the following configuration in web.xml

 <context-param> <param-name>contextConfigLocation</param-name> <param-value>classpath:applicationContext.xml</param-value> </context-param> 

org.springframework.web.context.ContextLoaderListener In a maven project we are keeping it inside resources folder.

Comments

0

You can put spring-context file in the same directory where dispatcher-servlet is exist or you can create new directory inside web-inf say spring in that you can put the spring-context file.

suppose you have put the spring-context inside spring directory then you can call it like :

<import resource="spring/spring-context.xml"/> 

in dispatcher-servlet.xml.

look this is my structure of spring application and working great :

enter image description here

still some problem then post me.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.