Spring Bean手工实例化方式

实例化容器

ApplicationContext ctx = new ClassPathXmlApplicationContext("beans.xml");

创建实例

OrderService orderService = ctx.getBean(OrderService.class);

其他

@Qualifier
类中同一类型对象定义了多个时,用Qualifier设置ID

@Primary
针对同一接口有多种实现且同时添加了@Component@Service@Repository等注解,用Primary指定默认@Autowired

猜你喜欢

转载自blog.csdn.net/lpw_cn/article/details/84642631