Mixing xml and java config with spring

后端 未结 1 892
名媛妹妹
名媛妹妹 2020-12-02 15:56

I am building a new application that configures spring through a java config rather than xml. This app is dependent on a module that uses the xml style config. When I try an

1条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-12-02 16:34

    In your configuration class, you can import xml configuration via the @ImportResource annotation.

    Something like this:

    @Configuration
    @ImportResource({"classpath:appbase-context.xml"})
    public class AppConfig {
        // @Bean definitions here...
    }
    

    Remember, when you are using Spring's Java Configuration, you need to specify an additional context-param that says the class to use for your application context:

    
        contextClass
        
            org.springframework.web.context.support.AnnotationConfigWebApplicationContext
        
    
    

    0 讨论(0)
提交回复
热议问题