@Autowired,@Qualifier,@Resource的使用

@Autowired直接使用

    @Autowired
    private UserMapper userMapper;

@Qualifier需要与@Autowired一起使用,并在Qualifier写bean的name

   @Autowired
    @Qualifier("userMapper")
    private UserMapper userMapper;

@Resource有三种方式

1,直接使用,通过bean  type自动注入bean

@Resource
private UserMapper userMapper;

2,指定bean name

  @Resource(name = "userMapper")
    private UserMapper userMapper;

3,指定bean type

    @Resource(type = com.example.mybatis.mapper.UserMapper.class)
    private UserMapper userMapper;

你可能感兴趣的:(Springboot)