加载中……

idea中使用maven+ssm自动注入时报错org.springframework.beans.ConversionNotSupportedException: Failed to convert

1、报错:


org.springframework.beans.ConversionNotSupportedException: Failed to convert value of type 'com.sun.proxy.$Proxy20 implementing com.whz.edu.base.IBaseService,org.springframework.aop.SpringProxy,org.springframework.aop.framework.Advised,org.springframework.core.DecoratingProxy' to required type 'com.whz.edu.base.BaseServiceImpl'; nested exception is java.lang.IllegalStateException: Cannot convert value of type 'com.sun.proxy.$Proxy20 implementing com.whz.edu.base.IBaseService,org.springframework.aop.SpringProxy,org.springframework.aop.framework.Advised,org.springframework.core.DecoratingProxy' to required type 'com.whz.edu.base.BaseServiceImpl': no matching editors or conversion strategy found

2、原因:

在controller中调用service层时需要使用接口编程。

3、解决:

service层结构:

1、抽取出基类

public interface IBaseService<T> {
    public T findById(Integer id);
    public void deleteById(Integer id);
    public void update(T t);
    public void insert(T t);
}

2、基类实现类:

public abstract class BaseServiceImpl<T> implements IBaseService<T>{
    //统一管理bean,自动注入
    @Autowired
    protected UserMapper userMapper;
}

 3、定义controller层需要调用的接口:

public interface IUserService extends IBaseService<User> {
    //可以在这儿定义特有的方法
    public User login(String username, String password);
}

4、controller层需要调用的接口实现类:

@Service
@Transactional
public class UserServiceImpl extends BaseServiceImpl<User> implements IUserService{
    @Override
    public User findById(Integer id) {
        return userMapper.findById(id);
    }

    @Override
    public void deleteById(Integer id) {

    }

    @Override
    public void update(User user) {

    }

    @Override
    public void insert(User user) {

    }

    @Override
    public User login(String username, String password) {
        return null;
    }
}

 

posted @ 2019-03-24 22:34  一泓清泉,一叶扁舟  阅读(169)  评论(0)    收藏  举报