首页>代码>Spring使用@Primary处理多个@Autowire申明的相同bean>/handling-multiple-autowire-candidates-spring-primary-example/src/main/java/com/memorynotfound/spring/core/autowired/Config.java
package com.memorynotfound.spring.core.autowired; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.ComponentScan; import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Primary; @Configuration @ComponentScan(basePackages = "com.memorynotfound") public class Config { @Bean public Person person(){ return new Person(); } @Bean @Primary public Job javaDeveloper(){ return new Job("Java Developer at zuidaima.com from AnnotationConfigApplicationContext"); } @Bean public Job frontEndDeveloper(){ return new Job("Front end Developer"); } }
最近浏览更多
全栈小白 LV32
2023年1月8日
ming_123_9715 LV23
2022年12月11日
daimazui951 LV1
2022年10月8日
19878648897 LV1
2022年6月28日
kingoneyang LV13
2022年3月18日
微信网友_5774849294258176
2022年1月4日
暂无贡献等级
ztkqwert LV1
2022年1月1日
君知否 LV17
2021年11月11日
最代码-宋家辉 LV61
2021年11月2日
liuyu-zui LV4
2021年8月25日