Spring3.0中多配置类引入设置

    科技2026-01-11  17

    Spring3.0中多配置类引入设置

    1.在创建Spring容器时引入多个配置类

    AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(ApplicationConf.class,ApplicationConfig.class);

    2.使用@Import注解

    在主配置类上使用@Import注解,其中使用大括号包裹要引入的其他配置类:

    @Configuration @Import({ApplicationConf.class,ApplicationConfig.class}) public class SpringConfig { }
    Processed: 0.017, SQL: 9