非WEB工程怎么在main方法中加载spring容器

2025-05-22 18:45:52
推荐回答(1个)
回答(1):

如果想要在Main方法中获得我们在spring容器中配置的bean的话,
直接用ApplicationContext context = new ClassPathXMLContext("bean.xml");
然后直接调用context.getbean();即可获得我们的bean对象