Spring get current ApplicationContext

后端 未结 11 908
陌清茗
陌清茗 2020-11-28 20:04

I am using Spring MVC for my web application. My beans are written in \"spring-servlet.xml\" file

Now I have a class MyClass and i want to

11条回答
  •  [愿得一人]
    2020-11-28 20:38

    Another way is to inject applicationContext through servlet.

    This is an example of how to inject dependencies when using Spring web services.

    
            my-soap-ws
            org.springframework.ws.transport.http.MessageDispatcherServlet
            
                transformWsdlLocations
                false
            
            
                contextConfigLocation
                classpath:my-applicationContext.xml
            
            5
    
    
    

    Alternate way is to add application Context in your web.xml as shown below

    
        contextConfigLocation
        
            /WEB-INF/classes/my-another-applicationContext.xml
            classpath:my-second-context.xml
        
    
    

    Basically you are trying to tell servlet that it should look for beans defined in these context files.

提交回复
热议问题