In my application I have placed the ApplicationContext xml file in src and the project is working fine.
Can we place the ApplicationContext.xml in our WebContent or Web-Inf folder?
Also I want to know if I can place my properties file in WebContent.
Since I have placed my ApplicationContext.xml in src, I placed my properties file in src and that worked fine. Below is the code for it
<bean id="licenseSettings"
class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="location" value="classpath:LicenseSettings.properties" />
</bean>
I tried putting the properties file in WebContent/conf but the properties were not read succesfully.
My question is, can we put ApplicationContext.xml and properties file somewhere inside WebContent folder?
Update: I put my ApplicationContext.xml in WEB-INF/classes and it was read successfully using ApplicationContext ctx = new ClassPathXmlApplicationContext("ApplicationContext.xml");
My only question remaining unanswered is, where shall I put my properties file and where is it appropriate to be put in?
There are couple of ways you can do this:
In Spring MVC, You mention
dispatcher-servletinweb.xmlas followsNow this by default will look for a file named
mvc-dispatcher-servlet.xml. That is, the servlet name appended by -servlet.xml. And it will look for this file in class path.Alternatively which fits your case, if you already have xml file and don’t want to rename it, add the following entry in web.xml in addition to the servlet entry above.
Here you can choose any location inside WEB-INF. Put the properties file in classes folder so that it could be found in classpath. Since you are using Eclipse embedded Tomcat, put the following as your bean configuration for property placeholder.