ClassPathXmlApplicationContext applicationContext = new ClassPathXmlApplicationContext("xxx.xml");
applicationContext.start();
xxxService x = (xxxService) applicationContext.getBean("xxxService");
比较简单的方式,在主函数中测试Spring装配Bean的情况,不需要启动装个系统。
本文介绍了一种简单的方法来测试 Spring 中的 Bean 装配情况,无需启动整个系统。通过在主函数中创建 ApplicationContext 并获取指定的服务 Bean,可以快速验证配置是否正确。
ClassPathXmlApplicationContext applicationContext = new ClassPathXmlApplicationContext("xxx.xml");
applicationContext.start();
xxxService x = (xxxService) applicationContext.getBean("xxxService");
比较简单的方式,在主函数中测试Spring装配Bean的情况,不需要启动装个系统。

被折叠的 条评论
为什么被折叠?