Intellij IDEA tips error when injecting MyBatis mapper Java interface using @Autowired

Background

Intellij IDEA tips inspection error when injecting MyBatis mapper Java interface using @Autowired

@Autowired
private MyMapper mapper;

Error Info

Could not autowire. No beans of 'MyMapper' type found.

Solutions

It is not really an error, but error tips are annoying.

Solution 1: Add @Repository or @Component annotation in top of MyBatis Mapper interface classes.

@Repository
public interface MyMapper {}

Solution 2: Using @Resource annotation to inject MyBatis Mapper interface classes.

@Resouce
private MyMapper mapper;

References

[1] Idea inspects batis mapper bean wrong