引入
@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是一个接口