Splitting applicationContext to multiple files

前端 未结 5 1800
心在旅途
心在旅途 2020-11-27 11:10

What is the correct way to split Spring\'s configuration to multiple xml files?

At the moment I have

  • /WEB-INF/foo-servlet.xml
5条回答
  •  一整个雨季
    2020-11-27 11:37

    There are two types of contexts we are dealing with:

    1: root context (parent context. Typically include all jdbc(ORM, Hibernate) initialisation and other spring security related configuration)

    2: individual servlet context (child context.Typically Dispatcher Servlet Context and initialise all beans related to spring-mvc (controllers , URL Mapping etc)).

    Here is an example of web.xml which includes multiple application context file

    
    
    
        Spring Web Application example
    
        
        
            org.springframework.web.context.ContextLoaderListener
        
        
            contextConfigLocation
            
                /WEB-INF/spring/jdbc/spring-jdbc.xml 
                /WEB-INF/spring/security/spring-security-context.xml 
            
        
    
        
        
            spring-mvc
            org.springframework.web.servlet.DispatcherServlet
            
                contextConfigLocation
                
                    /WEB-INF/spring/mvc/spring-mvc-servlet.xml
                
            
        
        
            spring-mvc
            /admin/*
        
    
    

提交回复
热议问题