springboot注解RedisCacheServiceImpl报错

引入

@Autowired
    private RedisCacheServiceImpl redisCacheServiceImpl;

报错如下:

Description:

The bean 'redisCacheService' could not be injected as a 'com.cmos.cache.service.impl.RedisCacheServiceImpl' because it is a JDK dynamic proxy that implements:

  下面先说解决办法:

方法一:

将引入的

@Autowired
    private RedisCacheServiceImpl redisCacheServiceImpl;


替换为

@Autowired
    private ICacheService redisCacheServiceImpl;

 方法二:参考网址:http://blog.csdn.net/huang_550/article/details/76492600 

即在ServiceApplication.java启动主方法上面引入注解

@EnableTransactionManagement(proxyTargetClass = true)  引入后如下图
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.EnableAspectJAutoProxy;
import org.springframework.transaction.annotation.EnableTransactionManagement;

import com.cmos.common.annotation.EnableDataSource;
import com.cmos.common.annotation.EnableTransaction;
import com.cmos.common.spring.ApplicationStarter;
import com.cmos.core.logger.interceptor.EnableLog4xComponent;

@Configuration
@EnableTransactionManagement(proxyTargetClass = true)  
@SpringBootApplication
@EnableAspectJAutoProxy
@EnableAutoConfiguration
@EnableDataSource
@EnableTransaction
@EnableLog4xComponent
@ComponentScan(basePackages = {"com.cmos.mp","com.cmos.cache"})
public class ServiceApplication {

    public static void main(String[] args) throws Exception
    {
        ApplicationStarter.startApplication(ServiceApplication.class, args);
    }

}

两种方法都可以解决问题。

 

 

 

下面分析一下原因:

对比RedisCacheServiceImpl和ICacheService:

public class RedisCacheServiceImpl extends AbstractCacheService
{
略
}
public interface ICacheService
{
略
}
RedisCacheServiceImpl 是作为类继承了AbstractCacheService类,而ICacheService是一个接口

 

转载于:https://www.cnblogs.com/lchzlp/p/8547993.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值