There is no such thing as perfect programming, but we shouldn’t be discouraged because programming is a constant pursuit of perfection.

Public static void main(String[] args) {// Get bean String from XML xmlPath = "application-context.xml"; ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(xmlPath); BeanService service = (BeanService) context.getBean("beanService"); System.out.println("xml bean : " + service); service.print(); / / by the annotation for bean AnnotationConfigApplicationContext aContext = new AnnotationConfigApplicationContext(Config.class); BeanService bService = (BeanService) aContext.getBean("beanService"); System.out.println("anno bean : " + bService); bService.print(); / / by the annotation scanning AnnotationConfigApplicationContext annoContext = new AnnotationConfigApplicationContext (); annoContext.register(ScanConfig.class); annoContext.refresh(); BeanService beanService = (BeanService) annoContext.getBean("beanService"); System.out.println("scan anno bean : " + beanService); beanService.print(); }Copy the code

For more information, please pay attention to the official account: