nested exception is org.springframework.beans.factory.BeanNotOfRequiredTypeException(SpringMVC)

出现nested exception is org.springframework.beans.factory.BeanNotOfRequiredTypeException的原因是,给类使用注解,没使用动态代理

例如:

/**
 * 用户信息管理Mapper
 */
public interface UserMapper {

    int addUser(User user);

    @Select("select * from db.User where CompanyId=#{CompanyId}")
    User queryUser(int CompanyId);

    @Select("select * from db.User")
    List<User> queryUsers();
}
@Service
public class UserServiceImpl implements UserService {

    @Autowired
    private UserMapper userMapper;

    @Override
    public boolean addUser(User user) {
        return userMapper.addUser(user) > 0;
    }
}

  

 

解决一:配置AspectJ

<!--aspectj配置-->
    <aop:aspectj-autoproxy proxy-target-class="true"/>

解决二:配置事务annotation

<!--配置事务annotation-->
    <tx:annotation-driven proxy-target-class="true"/>

 

posted @ 2017-09-19 16:06  猴子1  阅读(3183)  评论(0编辑  收藏  举报