AnnotationConfigApplicationContext(Context

@Configuration
@PropertySource(value = "classpath:jdbc.properties")
public class ContextEnvironmentTest {
    @Autowired
    private Environment env;
    @Bean
    public TestBean getTestBean(){
        TestBean testBean = new TestBean();
        testBean.setName(env.getProperty("password"));
        System.out.println(testBean.toString());
        return testBean;
    }
    public static void main(String[] args) {
        ApplicationContext ctx = new AnnotationConfigApplicationContext(ContextEnvironmentTest.class);
        ContextEnvironmentTest myService = ctx.getBean(ContextEnvironmentTest.class);
        TestBean bean = myService.getTestBean();
        System.out.println(bean.getName());
    }
}

你可能感兴趣的:(AnnotationConfigApplicationContext(Context)