Java – Spring application context file location in IntelliJ

intellij-ideajavaspringspring-mvctomcat

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

Best Solution

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?