【发布时间】:2017-03-09 04:35:35
【问题描述】:
tl;dr:如何基于基于注解的配置类创建 Spring 上下文,同时提供活动配置文件?
我正在尝试使用具有使用注释指定的配置的类来创建 Spring 上下文。
org.springframework.context.ApplicationContext context =
new org.springframework.context.annotation.AnnotationConfigApplicationContext( com.initech.ReleaserConfig.class );
但是,当它启动时,它会崩溃,因为它找不到所需的 bean,但该 bean 确实存在:尽管仅在某个配置文件 "myProfile" 下。
如何指定活动配置文件?我觉得我需要使用 org.springframework.context.annotation.AnnotationConfigApplicationContext(org.springframework.beans.factory.support.DefaultListableBeanFactory) 构造函数之一,但我不确定哪个合适。
PS- 我没有使用 Spring Boot,但我使用的是 Spring 4.2.4.RELEASE。
【问题讨论】: