Difference between applicationContext.xml and spring-servlet.xml in Spring Framework

前端 未结 6 549
挽巷
挽巷 2020-11-22 01:35
  • Are applicationContext.xml and spring-servlet.xml related anyhow in Spring Framework?
  • Will the properties files declared in
6条回答
  •  你的背包
    2020-11-22 01:40

    In Servlet technology if you want to pass any input to a particular servlet then you need to pass in init param like below code.

     
        DBController
        com.test.controller.DBController
        
            username
            John
        
        1
    
    
    
        DBController
        /DBController
    
    

    If you want to pass some in put that is common for all servlets then that time you need to configure context param. Example

     
        email
        admin@example.com
    
    

    SO exactly like this when ever we are working with Spring MVC we need to provide some information to Predefined servlet provided by Spring that is DispatcherServlet through init param. So the configuration is as fallows, here we are providing the spring-servlet.xml as init parameter to DispatcherServlet.

     
    
        Spring MVC App
    
        
            SpringController
            org.springframework.web.servlet.DispatcherServlet
            
                contextConfigLocation
                /WEB-INF/spring-servlet.xml
            
            1
        
    
        
            SpringController
            *.htm
        
    
    

    Again we need some context param. That is applicable for whole application. So we can provide the root context that is applicationcontext.xml The configuration is like this:

        
        contextConfigLocation
        /WEB-INF/applicationcontext.xml
    
    
        org.springframework.web.context.ContextLoaderListener
    
    
    
            SpringController
            org.springframework.web.servlet.DispatcherServlet
            
                contextConfigLocation
                /WEB-INF/spring-servlet.xml
            
            1
        
    
        
            SpringController
            *.htm
        
    

提交回复
热议问题