1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.common.util.spring.context;
17
18 import java.util.Arrays;
19 import java.util.Collections;
20 import java.util.List;
21 import java.util.Properties;
22
23 import org.junit.Test;
24 import org.kuali.common.util.PropertyUtils;
25 import org.kuali.common.util.log.LoggerUtils;
26 import org.kuali.common.util.spring.PropertySourceUtils;
27 import org.slf4j.Logger;
28 import org.springframework.context.annotation.AnnotationConfigApplicationContext;
29 import org.springframework.core.env.ConfigurableEnvironment;
30
31 import com.google.common.collect.Lists;
32
33 public class ContextTest {
34
35 private static final Logger logger = LoggerUtils.make();
36
37 @Test
38 public void test() {
39 try {
40 Properties source = PropertyUtils.load("classpath:org/kuali/common/util/spring/context/breakfast.properties");
41 AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
42 ConfigurableEnvironment env = ctx.getEnvironment();
43 PropertySourceUtils.reconfigurePropertySources(env, "properties", source);
44 ctx.register(CerealConfig.class, MilkConfig.class);
45 ctx.refresh();
46 String[] beanNames = ctx.getBeanDefinitionNames();
47 logger.info("{} beans in this application context", beanNames.length);
48 List<String> names = Lists.newArrayList(Arrays.asList(beanNames));
49 Collections.sort(names);
50 for (int i = 0; i < names.size(); i++) {
51 String name = names.get(i);
52 Object bean = ctx.getBean(name);
53 logger.info(" " + (i + 1) + " [{}]=[{}]", name, bean.getClass().getCanonicalName());
54 }
55 ctx.close();
56 } catch (Exception e) {
57 e.printStackTrace();
58 }
59 }
60
61 }