关于springboot整合dubbo时找不到service类的问题

在做spring整合dubbo项目时候,将服务接口和实体类写进一个普通的Maven工程,在服务提供者中继承服务接口,在消费者中调用zookeeper注册中心的服务。在依次启动了zookeeper和提供者都没报错,但在启动消费者时候报错:

2022-03-10 21:09:20.286  INFO 18292 --- [           main] com.longtong.Application                 : Starting Application using Java 1.8.0_60 on LONGTONG with PID 18292 (E:\Java\IntelliJ IDEA 2019.3.3\longtong_SpringBoot\024_consumer\target\classes started by SAMSUNG in E:\Java\IntelliJ IDEA 2019.3.3\longtong_SpringBoot)
2022-03-10 21:09:20.288  INFO 18292 --- [           main] com.longtong.Application                 : No active profile set, falling back to 1 default profile: "default"
2022-03-10 21:09:20.683  INFO 18292 --- [           main] com.alibaba.spring.util.BeanRegistrar    : The Infrastructure bean definition [Root bean: class [org.apache.dubbo.config.spring.beans.factory.annotation.ReferenceAnnotationBeanPostProcessor]; scope=; abstract=false; lazyInit=null; autowireMode=0; dependencyCheck=0; autowireCandidate=true; primary=false; factoryBeanName=null; factoryMethodName=null; initMethodName=null; destroyMethodName=nullwith name [referenceAnnotationBeanPostProcessor] has been registered.
2022-03-10 21:09:20.684  INFO 18292 --- [           main] com.alibaba.spring.util.BeanRegistrar    : The Infrastructure bean definition [Root bean: class [org.apache.dubbo.config.spring.beans.factory.annotation.DubboConfigAliasPostProcessor]; scope=; abstract=false; lazyInit=null; autowireMode=0; dependencyCheck=0; autowireCandidate=true; primary=false; factoryBeanName=null; factoryMethodName=null; initMethodName=null; destroyMethodName=nullwith name [dubboConfigAliasPostProcessor] has been registered.
2022-03-10 21:09:20.685  INFO 18292 --- [           main] com.alibaba.spring.util.BeanRegistrar    : The Infrastructure bean definition [Root bean: class [org.apache.dubbo.config.spring.context.DubboLifecycleComponentApplicationListener]; scope=; abstract=false; lazyInit=null; autowireMode=0; dependencyCheck=0; autowireCandidate=true; primary=false; factoryBeanName=null; factoryMethodName=null; initMethodName=null; destroyMethodName=nullwith name [dubboLifecycleComponentApplicationListener] has been registered.
2022-03-10 21:09:20.685  INFO 18292 --- [           main] com.alibaba.spring.util.BeanRegistrar    : The Infrastructure bean definition [Root bean: class [org.apache.dubbo.config.spring.context.DubboBootstrapApplicationListener]; scope=; abstract=false; lazyInit=null; autowireMode=0; dependencyCheck=0; autowireCandidate=true; primary=false; factoryBeanName=null; factoryMethodName=null; initMethodName=null; destroyMethodName=nullwith name [dubboBootstrapApplicationListener] has been registered.
2022-03-10 21:09:20.686  INFO 18292 --- [           main] com.alibaba.spring.util.BeanRegistrar    : The Infrastructure bean definition [Root bean: class [org.apache.dubbo.config.spring.beans.factory.config.DubboConfigDefaultPropertyValueBeanPostProcessor]; scope=; abstract=false; lazyInit=null; autowireMode=0; dependencyCheck=0; autowireCandidate=true; primary=false; factoryBeanName=null; factoryMethodName=null; initMethodName=null; destroyMethodName=nullwith name [dubboConfigDefaultPropertyValueBeanPostProcessor] has been registered.
2022-03-10 21:09:20.895  INFO 18292 --- [           main] .b.f.a.ConfigurationBeanBindingRegistrar : The configuration bean definition [name : org.apache.dubbo.config.ApplicationConfig#0, content : Root bean: class [org.apache.dubbo.config.ApplicationConfig]; scope=; abstract=false; lazyInit=null; autowireMode=0; dependencyCheck=0; autowireCandidate=true; primary=false; factoryBeanName=null; factoryMethodName=null; initMethodName=null; destroyMethodName=null] has been registered.
2022-03-10 21:09:20.895  INFO 18292 --- [           main] com.alibaba.spring.util.BeanRegistrar    : The Infrastructure bean definition [Root bean: class [com.alibaba.spring.beans.factory.annotation.ConfigurationBeanBindingPostProcessor]; scope=; abstract=false; lazyInit=null; autowireMode=0; dependencyCheck=0; autowireCandidate=true; primary=false; factoryBeanName=null; factoryMethodName=null; initMethodName=null; destroyMethodName=nullwith name [configurationBeanBindingPostProcessor] has been registered.
2022-03-10 21:09:20.895  INFO 18292 --- [           main] .b.f.a.ConfigurationBeanBindingRegistrar : The configuration bean definition [name : org.apache.dubbo.config.RegistryConfig#0, content : Root bean: class [org.apache.dubbo.config.RegistryConfig]; scope=; abstract=false; lazyInit=null; autowireMode=0; dependencyCheck=0; autowireCandidate=true; primary=false; factoryBeanName=null; factoryMethodName=null; initMethodName=null; destroyMethodName=null] has been registered.
2022-03-10 21:09:23.091  INFO 18292 --- [           main] o.s.c.a.ConfigurationClassPostProcessor  : Cannot enhance @Configuration bean definition 'org.apache.dubbo.spring.boot.autoconfigure.DubboAutoConfiguration' since its singleton instance has been created too early. The typical cause is a non-static @Bean method with a BeanDefinitionRegistryPostProcessor return type: Consider declaring such methods as 'static'.
2022-03-10 21:09:23.434  INFO 18292 --- [           main] o.s.b.w.embedded.tomcat.TomcatWebServer  : Tomcat initialized with port(s): 8080 (http)
2022-03-10 21:09:23.442  INFO 18292 --- [           main] o.apache.catalina.core.StandardService   : Starting service [Tomcat]
2022-03-10 21:09:23.442  INFO 18292 --- [           main] org.apache.catalina.core.StandardEngine  : Starting Servlet engine: [Apache Tomcat/9.0.58]
2022-03-10 21:09:23.521  INFO 18292 --- [           main] o.a.c.c.C.[Tomcat].[localhost].[/]       : Initializing Spring embedded WebApplicationContext
2022-03-10 21:09:23.521  INFO 18292 --- [           main] w.s.c.ServletWebServerApplicationContext : Root WebApplicationContext: initialization completed in 3187 ms
2022-03-10 21:09:23.612  WARN 18292 --- [           main] ConfigServletWebServerApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'studentController': Injection of resource dependencies failed; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 'com.longtong.service.StudentService' available: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: {@javax.annotation.Resource(shareable=true, lookup=, name=, description=, authenticationType=CONTAINER, type=class java.lang.Object, mappedName=), @org.apache.dubbo.config.annotation.DubboReference(cluster=, methods=[], lazy=false, listener=[], loadbalance=, callbacks=0, onconnect=, timeout=0, layer=, protocol=, reconnect=, ondisconnect=, stub=, client=, id=, tag=, interfaceName=, consumer=, connections=0, validation=, group=, owner=, init=false, registry=[], cache=, module=, injvm=true, monitor=, check=true, services=[], stubevent=false, version=1.0, actives=0, sent=false, generic=false, url=, filter=[], proxy=, retries=2, async=false, interfaceClass=interface com.longtong.service.StudentService, application=, sticky=false, mock=, parameters=[], merger=)}
2022-03-10 21:09:23.612  INFO 18292 --- [           main] f.a.ReferenceAnnotationBeanPostProcessor : class org.apache.dubbo.config.spring.beans.factory.annotation.ReferenceAnnotationBeanPostProcessor was destroying!
2022-03-10 21:09:23.614  INFO 18292 --- [           main] o.apache.catalina.core.StandardService   : Stopping service [Tomcat]
2022-03-10 21:09:23.625  INFO 18292 --- [           main] ConditionEvaluationReportLoggingListener : 

Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.
2022-03-10 21:09:23.643 ERROR 18292 --- [           main] o.s.b.d.LoggingFailureAnalysisReporter   : 

***************************
APPLICATION FAILED TO START
***************************

Description:

A component required a bean of type 'com.longtong.service.StudentService' that could not be found.


Action:

Consider defining a bean of type 'com.longtong.service.StudentService' in your configuration.

 显而易见,是在控制层类下没能成功调用服务类。我最先考虑到的是配置文件可能扫描包路径不对。反复巡查后,发现没有什么问题,然后就是几个小时过去了。。。。。。。。。。。

DubboReference是把远程服务对象当做spring容器中的对象一样注入。Resource和Autowired是把本地spring容器中的对象进行注入。所以这里不能用@Resource,而且这里写重复了,把这行删掉。 

最后,我扇了自己一巴掌。

猜你喜欢

转载自blog.csdn.net/m0_57545353/article/details/123411888