Demo entry 6732841

1

   

Submitted by 1 on Apr 15, 2018 at 16:29
Language: Java. Code size: 804 Bytes.

public class Main {
    
    public static void main(String[] args) {
        // 通过Java配置来实例化Spring容器
        AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(SpringConfig.class);
        
        // 在Spring容器中获取Bean对象
        PeopleService userService = context.getBean(PeopleService.class);
        
        // 调用对象中的方法
        List<People> list = userService.queryUserList();
        for (People user : list) {
            System.out.println("---"+user.getUsername() + ", " + user.getPassword() + ", " + user.getPassword()+"---");
        }
        
        DataSource datasource = context.getBean(DataSource.class);
        System.out.println(datasource);
        
        // 销毁该容器
        context.close();
        context.destroy();
    }

}

This snippet took 0.01 seconds to highlight.

Back to the Entry List or Home.

Delete this entry (admin only).