0
안녕하세요, 저는 스프링 프로파일을 사용하는 간단한 예제를 작성하려고합니다.Spring getEnvironment()
public static void main(String[] args) {
GenericXmlApplicationContext ctx = new GenericXmlApplicationContext();
ctx.getEnvironment().setActiveProfiles("kindergarten");
ctx.load("classpath:profile/*-config.xml");
ctx.refresh();
FoodProviderService foodProviderService =
ctx.getBean("foodProviderService", FoodProviderService.class);
List<Food> lunchSet = foodProviderService.provideLunchSet();
for (Food food: lunchSet) {
System.out.println("Food: " + food.getName());
}
} 그러나 이상한 점은
ctx.getEnvironment().setActiveProfiles("kindergarten");
투여하지 work.My STS 그가 생각하기 때문에 주요 실행을 거부 세 번째 줄 수 있도록 API의에서이 getEnviroment() 메소드가없는 선량 GenericXmlApplicationContext 발생 이것은 그가 나 에게이 메시지를주는 sintax 오류입니다 :
Exception in thread "main" java.lang.Error: Unresolved compilation problem:
The method getEnvironment() is undefined for the type GenericXmlApplicationContext
어떤 아이디어? 덕분에 .