Java 将注释ConfigWebApplicationContext与ClassPathXmlApplicationContext合并
我有两个应用程序上下文:Java 将注释ConfigWebApplicationContext与ClassPathXmlApplicationContext合并,java,spring,Java,Spring,我有两个应用程序上下文: AnnotationConfigWebApplicationContext appContext = new AnnotationConfigWebApplicationContext(); appContext.register(BeansConfig.class); 及 如何在不使用注释重新编写XML或反之亦然的情况下将这些内容转换为单个上下文 ApplicationContext mergedContext = // appContext.
AnnotationConfigWebApplicationContext appContext = new AnnotationConfigWebApplicationContext();
appContext.register(BeansConfig.class);
及
如何在不使用注释重新编写XML或反之亦然的情况下将这些内容转换为单个上下文
ApplicationContext mergedContext = // appContext.merge(secContext ) ????
这样做可能吗?使用@Configuration类导入xml和注释配置
@Configuration
@Import(BeansConfig.class)
@ImportResource("classpath:/spring-security.xml")
public class AppConfig{}
如果您使用Spring Boot,您也可以直接在Spring Boot主类上添加它在您的BeansConfig
上,但您为什么要创建自己的配置?通常,这是您不应该做的事情,表明您做了错误的事情。(该配置应由ContextLoaderLIstener
或DispatcherServlet
加载)。
@Configuration
@Import(BeansConfig.class)
@ImportResource("classpath:/spring-security.xml")
public class AppConfig{}