通过spring配置文件方式消费dubbo服务,在servlet中注入了该dubbo服务,报代理错误
- [x] I have searched the issues of this repository and believe that this is not a duplicate.
- [x] I have checked the FAQ of this repository and believe that this is not a duplicate.
test
- Dubbo version: 2.7.0
- Operating System version:
- Java version: 1.8
Steps to reproduce this issue
- 通过spring配置文件方式消费dubbo服务 2.在servlet中注入了该dubbo服务
- 服务启动报错,报could not generate CGLIB subclass of class org.apache.dubbo.common.bytecode.proxy0;common causes of this problem include using a final class or a non-visible class
如果把服务消费reference的配置改为饥饿加载init=“true”,则启动不报错。 是什么原因导致
Pls. provide [GitHub address] to reproduce this issue.
Expected Result
What do you expected from the above steps?
Actual Result
What actually happens?
If there is an exception, please attach the exception trace:
Just put your stack trace here!
Can you provide a demo to reproduce this issue?
Can you provide a demo to reproduce this issue?
[#770]跟这个问题类似,差别在于没有使用注解的方式,通过<dubbo:reference >方式消费服务,并通过@Autowired的方式注入到servlet中
如果没记错的话,servlet默认不属于spring容器的bean, 所以你这个注解是不被扫描的。 可以将这个servlet使用spring的方式 ServletRegistrationBean 来把这个servlet注册到spring容器里
Originally posted by @Gonzo-Tan in https://github.com/apache/incubator-dubbo/issues/770#issuecomment-339541534
那这个回复能解答你的疑问吗
如果没记错的话,servlet默认不属于spring容器的bean, 所以你这个注解是不被扫描的。 可以将这个servlet使用spring的方式 ServletRegistrationBean 来把这个servlet注册到spring容器里
Originally posted by @Gonzo-Tan in #770 (comment)
那这个回复能解答你的疑问吗
跟我的问题有点差异。我的是非注解方式,且如果通过配置饥饿加载可以注入。非饥饿加载Spring代理报无法继承final类无法进行字节码增强
servlet 注入 spring bean 请参考 https://github.com/kexianjun/dubbo-test/blob/master/dubbo-issue-3827/issue-3827-comsumer/src/main/java/issue/test/servlet/WorkServlet.java
使用lazy的得到的结果是你的接口单独被代理,而不是dubbo出来的proxy,这意味着你二次代理的对象不在是org.apache.dubbo.common.bytecode.proxy0。之后在你真正调用方法的时候才会引用到你的dubboproxy
@Alfred-Wong ,添加proxy=jdk应该可以解决你的问题
具体原因是啥啊?
一样的问题,@DubboReference(proxy = "jdk")可以解决 stackTrace:
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'customExceptionTranslationFilter': Injection of @DubboReference dependencies is failed; nested exception is org.springframework.aop.framework.AopConfigException: Could not generate CGLIB subclass of class org.apache.dubbo.common.bytecode.proxy1: Common causes of this problem include using a final class or a non-visible class; nested exception is org.springframework.cglib.core.CodeGenerationException: java.lang.NoClassDefFoundError-->org/apache/dubbo/common/bytecode/proxy1
at com.alibaba.spring.beans.factory.annotation.AbstractAnnotationBeanPostProcessor.postProcessPropertyValues(AbstractAnnotationBeanPostProcessor.java:183)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1430)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:593)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:516)
at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:324)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:234)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:322)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:207)