Spring Configuration

前端 未结 5 1258
情深已故
情深已故 2020-12-14 09:48

I\'ve been reading up on Spring and it keeps talking about the spring configuration data you need, but where do you put this xml file? and what do you save it as? I can\'t s

5条回答
  •  隐瞒了意图╮
    2020-12-14 10:36

    As others pointed out the name of the Spring configuration file is not very important. The real question is how this file is loaded. In a standalone application you do it explicitly by using something like the ClassPathXmlApplicationContext class, as described in this part of the Spring documentation.

    In a web application this is usually configured in the web.xml file, by adding definitions for configuration listeners, and possibly configuration files. This is the setup I use:

    
            contextConfigLocation
            classpath:appContext.xml
        
    
            org.springframework.web.context.ContextLoaderListener
        
        
            org.springframework.web.context.request.RequestContextListener
        
    

    This allows me to put the config file anywhere I like, as long as it's on the application's classpath. You can even specify several configuration files in the param-value element, by separating them with spaces.

提交回复
热议问题