Почему mapperScannerConfigurer не создает бин? - PullRequest
0 голосов
/ 03 мая 2020

Я использую

sts4
java8 
mybatis : 3.4.1
mybatis-spring : 1.3.0
spring project nature

Я создал annotationClass с именем Mapper и создал mapperScannerConfigurer для сканирования того, что имеет @ Mapper.

    <!-- MapperScannerCofigurer -->
<bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
    <property name="basePackage"  value="myspring.user.dao" />
    <property name="annotationClass" value="myspring.user.dao.Mapper" />
</bean>

Класс UserMapper

@Mapper
public interface UserMapper {
    UserVO selectUserById(String id);
    List<UserVO> selectUserList();
    void insertUser(UserVO userVO);
    void updateUser(UserVO userVO);
    void deleteUser(String id);
}

И я установил соединение UserMapper с помощью @autowired в UserDaoImplMapper.

@Repository("userDao")
public class UserDaoImplMapper implements UserDao {

    @Autowired
    private UserMapper userMapper;

    @Override
    public UserVO read(String id) {
        UserVO user = userMapper.selectUserById(id);
        return user;
    }

    @Override
    public void insert(UserVO user) {
        userMapper.insertUser(user);        
    }
}

Когда я проверяю это, я получаю следующую ошибку.

Caused by: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'userDao': Unsatisfied dependency expressed through field 'userMapper'; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 'myspring.user.dao.UserMapper' available: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}

Не так ли MapperScannerConfigur сканирует AnnotationClass для создания бина? Пожалуйста, помогите мне.

...