Contents
  1. 1. Background
  2. 2. Error Info
  3. 3. Solutions
  4. 4. References

Background

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

1
2
@Autowired
private MyMapper mapper;

Error Info

1
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.

1
2
@Repository
public interface MyMapper {}

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

1
2
@Resouce
private MyMapper mapper;

References

[1] Idea inspects batis mapper bean wrong

Contents
  1. 1. Background
  2. 2. Error Info
  3. 3. Solutions
  4. 4. References