标签:找不到 contex odi das 聚合 pem ase awd ack
@Target({ElementType.CONSTRUCTOR, ElementType.METHOD, ElementType.PARAMETER, ElementType.FIELD, ElementType.ANNOTATION_TYPE}) @Retention(RetentionPolicy.RUNTIME) @Documented public @interface Autowired { /** * Declares whether the annotated dependency is required. * <p>Defaults to {@code true}. */ boolean required() default true; }
@Configuration @ComponentScan(basePackages = {"cn.monolog.service"}) public class AutowiredBeanConfig { @Bean(value = "bookDao1") public BookDao bookDao1() { BookDao bookDao = new BookDao(); bookDao.setLabel("bookDao1"); return bookDao; } @Bean(value = "bookDao2") @Primary public BookDao bookDao2() { BookDao bookDao = new BookDao(); bookDao.setLabel("bookDao2"); return bookDao; } @Bean(value = "bookDao3") public BookDao bookDao3() { BookDao bookDao = new BookDao(); bookDao.setLabel("bookDao3"); return bookDao; } }
@Autowired @Qualifier(value = "bookDao1") private BookDao bookDao3;
@Configuration @ComponentScan(basePackages = {"cn.monolog.service"}) public class ResourceBeanConfig { @Bean(value = "carDao1") public CarDao carDao1() { CarDao carDao = new CarDao(); carDao.setLabel("1"); return carDao; } @Bean(value = "carDao2") public CarDao carDao() { CarDao carDao = new CarDao(); carDao.setLabel("2"); return carDao; } }
//自动注入 @Resource private CarDao carDao2;
//自动注入 @Resource(name = "carDao1") private CarDao carDao2;
@Configuration public class InjectBeanConfig { @Bean(value = "employeeDao1") public EmployeeDao employeeDao1() { EmployeeDao employeeDao = new EmployeeDao(); employeeDao.setLabel("1"); return employeeDao; } }
@Inject private EmployeeDao employeeDao3;
@Configuration public class InjectBeanConfig { @Bean(value = "employeeDao1") public EmployeeDao employeeDao1() { EmployeeDao employeeDao = new EmployeeDao(); employeeDao.setLabel("1"); return employeeDao; } @Bean(value = "employeeDao2") public EmployeeDao employeeDao2() { EmployeeDao employeeDao = new EmployeeDao(); employeeDao.setLabel("2"); return employeeDao; } @Bean(value = "employeeDao3") public EmployeeDao employeeDao3() { EmployeeDao employeeDao = new EmployeeDao(); employeeDao.setLabel("3"); return employeeDao; } }
@Inject private EmployeeDao employeeDao3;
@Configuration public class InjectBeanConfig {
@Bean(value = "employeeDao1") public EmployeeDao employeeDao1() { EmployeeDao employeeDao = new EmployeeDao(); employeeDao.setLabel("1"); return employeeDao; }
@Bean(value = "employeeDao2") @Primary
public EmployeeDao employeeDao2() { EmployeeDao employeeDao = new EmployeeDao(); employeeDao.setLabel("2"); return employeeDao; }
@Bean(value = "employeeDao3") public EmployeeDao employeeDao3() { EmployeeDao employeeDao = new EmployeeDao(); employeeDao.setLabel("3"); return employeeDao; } }
标签:找不到 contex odi das 聚合 pem ase awd ack
原文地址:https://www.cnblogs.com/dubhlinn/p/10708142.html