Location of ApplicationContext.xml and properties file in spring

前端 未结 2 1606
生来不讨喜
生来不讨喜 2021-02-06 18:25

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

2条回答
  •  你的背包
    2021-02-06 19:16

    There are couple of ways you can do this:

    In Spring MVC, You mention dispatcher-servlet in web.xml as follows

     
              mvc-dispatcher
                
                          org.springframework.web.servlet.DispatcherServlet
                
                1
    
    

    Now 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.

     
        contextConfigLocation
        /WEB-INF/conf/ApplicationContext.xml
     

    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.

      
    

提交回复
热议问题