问题描述:在controller中注入了另一个controller,按理说,三个注解controller、service、respository都是component衍生而来,任何被注入容器中的bean都可以以同样方式获取,但是在使用springboot项目时,controller中注入另一个controller发现失败。改成注入service成功。
报错:
2020-12-08 15:17:18.812 WARN 12352 — [ main] ConfigServletWebServerApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.BeanCreationException: Error creating bean with name ‘testController’: Injection of @DubboReference dependencies is failed; nested exception is java.lang.IllegalArgumentException: @Service interfaceClass() or interfaceName() or interface class must be present!
2020-12-08 15:17:18.813 INFO 12352 — [ main] f.a.ReferenceAnnotationBeanPostProcessor : org.apache.dubbo.common.bytecode.proxy11@1410d645 was destroying!
2020-12-08 15:17:18.814 INFO 12352 — [ main] f.a.ReferenceAnnotationBeanPostProcessor : org.apache.dubbo.common.bytecode.proxy9@4ccdacf5 was destroying!
2020-12-08 15:17:18.814 INFO 12352 — [ main] f.a.ReferenceAnnotationBeanPostProcessor : org.apache.dubbo.common.bytecode.proxy6@5aa6da2 was destroying!
2020-12-08 15:17:18.814 INFO 12352 — [ main] f.a.ReferenceAnnotationBeanPostProcessor : org.apache.dubbo.common.bytecode.proxy0@1a0d313 was destroying!
2020-12-08 15:17:18.814 INFO 12352 — [ main] f.a.ReferenceAnnotationBeanPostProcessor : org.apache.dubbo.common.bytecode.proxy8@13908f9c was destroying!
2020-12-08 15:17:18.815 INFO 12352 — [ main] f.a.ReferenceAnnotationBeanPostProcessor : org.apache.dubbo.common.bytecode.proxy6@5aa6da2 was destroying!
2020-12-08 15:17:18.815 INFO 12352 — [ main] f.a.ReferenceAnnotationBeanPostProcessor : org.apache.dubbo.common.bytecode.proxy15@329b331f was destroying!
2020-12-08 15:17:18.815 INFO 12352 — [ main] f.a.ReferenceAnnotationBeanPostProcessor : org.apache.dubbo.common.bytecode.proxy7@640a8f93 was destroying!
2020-12-08 15:17:18.815 INFO 12352 — [ main] f.a.ReferenceAnnotationBeanPostProcessor : org.apache.dubbo.common.bytecode.proxy4@6335f04a was destroying!
2020-12-08 15:17:18.815 INFO 12352 — [ main] f.a.ReferenceAnnotationBeanPostProcessor : org.apache.dubbo.common.bytecode.proxy9@4ccdacf5 was destroying!
2020-12-08 15:17:18.816 INFO 12352 — [ main] f.a.ReferenceAnnotationBeanPostProcessor : org.apache.dubbo.common.bytecode.proxy5@74ce7fdf was destroying!
2020-12-08 15:17:18.816 INFO 12352 — [ main] f.a.ReferenceAnnotationBeanPostProcessor : org.apache.dubbo.common.bytecode.proxy14@1f26b992 was destroying!
2020-12-08 15:17:18.816 INFO 12352 — [ main] f.a.ReferenceAnnotationBeanPostProcessor : org.apache.dubbo.common.bytecode.proxy10@2f60cbf2 was destroying!
2020-12-08 15:17:18.816 INFO 12352 — [ main] f.a.ReferenceAnnotationBeanPostProcessor : org.apache.dubbo.common.bytecode.proxy17@631bc9f4 was destroying!
2020-12-08 15:17:18.817 INFO 12352 — [ main] f.a.ReferenceAnnotationBeanPostProcessor : org.apache.dubbo.common.bytecode.proxy12@642c72cf was destroying!
2020-12-08 15:17:18.817 INFO 12352 — [ main] f.a.ReferenceAnnotationBeanPostProcessor : org.apache.dubbo.common.bytecode.proxy16@4e6cbdf1 was destroying!
2020-12-08 15:17:18.817 INFO 12352 — [ main] f.a.ReferenceAnnotationBeanPostProcessor : org.apache.dubbo.common.bytecode.proxy3@67fac095 was destroying!
2020-12-08 15:17:18.818 INFO 12352 — [ main] f.a.ReferenceAnnotationBeanPostProcessor : org.apache.dubbo.common.bytecode.proxy2@5a13f1f7 was destroying!
2020-12-08 15:17:18.818 INFO 12352 — [ main] f.a.ReferenceAnnotationBeanPostProcessor : org.apache.dubbo.common.bytecode.proxy13@5dae5a70 was destroying!
2020-12-08 15:17:18.819 INFO 12352 — [ main] f.a.ReferenceAnnotationBeanPostProcessor : org.apache.dubbo.common.bytecode.proxy1@7686f701 was destroying!
2020-12-08 15:17:18.819 INFO 12352 — [ main] f.a.ReferenceAnnotationBeanPostProcessor : org.apache.dubbo.common.bytecode.proxy8@13908f9c was destroying!
2020-12-08 15:17:18.819 INFO 12352 — [ main] f.a.ReferenceAnnotationBeanPostProcessor : org.apache.dubbo.common.bytecode.proxy9@4ccdacf5 was destroying!
2020-12-08 15:17:18.820 INFO 12352 — [ main] f.a.ReferenceAnnotationBeanPostProcessor : class org.apache.dubbo.config.spring.beans.factory.annotation.ReferenceAnnotationBeanPostProcessor was destroying!
2020-12-08 15:17:18.828 INFO 12352 — [ main] o.apache.catalina.core.StandardService : Stopping service [Tomcat]
2020-12-08 15:17:18.837 ERROR 12352 — [ main] o.a.c.c.C.[Tomcat].[localhost].[/] : Failed to destroy the filter named [Tomcat WebSocket (JSR356) Filter] of type [org.apache.tomcat.websocket.server.WsFilter]
java.lang.AbstractMethodError: null
at org.apache.catalina.core.ApplicationFilterConfig.release(ApplicationFilterConfig.java:301)
问题原因:使用了@Reference去注入对象了,Reference是dubbo的一种注解,作用是注入dubbo容器中对象,dubbo容器与spring容器自然不是一个容器,不可以混用,这里想要controller调用controller只需使用spring的注解@Autowired注解即可
改成service成功原因:@service注解也是dubbo的注解,@Reference注入的就是使用了dubbo的@Service的类的对象。故可以正常使用。
深思:以前学习过boot原理,已经很模糊,需要复习了
一个项目的启动就会有一个spring的容器(不是一个看做一个好了),其他的项目自然是调用不到该容器中的bean了,所以分布式项目中是没有机会使用controller调用controller的了,根本不在一个容器中啊,咋注入。