Mixing xml and java config with spring

后端 未结 1 881
名媛妹妹
名媛妹妹 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:

    <context-param>
        <param-name>contextClass</param-name>
        <param-value>
            org.springframework.web.context.support.AnnotationConfigWebApplicationContext
        </param-value>
    </context-param>
    
    0 讨论(0)
提交回复
热议问题