理论上只需要2个最核心的依赖
<dependency>
<groupId>org.apache.dubbogroupId>
<artifactId>dubbo-spring-boot-starterartifactId>
<version>${dubbo-spring-boot-starter.version}version>
dependency>
<dependency>
<groupId>com.alibaba.cloudgroupId>
<artifactId>spring-cloud-starter-alibaba-nacos-discoveryartifactId>
dependency>
但是dubbo会用到nacos-api,spring-cloud-starter-alibaba-nacos-discovery中依赖的nacos-client版本太低,需要单独指定nacos-client版本,否则在org.apache.dubbo:dubbo中使用nacos-api时会抛NoSuchMethodError,所以在pom中还需要添加
<dependency>
<groupId>com.alibaba.nacosgroupId>
<artifactId>nacos-clientartifactId>
<version>${nacos-client.version}version>
dependency>
2022-04-05 19:09:39.667 WARN 15740 --- [ main] o.a.d.c.deploy.FrameworkModelCleaner : [DUBBO] ExtensionDirector is destroyed, dubbo version: 3.0.6, current host: 192.168.1.4
java.lang.IllegalStateException: ExtensionDirector is destroyed
at org.apache.dubbo.common.extension.ExtensionDirector.checkDestroyed(ExtensionDirector.java:156) ~[dubbo-3.0.6.jar:3.0.6]
at org.apache.dubbo.common.extension.ExtensionDirector.getExtensionLoader(ExtensionDirector.java:67) ~[dubbo-3.0.6.jar:3.0.6]
at org.apache.dubbo.common.extension.ExtensionAccessor.getExtensionLoader(ExtensionAccessor.java:27) ~[dubbo-3.0.6.jar:3.0.6]
at org.apache.dubbo.rpc.model.ScopeModelUtil.getExtensionLoader(ScopeModelUtil.java:102) ~[dubbo-3.0.6.jar:3.0.6]
at org.apache.dubbo.registry.integration.RegistryProtocol.getRegistry(RegistryProtocol.java:391) ~[dubbo-3.0.6.jar:3.0.6]
at org.apache.dubbo.registry.integration.RegistryProtocol$ExporterChangeableWrapper.unexport(RegistryProtocol.java:892) ~[dubbo-3.0.6.jar:3.0.6]
at org.apache.dubbo.registry.integration.RegistryProtocol.destroy(RegistryProtocol.java:636) ~[dubbo-3.0.6.jar:3.0.6]
at org.apache.dubbo.rpc.protocol.ProtocolListenerWrapper.destroy(ProtocolListenerWrapper.java:89) ~[dubbo-3.0.6.jar:3.0.6]
at org.apache.dubbo.qos.protocol.QosProtocolWrapper.destroy(QosProtocolWrapper.java:90) ~[dubbo-3.0.6.jar:3.0.6]
at org.apache.dubbo.rpc.cluster.filter.ProtocolFilterWrapper.destroy(ProtocolFilterWrapper.java:79) ~[dubbo-3.0.6.jar:3.0.6]
at org.apache.dubbo.rpc.protocol.ProtocolSerializationWrapper.destroy(ProtocolSerializationWrapper.java:57) ~[dubbo-3.0.6.jar:3.0.6]
at org.apache.dubbo.config.deploy.FrameworkModelCleaner.destroyProtocols(FrameworkModelCleaner.java:55) ~[dubbo-3.0.6.jar:3.0.6]
at org.apache.dubbo.config.deploy.FrameworkModelCleaner.destroyFrameworkResources(FrameworkModelCleaner.java:43) ~[dubbo-3.0.6.jar:3.0.6]
at org.apache.dubbo.config.deploy.FrameworkModelCleaner.onDestroy(FrameworkModelCleaner.java:35) ~[dubbo-3.0.6.jar:3.0.6]
at org.apache.dubbo.config.deploy.FrameworkModelCleaner.onDestroy(FrameworkModelCleaner.java:29) ~[dubbo-3.0.6.jar:3.0.6]
at org.apache.dubbo.rpc.model.ScopeModel.notifyDestroy(ScopeModel.java:133) ~[dubbo-3.0.6.jar:3.0.6]
at org.apache.dubbo.rpc.model.FrameworkModel.onDestroy(FrameworkModel.java:125) ~[dubbo-3.0.6.jar:3.0.6]
at org.apache.dubbo.rpc.model.ScopeModel.destroy(ScopeModel.java:110) ~[dubbo-3.0.6.jar:3.0.6]
at org.apache.dubbo.rpc.model.FrameworkModel.tryDestroy(FrameworkModel.java:257) ~[dubbo-3.0.6.jar:3.0.6]
at org.apache.dubbo.rpc.model.ApplicationModel.onDestroy(ApplicationModel.java:277) ~[dubbo-3.0.6.jar:3.0.6]
at org.apache.dubbo.rpc.model.ScopeModel.destroy(ScopeModel.java:110) ~[dubbo-3.0.6.jar:3.0.6]
at org.apache.dubbo.rpc.model.ApplicationModel.tryDestroy(ApplicationModel.java:351) ~[dubbo-3.0.6.jar:3.0.6]
at org.apache.dubbo.rpc.model.ModuleModel.onDestroy(ModuleModel.java:124) ~[dubbo-3.0.6.jar:3.0.6]
at org.apache.dubbo.rpc.model.ScopeModel.destroy(ScopeModel.java:110) ~[dubbo-3.0.6.jar:3.0.6]
at org.apache.dubbo.config.spring.context.DubboDeployApplicationListener.onContextClosedEvent(DubboDeployApplicationListener.java:130) ~[dubbo-3.0.6.jar:3.0.6]
at org.apache.dubbo.config.spring.context.DubboDeployApplicationListener.onApplicationEvent(DubboDeployApplicationListener.java:102) ~[dubbo-3.0.6.jar:3.0.6]
at org.apache.dubbo.config.spring.context.DubboDeployApplicationListener.onApplicationEvent(DubboDeployApplicationListener.java:45) ~[dubbo-3.0.6.jar:3.0.6]
at org.springframework.context.event.SimpleApplicationEventMulticaster.doInvokeListener(SimpleApplicationEventMulticaster.java:176) ~[spring-context-5.3.18.jar:5.3.18]
at org.springframework.context.event.SimpleApplicationEventMulticaster.invokeListener(SimpleApplicationEventMulticaster.java:169) ~[spring-context-5.3.18.jar:5.3.18]
at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:143) ~[spring-context-5.3.18.jar:5.3.18]
at org.springframework.context.support.AbstractApplicationContext.publishEvent(AbstractApplicationContext.java:421) ~[spring-context-5.3.18.jar:5.3.18]
at org.springframework.context.support.AbstractApplicationContext.publishEvent(AbstractApplicationContext.java:378) ~[spring-context-5.3.18.jar:5.3.18]
at org.springframework.context.support.AbstractApplicationContext.doClose(AbstractApplicationContext.java:1058) ~[spring-context-5.3.18.jar:5.3.18]
at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.doClose(ServletWebServerApplicationContext.java:172) ~[spring-boot-2.6.6.jar:2.6.6]
at org.springframework.context.support.AbstractApplicationContext.close(AbstractApplicationContext.java:1021) ~[spring-context-5.3.18.jar:5.3.18]
at org.springframework.boot.builder.ParentContextCloserApplicationListener$ContextCloserListener.onApplicationEvent(ParentContextCloserApplicationListener.java:94) ~[spring-boot-2.6.6.jar:2.6.6]
at org.springframework.boot.builder.ParentContextCloserApplicationListener$ContextCloserListener.onApplicationEvent(ParentContextCloserApplicationListener.java:82) ~[spring-boot-2.6.6.jar:2.6.6]
at org.springframework.context.event.SimpleApplicationEventMulticaster.doInvokeListener(SimpleApplicationEventMulticaster.java:176) ~[spring-context-5.3.18.jar:5.3.18]
at org.springframework.context.event.SimpleApplicationEventMulticaster.invokeListener(SimpleApplicationEventMulticaster.java:169) ~[spring-context-5.3.18.jar:5.3.18]
at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:143) ~[spring-context-5.3.18.jar:5.3.18]
at org.springframework.context.support.AbstractApplicationContext.publishEvent(AbstractApplicationContext.java:421) ~[spring-context-5.3.18.jar:5.3.18]
at org.springframework.context.support.AbstractApplicationContext.publishEvent(AbstractApplicationContext.java:378) ~[spring-context-5.3.18.jar:5.3.18]
at org.springframework.context.support.AbstractApplicationContext.doClose(AbstractApplicationContext.java:1058) ~[spring-context-5.3.18.jar:5.3.18]
at org.springframework.context.support.AbstractApplicationContext.close(AbstractApplicationContext.java:1021) ~[spring-context-5.3.18.jar:5.3.18]
at org.springframework.cloud.bootstrap.BootstrapApplicationListener$CloseContextOnFailureApplicationListener.onApplicationEvent(BootstrapApplicationListener.java:497) ~[spring-cloud-context-3.1.1.jar:3.1.1]
at org.springframework.context.event.SimpleApplicationEventMulticaster.doInvokeListener(SimpleApplicationEventMulticaster.java:176) ~[spring-context-5.3.18.jar:5.3.18]
at org.springframework.context.event.SimpleApplicationEventMulticaster.invokeListener(SimpleApplicationEventMulticaster.java:169) ~[spring-context-5.3.18.jar:5.3.18]
at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:143) ~[spring-context-5.3.18.jar:5.3.18]
at org.springframework.context.support.AbstractApplicationContext.publishEvent(AbstractApplicationContext.java:421) ~[spring-context-5.3.18.jar:5.3.18]
at org.springframework.context.support.AbstractApplicationContext.publishEvent(AbstractApplicationContext.java:378) ~[spring-context-5.3.18.jar:5.3.18]
at org.springframework.boot.context.event.EventPublishingRunListener.failed(EventPublishingRunListener.java:124) ~[spring-boot-2.6.6.jar:2.6.6]
at org.springframework.boot.SpringApplicationRunListeners.callFailedListener(SpringApplicationRunListeners.java:96) ~[spring-boot-2.6.6.jar:2.6.6]
at org.springframework.boot.SpringApplicationRunListeners.lambda$failed$7(SpringApplicationRunListeners.java:87) ~[spring-boot-2.6.6.jar:2.6.6]
at java.base/java.util.ArrayList.forEach(ArrayList.java:1511) ~[na:na]
at org.springframework.boot.SpringApplicationRunListeners.doWithListeners(SpringApplicationRunListeners.java:120) ~[spring-boot-2.6.6.jar:2.6.6]
at org.springframework.boot.SpringApplicationRunListeners.failed(SpringApplicationRunListeners.java:86) ~[spring-boot-2.6.6.jar:2.6.6]
at org.springframework.boot.SpringApplication.handleRunFailure(SpringApplication.java:790) ~[spring-boot-2.6.6.jar:2.6.6]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:313) ~[spring-boot-2.6.6.jar:2.6.6]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1312) ~[spring-boot-2.6.6.jar:2.6.6]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1301) ~[spring-boot-2.6.6.jar:2.6.6]
at com.wen3.dubbonacos.DemoProviderApplication.main(DemoProviderApplication.java:15) ~[classes/:na]
2022-04-05 19:09:48.830 ERROR 15740 --- [ main] o.s.boot.SpringApplication : Application run failed
java.lang.IllegalStateException: No such extension org.apache.dubbo.rpc.Protocol by name rest, possible causes:
(1) rest=org.apache.dubbo.rpc.protocol.rest.RestProtocol:
java.lang.IllegalStateException: Failed to load extension class (interface: interface org.apache.dubbo.rpc.Protocol, class line: rest=org.apache.dubbo.rpc.protocol.rest.RestProtocol) in jar:file:/G:/repository/org/apache/dubbo/dubbo/3.0.6/dubbo-3.0.6.jar!/META-INF/dubbo/internal/org.apache.dubbo.rpc.Protocol, cause: org/jboss/resteasy/client/jaxrs/ClientHttpEngine
java.lang.IllegalStateException: Failed to load extension class (interface: interface org.apache.dubbo.rpc.Protocol, class line: rest=org.apache.dubbo.rpc.protocol.rest.RestProtocol) in jar:file:/G:/repository/org/apache/dubbo/dubbo/3.0.6/dubbo-3.0.6.jar!/META-INF/dubbo/internal/org.apache.dubbo.rpc.Protocol, cause: org/jboss/resteasy/client/jaxrs/ClientHttpEngine
at org.apache.dubbo.common.extension.ExtensionLoader.loadResource(ExtensionLoader.java:1052)
at org.apache.dubbo.common.extension.ExtensionLoader.loadFromClass(ExtensionLoader.java:1019)
at org.apache.dubbo.common.extension.ExtensionLoader.lambda$loadDirectory$4(ExtensionLoader.java:1007)
at java.base/java.util.LinkedHashMap.forEach(LinkedHashMap.java:721)
at java.base/java.util.Collections$UnmodifiableMap.forEach(Collections.java:1553)
at org.apache.dubbo.common.extension.ExtensionLoader.loadDirectory(ExtensionLoader.java:1006)
at org.apache.dubbo.common.extension.ExtensionLoader.loadDirectory(ExtensionLoader.java:943)
at org.apache.dubbo.common.extension.ExtensionLoader.loadExtensionClasses(ExtensionLoader.java:931)
at org.apache.dubbo.common.extension.ExtensionLoader.getExtensionClasses(ExtensionLoader.java:913)
at org.apache.dubbo.common.extension.ExtensionLoader.getAdaptiveExtensionClass(ExtensionLoader.java:1243)
at org.apache.dubbo.common.extension.ExtensionLoader.createAdaptiveExtension(ExtensionLoader.java:1231)
at org.apache.dubbo.common.extension.ExtensionLoader.getAdaptiveExtension(ExtensionLoader.java:713)
at org.apache.dubbo.config.ServiceConfig.postProcessAfterScopeModelChanged(ServiceConfig.java:154)
at org.apache.dubbo.config.AbstractConfig.setScopeModel(AbstractConfig.java:395)
at org.apache.dubbo.config.AbstractConfig.(AbstractConfig.java:117)
at org.apache.dubbo.config.AbstractMethodConfig.(AbstractMethodConfig.java:103)
at org.apache.dubbo.config.AbstractInterfaceConfig.(AbstractInterfaceConfig.java:192)
at org.apache.dubbo.config.AbstractServiceConfig.(AbstractServiceConfig.java:132)
at org.apache.dubbo.config.ServiceConfigBase.(ServiceConfigBase.java:84)
at org.apache.dubbo.config.ServiceConfig.(ServiceConfig.java:136)
at org.apache.dubbo.config.spring.ServiceBean.(ServiceBean.java:56)
at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:77)
at java.base/jdk.internal.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.base/java.lang.reflect.Constructor.newInstanceWithCaller(Constructor.java:499)
at java.base/java.lang.reflect.Constructor.newInstance(Constructor.java:480)
at org.springframework.beans.BeanUtils.instantiateClass(BeanUtils.java:211)
at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:87)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateBean(AbstractAutowireCapableBeanFactory.java:1326)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1232)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:582)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:542)
at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:335)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:234)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:333)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:208)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:953)
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:918)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:583)
at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:145)
at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:740)
at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:415)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:303)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1312)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1301)
at com.wen3.dubbonacos.DemoProviderApplication.main(DemoProviderApplication.java:15)
Caused by: java.lang.NoClassDefFoundError: org/jboss/resteasy/client/jaxrs/ClientHttpEngine
at java.base/java.lang.Class.forName0(Native Method)
at java.base/java.lang.Class.forName(Class.java:467)
at org.apache.dubbo.common.extension.ExtensionLoader.loadResource(ExtensionLoader.java:1048)
... 45 more
Caused by: java.lang.ClassNotFoundException: org.jboss.resteasy.client.jaxrs.ClientHttpEngine
at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:641)
at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:188)
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:520)
... 48 more
at org.apache.dubbo.common.extension.ExtensionLoader.findException(ExtensionLoader.java:747) ~[dubbo-3.0.6.jar:3.0.6]
at org.apache.dubbo.common.extension.ExtensionLoader.createExtension(ExtensionLoader.java:754) ~[dubbo-3.0.6.jar:3.0.6]
at org.apache.dubbo.common.extension.ExtensionLoader.getExtension(ExtensionLoader.java:548) ~[dubbo-3.0.6.jar:3.0.6]
at org.apache.dubbo.common.extension.ExtensionLoader.getExtension(ExtensionLoader.java:523) ~[dubbo-3.0.6.jar:3.0.6]
at org.apache.dubbo.config.ServiceConfig.findConfiguredPort(ServiceConfig.java:760) ~[dubbo-3.0.6.jar:3.0.6]
at org.apache.dubbo.config.ServiceConfig.buildUrl(ServiceConfig.java:543) ~[dubbo-3.0.6.jar:3.0.6]
at org.apache.dubbo.config.ServiceConfig.doExportUrlsFor1Protocol(ServiceConfig.java:398) ~[dubbo-3.0.6.jar:3.0.6]
at org.apache.dubbo.config.ServiceConfig.doExportUrls(ServiceConfig.java:386) ~[dubbo-3.0.6.jar:3.0.6]
at org.apache.dubbo.config.ServiceConfig.doExport(ServiceConfig.java:361) ~[dubbo-3.0.6.jar:3.0.6]
at org.apache.dubbo.config.ServiceConfig.export(ServiceConfig.java:233) ~[dubbo-3.0.6.jar:3.0.6]
at org.apache.dubbo.config.deploy.DefaultModuleDeployer.exportServiceInternal(DefaultModuleDeployer.java:338) ~[dubbo-3.0.6.jar:3.0.6]
at org.apache.dubbo.config.deploy.DefaultModuleDeployer.exportServices(DefaultModuleDeployer.java:310) ~[dubbo-3.0.6.jar:3.0.6]
at org.apache.dubbo.config.deploy.DefaultModuleDeployer.start(DefaultModuleDeployer.java:142) ~[dubbo-3.0.6.jar:3.0.6]
at org.apache.dubbo.config.spring.context.DubboDeployApplicationListener.onContextRefreshedEvent(DubboDeployApplicationListener.java:111) ~[dubbo-3.0.6.jar:3.0.6]
at org.apache.dubbo.config.spring.context.DubboDeployApplicationListener.onApplicationEvent(DubboDeployApplicationListener.java:100) ~[dubbo-3.0.6.jar:3.0.6]
at org.apache.dubbo.config.spring.context.DubboDeployApplicationListener.onApplicationEvent(DubboDeployApplicationListener.java:45) ~[dubbo-3.0.6.jar:3.0.6]
at org.springframework.context.event.SimpleApplicationEventMulticaster.doInvokeListener(SimpleApplicationEventMulticaster.java:176) ~[spring-context-5.3.18.jar:5.3.18]
at org.springframework.context.event.SimpleApplicationEventMulticaster.invokeListener(SimpleApplicationEventMulticaster.java:169) ~[spring-context-5.3.18.jar:5.3.18]
at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:143) ~[spring-context-5.3.18.jar:5.3.18]
at org.springframework.context.support.AbstractApplicationContext.publishEvent(AbstractApplicationContext.java:421) ~[spring-context-5.3.18.jar:5.3.18]
at org.springframework.context.support.AbstractApplicationContext.publishEvent(AbstractApplicationContext.java:378) ~[spring-context-5.3.18.jar:5.3.18]
at org.springframework.context.support.AbstractApplicationContext.finishRefresh(AbstractApplicationContext.java:938) ~[spring-context-5.3.18.jar:5.3.18]
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:586) ~[spring-context-5.3.18.jar:5.3.18]
at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:145) ~[spring-boot-2.6.6.jar:2.6.6]
at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:740) ~[spring-boot-2.6.6.jar:2.6.6]
at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:415) ~[spring-boot-2.6.6.jar:2.6.6]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:303) ~[spring-boot-2.6.6.jar:2.6.6]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1312) ~[spring-boot-2.6.6.jar:2.6.6]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1301) ~[spring-boot-2.6.6.jar:2.6.6]
at com.wen3.dubbonacos.DemoProviderApplication.main(DemoProviderApplication.java:15) ~[classes/:na]
把dubbo服务注册到nacos,如果nacos开启了权限认证,那么springboot应用的配置文件在写dubbo配置项时,需要指定用户名和密码,如果这样指定是无效的
dubbo:
registry:
address: nacos://localhost:8848
username: nacos
password: nacos
这样在启动时,dubbo向nacos注册服务会报403 unknown user的错误。
2022-04-05 19:09:28.389 WARN 15740 --- [ main] o.a.dubbo.registry.nacos.NacosRegistry : [DUBBO] Failed to unregister url dubbo://192.168.1.4:20880/org.apache.dubbo.metadata.MetadataService?anyhost=true&application=provider1&background=false&connections=1&delay=0&deprecated=false&dubbo=2.0.2&dynamic=true&executes=100&generic=false&group=provider1&interface=org.apache.dubbo.metadata.MetadataService&metadata-type=remote&methods=getMetadataURL,isMetadataService,getExportedURLs,serviceName,version,getSubscribedURLs,getExportedServiceURLs,getMetadataInfo,toSortedStrings,getMetadataInfos,getServiceDefinition&pid=15740&release=3.0.6&revision=3.0.6&service-name-mapping=true&side=provider×tamp=1649156966499&version=1.0.0 to registry nacos://localhost:8848/org.apache.dubbo.registry.RegistryService?application=provider1&dubbo=2.0.2&group=demo-provider&interface=org.apache.dubbo.registry.RegistryService&pid=15740&qos.enable=false&release=3.0.6&server=localhost on destroy, cause: Failed to unregister dubbo://192.168.1.4:20880/org.apache.dubbo.metadata.MetadataService?anyhost=true&application=provider1&background=false&connections=1&delay=0&deprecated=false&dubbo=2.0.2&dynamic=true&executes=100&generic=false&group=provider1&interface=org.apache.dubbo.metadata.MetadataService&metadata-type=remote&methods=getMetadataURL,isMetadataService,getExportedURLs,serviceName,version,getSubscribedURLs,getExportedServiceURLs,getMetadataInfo,toSortedStrings,getMetadataInfos,getServiceDefinition&pid=15740&release=3.0.6&revision=3.0.6&service-name-mapping=true&side=provider×tamp=1649156966499&version=1.0.0 to registry localhost:8848, cause: Failed to unregister dubbo://192.168.1.4:20880/org.apache.dubbo.metadata.MetadataService?anyhost=true&application=provider1&background=false&connections=1&delay=0&deprecated=false&dubbo=2.0.2&dynamic=true&executes=100&generic=false&group=provider1&interface=org.apache.dubbo.metadata.MetadataService&metadata-type=remote&methods=getMetadataURL,isMetadataService,getExportedURLs,serviceName,version,getSubscribedURLs,getExportedServiceURLs,getMetadataInfo,toSortedStrings,getMetadataInfos,getServiceDefinition&pid=15740&release=3.0.6&revision=3.0.6&service-name-mapping=true&side=provider×tamp=1649156966499&version=1.0.0 to nacos nacos://localhost:8848/org.apache.dubbo.registry.RegistryService?application=provider1&dubbo=2.0.2&group=demo-provider&interface=org.apache.dubbo.registry.RegistryService&pid=15740&qos.enable=false&release=3.0.6&server=localhost, cause: failed to req API:/nacos/v1/ns/instance after all servers([localhost:8848]) tried: ErrCode:403, ErrMsg:Whitelabel Error Page
This application has no explicit mapping for /error, so you are seeing this as a fallback.
Tue Apr 05 19:09:28 CST 2022There was an unexpected error (type=Forbidden, status=403).unknown user!, dubbo version: 3.0.6, current host: 192.168.1.4
java.lang.IllegalStateException: Failed to unregister dubbo://192.168.1.4:20880/org.apache.dubbo.metadata.MetadataService?anyhost=true&application=provider1&background=false&connections=1&delay=0&deprecated=false&dubbo=2.0.2&dynamic=true&executes=100&generic=false&group=provider1&interface=org.apache.dubbo.metadata.MetadataService&metadata-type=remote&methods=getMetadataURL,isMetadataService,getExportedURLs,serviceName,version,getSubscribedURLs,getExportedServiceURLs,getMetadataInfo,toSortedStrings,getMetadataInfos,getServiceDefinition&pid=15740&release=3.0.6&revision=3.0.6&service-name-mapping=true&side=provider×tamp=1649156966499&version=1.0.0 to registry localhost:8848, cause: Failed to unregister dubbo://192.168.1.4:20880/org.apache.dubbo.metadata.MetadataService?anyhost=true&application=provider1&background=false&connections=1&delay=0&deprecated=false&dubbo=2.0.2&dynamic=true&executes=100&generic=false&group=provider1&interface=org.apache.dubbo.metadata.MetadataService&metadata-type=remote&methods=getMetadataURL,isMetadataService,getExportedURLs,serviceName,version,getSubscribedURLs,getExportedServiceURLs,getMetadataInfo,toSortedStrings,getMetadataInfos,getServiceDefinition&pid=15740&release=3.0.6&revision=3.0.6&service-name-mapping=true&side=provider×tamp=1649156966499&version=1.0.0 to nacos nacos://localhost:8848/org.apache.dubbo.registry.RegistryService?application=provider1&dubbo=2.0.2&group=demo-provider&interface=org.apache.dubbo.registry.RegistryService&pid=15740&qos.enable=false&release=3.0.6&server=localhost, cause: failed to req API:/nacos/v1/ns/instance after all servers([localhost:8848]) tried: ErrCode:403, ErrMsg:Whitelabel Error Page
This application has no explicit mapping for /error, so you are seeing this as a fallback.
Tue Apr 05 19:09:28 CST 2022There was an unexpected error (type=Forbidden, status=403).unknown user!
at org.apache.dubbo.registry.support.FailbackRegistry.unregister(FailbackRegistry.java:266) ~[dubbo-3.0.6.jar:3.0.6]
at org.apache.dubbo.registry.support.AbstractRegistry.destroy(AbstractRegistry.java:496) ~[dubbo-3.0.6.jar:3.0.6]
at org.apache.dubbo.registry.support.FailbackRegistry.destroy(FailbackRegistry.java:407) ~[dubbo-3.0.6.jar:3.0.6]
at org.apache.dubbo.registry.support.RegistryManager.destroyAll(RegistryManager.java:105) ~[dubbo-3.0.6.jar:3.0.6]
at org.apache.dubbo.config.deploy.DefaultApplicationDeployer.destroyRegistries(DefaultApplicationDeployer.java:1009) ~[dubbo-3.0.6.jar:3.0.6]
at org.apache.dubbo.config.deploy.DefaultApplicationDeployer.postDestroy(DefaultApplicationDeployer.java:775) ~[dubbo-3.0.6.jar:3.0.6]
at org.apache.dubbo.rpc.model.ApplicationModel.onDestroy(ApplicationModel.java:257) ~[dubbo-3.0.6.jar:3.0.6]
at org.apache.dubbo.rpc.model.ScopeModel.destroy(ScopeModel.java:110) ~[dubbo-3.0.6.jar:3.0.6]
at org.apache.dubbo.rpc.model.ApplicationModel.tryDestroy(ApplicationModel.java:351) ~[dubbo-3.0.6.jar:3.0.6]
at org.apache.dubbo.rpc.model.ModuleModel.onDestroy(ModuleModel.java:124) ~[dubbo-3.0.6.jar:3.0.6]
at org.apache.dubbo.rpc.model.ScopeModel.destroy(ScopeModel.java:110) ~[dubbo-3.0.6.jar:3.0.6]
at org.apache.dubbo.config.spring.context.DubboDeployApplicationListener.onContextClosedEvent(DubboDeployApplicationListener.java:130) ~[dubbo-3.0.6.jar:3.0.6]
at org.apache.dubbo.config.spring.context.DubboDeployApplicationListener.onApplicationEvent(DubboDeployApplicationListener.java:102) ~[dubbo-3.0.6.jar:3.0.6]
at org.apache.dubbo.config.spring.context.DubboDeployApplicationListener.onApplicationEvent(DubboDeployApplicationListener.java:45) ~[dubbo-3.0.6.jar:3.0.6]
at org.springframework.context.event.SimpleApplicationEventMulticaster.doInvokeListener(SimpleApplicationEventMulticaster.java:176) ~[spring-context-5.3.18.jar:5.3.18]
at org.springframework.context.event.SimpleApplicationEventMulticaster.invokeListener(SimpleApplicationEventMulticaster.java:169) ~[spring-context-5.3.18.jar:5.3.18]
at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:143) ~[spring-context-5.3.18.jar:5.3.18]
at org.springframework.context.support.AbstractApplicationContext.publishEvent(AbstractApplicationContext.java:421) ~[spring-context-5.3.18.jar:5.3.18]
at org.springframework.context.support.AbstractApplicationContext.publishEvent(AbstractApplicationContext.java:378) ~[spring-context-5.3.18.jar:5.3.18]
at org.springframework.context.support.AbstractApplicationContext.doClose(AbstractApplicationContext.java:1058) ~[spring-context-5.3.18.jar:5.3.18]
at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.doClose(ServletWebServerApplicationContext.java:172) ~[spring-boot-2.6.6.jar:2.6.6]
at org.springframework.context.support.AbstractApplicationContext.close(AbstractApplicationContext.java:1021) ~[spring-context-5.3.18.jar:5.3.18]
at org.springframework.boot.builder.ParentContextCloserApplicationListener$ContextCloserListener.onApplicationEvent(ParentContextCloserApplicationListener.java:94) ~[spring-boot-2.6.6.jar:2.6.6]
at org.springframework.boot.builder.ParentContextCloserApplicationListener$ContextCloserListener.onApplicationEvent(ParentContextCloserApplicationListener.java:82) ~[spring-boot-2.6.6.jar:2.6.6]
at org.springframework.context.event.SimpleApplicationEventMulticaster.doInvokeListener(SimpleApplicationEventMulticaster.java:176) ~[spring-context-5.3.18.jar:5.3.18]
at org.springframework.context.event.SimpleApplicationEventMulticaster.invokeListener(SimpleApplicationEventMulticaster.java:169) ~[spring-context-5.3.18.jar:5.3.18]
at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:143) ~[spring-context-5.3.18.jar:5.3.18]
at org.springframework.context.support.AbstractApplicationContext.publishEvent(AbstractApplicationContext.java:421) ~[spring-context-5.3.18.jar:5.3.18]
at org.springframework.context.support.AbstractApplicationContext.publishEvent(AbstractApplicationContext.java:378) ~[spring-context-5.3.18.jar:5.3.18]
at org.springframework.context.support.AbstractApplicationContext.doClose(AbstractApplicationContext.java:1058) ~[spring-context-5.3.18.jar:5.3.18]
at org.springframework.context.support.AbstractApplicationContext.close(AbstractApplicationContext.java:1021) ~[spring-context-5.3.18.jar:5.3.18]
at org.springframework.cloud.bootstrap.BootstrapApplicationListener$CloseContextOnFailureApplicationListener.onApplicationEvent(BootstrapApplicationListener.java:497) ~[spring-cloud-context-3.1.1.jar:3.1.1]
at org.springframework.context.event.SimpleApplicationEventMulticaster.doInvokeListener(SimpleApplicationEventMulticaster.java:176) ~[spring-context-5.3.18.jar:5.3.18]
at org.springframework.context.event.SimpleApplicationEventMulticaster.invokeListener(SimpleApplicationEventMulticaster.java:169) ~[spring-context-5.3.18.jar:5.3.18]
at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:143) ~[spring-context-5.3.18.jar:5.3.18]
at org.springframework.context.support.AbstractApplicationContext.publishEvent(AbstractApplicationContext.java:421) ~[spring-context-5.3.18.jar:5.3.18]
at org.springframework.context.support.AbstractApplicationContext.publishEvent(AbstractApplicationContext.java:378) ~[spring-context-5.3.18.jar:5.3.18]
at org.springframework.boot.context.event.EventPublishingRunListener.failed(EventPublishingRunListener.java:124) ~[spring-boot-2.6.6.jar:2.6.6]
at org.springframework.boot.SpringApplicationRunListeners.callFailedListener(SpringApplicationRunListeners.java:96) ~[spring-boot-2.6.6.jar:2.6.6]
at org.springframework.boot.SpringApplicationRunListeners.lambda$failed$7(SpringApplicationRunListeners.java:87) ~[spring-boot-2.6.6.jar:2.6.6]
at java.base/java.util.ArrayList.forEach(ArrayList.java:1511) ~[na:na]
at org.springframework.boot.SpringApplicationRunListeners.doWithListeners(SpringApplicationRunListeners.java:120) ~[spring-boot-2.6.6.jar:2.6.6]
at org.springframework.boot.SpringApplicationRunListeners.failed(SpringApplicationRunListeners.java:86) ~[spring-boot-2.6.6.jar:2.6.6]
at org.springframework.boot.SpringApplication.handleRunFailure(SpringApplication.java:790) ~[spring-boot-2.6.6.jar:2.6.6]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:313) ~[spring-boot-2.6.6.jar:2.6.6]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1312) ~[spring-boot-2.6.6.jar:2.6.6]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1301) ~[spring-boot-2.6.6.jar:2.6.6]
at com.wen3.dubbonacos.DemoProviderApplication.main(DemoProviderApplication.java:15) ~[classes/:na]
Caused by: org.apache.dubbo.rpc.RpcException: Failed to unregister dubbo://192.168.1.4:20880/org.apache.dubbo.metadata.MetadataService?anyhost=true&application=provider1&background=false&connections=1&delay=0&deprecated=false&dubbo=2.0.2&dynamic=true&executes=100&generic=false&group=provider1&interface=org.apache.dubbo.metadata.MetadataService&metadata-type=remote&methods=getMetadataURL,isMetadataService,getExportedURLs,serviceName,version,getSubscribedURLs,getExportedServiceURLs,getMetadataInfo,toSortedStrings,getMetadataInfos,getServiceDefinition&pid=15740&release=3.0.6&revision=3.0.6&service-name-mapping=true&side=provider×tamp=1649156966499&version=1.0.0 to nacos nacos://localhost:8848/org.apache.dubbo.registry.RegistryService?application=provider1&dubbo=2.0.2&group=demo-provider&interface=org.apache.dubbo.registry.RegistryService&pid=15740&qos.enable=false&release=3.0.6&server=localhost, cause: failed to req API:/nacos/v1/ns/instance after all servers([localhost:8848]) tried: ErrCode:403, ErrMsg:Whitelabel Error Page
This application has no explicit mapping for /error, so you are seeing this as a fallback.
Tue Apr 05 19:09:28 CST 2022There was an unexpected error (type=Forbidden, status=403).unknown user!
at org.apache.dubbo.registry.nacos.NacosRegistry.doUnregister(NacosRegistry.java:194) ~[dubbo-3.0.6.jar:3.0.6]
at org.apache.dubbo.registry.support.FailbackRegistry.unregister(FailbackRegistry.java:253) ~[dubbo-3.0.6.jar:3.0.6]
... 47 common frames omitted
Caused by: com.alibaba.nacos.api.exception.NacosException: failed to req API:/nacos/v1/ns/instance after all servers([localhost:8848]) tried: ErrCode:403, ErrMsg:Whitelabel Error Page
This application has no explicit mapping for /error, so you are seeing this as a fallback.
Tue Apr 05 19:09:28 CST 2022There was an unexpected error (type=Forbidden, status=403).unknown user!
at com.alibaba.nacos.client.naming.net.NamingProxy.reqApi(NamingProxy.java:556) ~[nacos-client-1.4.2.jar:na]
at com.alibaba.nacos.client.naming.net.NamingProxy.reqApi(NamingProxy.java:498) ~[nacos-client-1.4.2.jar:na]
at com.alibaba.nacos.client.naming.net.NamingProxy.reqApi(NamingProxy.java:493) ~[nacos-client-1.4.2.jar:na]
at com.alibaba.nacos.client.naming.net.NamingProxy.deregisterService(NamingProxy.java:271) ~[nacos-client-1.4.2.jar:na]
at com.alibaba.nacos.client.naming.NacosNamingService.deregisterInstance(NacosNamingService.java:252) ~[nacos-client-1.4.2.jar:na]
at com.alibaba.nacos.client.naming.NacosNamingService.deregisterInstance(NacosNamingService.java:238) ~[nacos-client-1.4.2.jar:na]
at com.alibaba.nacos.client.naming.NacosNamingService.deregisterInstance(NacosNamingService.java:222) ~[nacos-client-1.4.2.jar:na]
at org.apache.dubbo.registry.nacos.NacosNamingServiceWrapper.deregisterInstance(NacosNamingServiceWrapper.java:63) ~[dubbo-3.0.6.jar:3.0.6]
at org.apache.dubbo.registry.nacos.NacosRegistry.doUnregister(NacosRegistry.java:189) ~[dubbo-3.0.6.jar:3.0.6]
... 48 common frames omitted
翻看了nacos源码发现
public void setAddress(String address) {
this.address = address;
if (address != null) {
try {
URL url = URL.valueOf(address);
// Refactor since 2.7.8
updatePropertyIfAbsent(this::getUsername, this::setUsername, url.getUsername());
updatePropertyIfAbsent(this::getPassword, this::setPassword, url.getPassword());
updatePropertyIfAbsent(this::getProtocol, this::setProtocol, url.getProtocol());
updatePropertyIfAbsent(this::getPort, this::setPort, url.getPort());
Map params = url.getParameters();
if (CollectionUtils.isNotEmptyMap(params)) {
params.remove(BACKUP_KEY);
}
updateParameters(params);
} catch (Exception ignored) {
}
}
}
在处理address时,会处理username和password,因此需要这样配置
dubbo:
registry:
address: nacos://localhost:8848?username=nacos&password=nacos
翻看DubboConfigurationProperties这个类的源码,以及对象成员属性的所有字段,均没有找到任何关于namespace的配置项,但在registry对象里面有一个parameters配置,看起来有点像,试着在这个配置里面追加一个namespace,果然成了,正确配置如下
dubbo:
registry:
address: nacos://localhost:8848?username=nacos&password=nacos
parameters:
namespace: demo-dubbo-nacos
消费端关键的一个注解就是**@DubboReference**,在使用这个注解的时候需要指定版本号和group,例如
@DubboReference(version = "demo-1.0.0", group = "demo-provider")
完整代码如下
@RestController
public class DemoHelloConsumerController {
@DubboReference(version = "demo-1.0.0", group = "demo-provider")
private DemoService demoService;
@GetMapping(path = "/hello-dubbo")
public String helloDubbo(String name) {
return demoService.helloWorld(name);
}
}
只需要修改服务提供者**@DubboService注解的protocol**属性
@DubboService(protocol = "dubbo,rest")
2022-04-09 09:07:39.058 ERROR 10896 --- [ main] o.s.boot.SpringApplication : Application run failed
java.lang.IllegalStateException: No such extension org.apache.dubbo.rpc.Protocol by name rest, possible causes:
(1) rest=org.apache.dubbo.rpc.protocol.rest.RestProtocol:
java.lang.IllegalStateException: Failed to load extension class (interface: interface org.apache.dubbo.rpc.Protocol, class line: rest=org.apache.dubbo.rpc.protocol.rest.RestProtocol) in jar:file:/G:/repository/org/apache/dubbo/dubbo/3.0.7/dubbo-3.0.7.jar!/META-INF/dubbo/internal/org.apache.dubbo.rpc.Protocol, cause: org/jboss/resteasy/client/jaxrs/ClientHttpEngine
java.lang.IllegalStateException: Failed to load extension class (interface: interface org.apache.dubbo.rpc.Protocol, class line: rest=org.apache.dubbo.rpc.protocol.rest.RestProtocol) in jar:file:/G:/repository/org/apache/dubbo/dubbo/3.0.7/dubbo-3.0.7.jar!/META-INF/dubbo/internal/org.apache.dubbo.rpc.Protocol, cause: org/jboss/resteasy/client/jaxrs/ClientHttpEngine
at org.apache.dubbo.common.extension.ExtensionLoader.loadResource(ExtensionLoader.java:1052)
at org.apache.dubbo.common.extension.ExtensionLoader.loadFromClass(ExtensionLoader.java:1019)
at org.apache.dubbo.common.extension.ExtensionLoader.lambda$loadDirectory$4(ExtensionLoader.java:1007)
at java.base/java.util.LinkedHashMap.forEach(LinkedHashMap.java:721)
at java.base/java.util.Collections$UnmodifiableMap.forEach(Collections.java:1553)
at org.apache.dubbo.common.extension.ExtensionLoader.loadDirectory(ExtensionLoader.java:1006)
at org.apache.dubbo.common.extension.ExtensionLoader.loadDirectory(ExtensionLoader.java:943)
at org.apache.dubbo.common.extension.ExtensionLoader.loadExtensionClasses(ExtensionLoader.java:931)
at org.apache.dubbo.common.extension.ExtensionLoader.getExtensionClasses(ExtensionLoader.java:913)
at org.apache.dubbo.common.extension.ExtensionLoader.getAdaptiveExtensionClass(ExtensionLoader.java:1243)
at org.apache.dubbo.common.extension.ExtensionLoader.createAdaptiveExtension(ExtensionLoader.java:1231)
at org.apache.dubbo.common.extension.ExtensionLoader.getAdaptiveExtension(ExtensionLoader.java:713)
at org.apache.dubbo.config.ServiceConfig.postProcessAfterScopeModelChanged(ServiceConfig.java:154)
at org.apache.dubbo.config.AbstractConfig.setScopeModel(AbstractConfig.java:395)
at org.apache.dubbo.config.AbstractConfig.(AbstractConfig.java:117)
at org.apache.dubbo.config.AbstractMethodConfig.(AbstractMethodConfig.java:103)
at org.apache.dubbo.config.AbstractInterfaceConfig.(AbstractInterfaceConfig.java:192)
at org.apache.dubbo.config.AbstractServiceConfig.(AbstractServiceConfig.java:132)
at org.apache.dubbo.config.ServiceConfigBase.(ServiceConfigBase.java:84)
at org.apache.dubbo.config.ServiceConfig.(ServiceConfig.java:136)
at org.apache.dubbo.config.spring.ServiceBean.(ServiceBean.java:56)
at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:77)
at java.base/jdk.internal.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.base/java.lang.reflect.Constructor.newInstanceWithCaller(Constructor.java:499)
at java.base/java.lang.reflect.Constructor.newInstance(Constructor.java:480)
at org.springframework.beans.BeanUtils.instantiateClass(BeanUtils.java:211)
at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:87)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateBean(AbstractAutowireCapableBeanFactory.java:1326)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1232)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:582)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:542)
at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:335)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:234)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:333)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:208)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:953)
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:918)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:583)
at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:145)
at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:740)
at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:415)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:303)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1312)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1301)
at com.wen3.dubbonacos.DemoProviderApplication.main(DemoProviderApplication.java:15)
Caused by: java.lang.NoClassDefFoundError: org/jboss/resteasy/client/jaxrs/ClientHttpEngine
at java.base/java.lang.Class.forName0(Native Method)
at java.base/java.lang.Class.forName(Class.java:467)
at org.apache.dubbo.common.extension.ExtensionLoader.loadResource(ExtensionLoader.java:1048)
... 45 more
Caused by: java.lang.ClassNotFoundException: org.jboss.resteasy.client.jaxrs.ClientHttpEngine
at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:641)
at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:188)
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:520)
... 48 more
at org.apache.dubbo.common.extension.ExtensionLoader.findException(ExtensionLoader.java:747) ~[dubbo-3.0.7.jar:3.0.7]
at org.apache.dubbo.common.extension.ExtensionLoader.createExtension(ExtensionLoader.java:754) ~[dubbo-3.0.7.jar:3.0.7]
at org.apache.dubbo.common.extension.ExtensionLoader.getExtension(ExtensionLoader.java:548) ~[dubbo-3.0.7.jar:3.0.7]
at org.apache.dubbo.common.extension.ExtensionLoader.getExtension(ExtensionLoader.java:523) ~[dubbo-3.0.7.jar:3.0.7]
at org.apache.dubbo.config.ServiceConfig.findConfiguredPort(ServiceConfig.java:769) ~[dubbo-3.0.7.jar:3.0.7]
at org.apache.dubbo.config.ServiceConfig.buildUrl(ServiceConfig.java:552) ~[dubbo-3.0.7.jar:3.0.7]
at org.apache.dubbo.config.ServiceConfig.doExportUrlsFor1Protocol(ServiceConfig.java:408) ~[dubbo-3.0.7.jar:3.0.7]
at org.apache.dubbo.config.ServiceConfig.doExportUrls(ServiceConfig.java:396) ~[dubbo-3.0.7.jar:3.0.7]
at org.apache.dubbo.config.ServiceConfig.doExport(ServiceConfig.java:361) ~[dubbo-3.0.7.jar:3.0.7]
at org.apache.dubbo.config.ServiceConfig.export(ServiceConfig.java:233) ~[dubbo-3.0.7.jar:3.0.7]
at org.apache.dubbo.config.deploy.DefaultModuleDeployer.exportServiceInternal(DefaultModuleDeployer.java:341) ~[dubbo-3.0.7.jar:3.0.7]
at org.apache.dubbo.config.deploy.DefaultModuleDeployer.exportServices(DefaultModuleDeployer.java:313) ~[dubbo-3.0.7.jar:3.0.7]
at org.apache.dubbo.config.deploy.DefaultModuleDeployer.start(DefaultModuleDeployer.java:145) ~[dubbo-3.0.7.jar:3.0.7]
at org.apache.dubbo.config.spring.context.DubboDeployApplicationListener.onContextRefreshedEvent(DubboDeployApplicationListener.java:111) ~[dubbo-3.0.7.jar:3.0.7]
at org.apache.dubbo.config.spring.context.DubboDeployApplicationListener.onApplicationEvent(DubboDeployApplicationListener.java:100) ~[dubbo-3.0.7.jar:3.0.7]
at org.apache.dubbo.config.spring.context.DubboDeployApplicationListener.onApplicationEvent(DubboDeployApplicationListener.java:45) ~[dubbo-3.0.7.jar:3.0.7]
at org.springframework.context.event.SimpleApplicationEventMulticaster.doInvokeListener(SimpleApplicationEventMulticaster.java:176) ~[spring-context-5.3.18.jar:5.3.18]
at org.springframework.context.event.SimpleApplicationEventMulticaster.invokeListener(SimpleApplicationEventMulticaster.java:169) ~[spring-context-5.3.18.jar:5.3.18]
at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:143) ~[spring-context-5.3.18.jar:5.3.18]
at org.springframework.context.support.AbstractApplicationContext.publishEvent(AbstractApplicationContext.java:421) ~[spring-context-5.3.18.jar:5.3.18]
at org.springframework.context.support.AbstractApplicationContext.publishEvent(AbstractApplicationContext.java:378) ~[spring-context-5.3.18.jar:5.3.18]
at org.springframework.context.support.AbstractApplicationContext.finishRefresh(AbstractApplicationContext.java:938) ~[spring-context-5.3.18.jar:5.3.18]
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:586) ~[spring-context-5.3.18.jar:5.3.18]
at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:145) ~[spring-boot-2.6.6.jar:2.6.6]
at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:740) ~[spring-boot-2.6.6.jar:2.6.6]
at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:415) ~[spring-boot-2.6.6.jar:2.6.6]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:303) ~[spring-boot-2.6.6.jar:2.6.6]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1312) ~[spring-boot-2.6.6.jar:2.6.6]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1301) ~[spring-boot-2.6.6.jar:2.6.6]
at com.wen3.dubbonacos.DemoProviderApplication.main(DemoProviderApplication.java:15) ~[classes/:na]
添加依赖
<dependency>
<groupId>org.apache.dubbogroupId>
<artifactId>dubbo-rpc-restartifactId>
<version>${dubbo.version}version>
dependency>
重启启动就不会提示找不到org.jboss.resteasy.client.jaxrs.ClientHttpEngine
这个类了
2022-04-09 09:29:09.393 ERROR 13308 --- [ main] o.s.boot.SpringApplication : Application run failed
java.lang.RuntimeException: RESTEASY003130: Class is not a root resource. It, or one of its interfaces must be annotated with @Path: com.wen3.dubbonacos.service.DemoService implements:
at org.jboss.resteasy.core.ResourceMethodRegistry.addResourceFactory(ResourceMethodRegistry.java:185) ~[resteasy-jaxrs-3.14.0.Final.jar:3.14.0.Final]
at org.jboss.resteasy.core.ResourceMethodRegistry.addResourceFactory(ResourceMethodRegistry.java:164) ~[resteasy-jaxrs-3.14.0.Final.jar:3.14.0.Final]
at org.apache.dubbo.rpc.protocol.rest.BaseRestProtocolServer.deploy(BaseRestProtocolServer.java:53) ~[dubbo-3.0.7.jar:3.0.7]
at org.apache.dubbo.rpc.protocol.rest.RestProtocol.doExport(RestProtocol.java:127) ~[dubbo-3.0.7.jar:3.0.7]
at org.apache.dubbo.rpc.protocol.AbstractProxyProtocol.export(AbstractProxyProtocol.java:89) ~[dubbo-3.0.7.jar:3.0.7]
at org.apache.dubbo.rpc.protocol.ProtocolListenerWrapper.export(ProtocolListenerWrapper.java:66) ~[dubbo-3.0.7.jar:3.0.7]
at org.apache.dubbo.qos.protocol.QosProtocolWrapper.export(QosProtocolWrapper.java:76) ~[dubbo-3.0.7.jar:3.0.7]
at org.apache.dubbo.rpc.cluster.filter.ProtocolFilterWrapper.export(ProtocolFilterWrapper.java:61) ~[dubbo-3.0.7.jar:3.0.7]
at org.apache.dubbo.rpc.protocol.ProtocolSerializationWrapper.export(ProtocolSerializationWrapper.java:47) ~[dubbo-3.0.7.jar:3.0.7]
at org.apache.dubbo.rpc.Protocol$Adaptive.export(Protocol$Adaptive.java) ~[dubbo-3.0.7.jar:3.0.7]
at org.apache.dubbo.registry.integration.RegistryProtocol.lambda$doLocalExport$2(RegistryProtocol.java:294) ~[dubbo-3.0.7.jar:3.0.7]
at java.base/java.util.concurrent.ConcurrentHashMap.computeIfAbsent(ConcurrentHashMap.java:1708) ~[na:na]
at org.apache.dubbo.registry.integration.RegistryProtocol.doLocalExport(RegistryProtocol.java:292) ~[dubbo-3.0.7.jar:3.0.7]
at org.apache.dubbo.registry.integration.RegistryProtocol.export(RegistryProtocol.java:239) ~[dubbo-3.0.7.jar:3.0.7]
at org.apache.dubbo.rpc.protocol.ProtocolListenerWrapper.export(ProtocolListenerWrapper.java:64) ~[dubbo-3.0.7.jar:3.0.7]
at org.apache.dubbo.qos.protocol.QosProtocolWrapper.export(QosProtocolWrapper.java:74) ~[dubbo-3.0.7.jar:3.0.7]
at org.apache.dubbo.rpc.cluster.filter.ProtocolFilterWrapper.export(ProtocolFilterWrapper.java:58) ~[dubbo-3.0.7.jar:3.0.7]
at org.apache.dubbo.rpc.protocol.ProtocolSerializationWrapper.export(ProtocolSerializationWrapper.java:47) ~[dubbo-3.0.7.jar:3.0.7]
at org.apache.dubbo.rpc.Protocol$Adaptive.export(Protocol$Adaptive.java) ~[dubbo-3.0.7.jar:3.0.7]
at org.apache.dubbo.config.ServiceConfig.doExportUrl(ServiceConfig.java:641) ~[dubbo-3.0.7.jar:3.0.7]
at org.apache.dubbo.config.ServiceConfig.exportRemote(ServiceConfig.java:619) ~[dubbo-3.0.7.jar:3.0.7]
at org.apache.dubbo.config.ServiceConfig.exportUrl(ServiceConfig.java:578) ~[dubbo-3.0.7.jar:3.0.7]
at org.apache.dubbo.config.ServiceConfig.doExportUrlsFor1Protocol(ServiceConfig.java:410) ~[dubbo-3.0.7.jar:3.0.7]
at org.apache.dubbo.config.ServiceConfig.doExportUrls(ServiceConfig.java:396) ~[dubbo-3.0.7.jar:3.0.7]
at org.apache.dubbo.config.ServiceConfig.doExport(ServiceConfig.java:361) ~[dubbo-3.0.7.jar:3.0.7]
at org.apache.dubbo.config.ServiceConfig.export(ServiceConfig.java:233) ~[dubbo-3.0.7.jar:3.0.7]
at org.apache.dubbo.config.deploy.DefaultModuleDeployer.exportServiceInternal(DefaultModuleDeployer.java:341) ~[dubbo-3.0.7.jar:3.0.7]
at org.apache.dubbo.config.deploy.DefaultModuleDeployer.exportServices(DefaultModuleDeployer.java:313) ~[dubbo-3.0.7.jar:3.0.7]
at org.apache.dubbo.config.deploy.DefaultModuleDeployer.start(DefaultModuleDeployer.java:145) ~[dubbo-3.0.7.jar:3.0.7]
at org.apache.dubbo.config.spring.context.DubboDeployApplicationListener.onContextRefreshedEvent(DubboDeployApplicationListener.java:111) ~[dubbo-3.0.7.jar:3.0.7]
at org.apache.dubbo.config.spring.context.DubboDeployApplicationListener.onApplicationEvent(DubboDeployApplicationListener.java:100) ~[dubbo-3.0.7.jar:3.0.7]
at org.apache.dubbo.config.spring.context.DubboDeployApplicationListener.onApplicationEvent(DubboDeployApplicationListener.java:45) ~[dubbo-3.0.7.jar:3.0.7]
at org.springframework.context.event.SimpleApplicationEventMulticaster.doInvokeListener(SimpleApplicationEventMulticaster.java:176) ~[spring-context-5.3.18.jar:5.3.18]
at org.springframework.context.event.SimpleApplicationEventMulticaster.invokeListener(SimpleApplicationEventMulticaster.java:169) ~[spring-context-5.3.18.jar:5.3.18]
at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:143) ~[spring-context-5.3.18.jar:5.3.18]
at org.springframework.context.support.AbstractApplicationContext.publishEvent(AbstractApplicationContext.java:421) ~[spring-context-5.3.18.jar:5.3.18]
at org.springframework.context.support.AbstractApplicationContext.publishEvent(AbstractApplicationContext.java:378) ~[spring-context-5.3.18.jar:5.3.18]
at org.springframework.context.support.AbstractApplicationContext.finishRefresh(AbstractApplicationContext.java:938) ~[spring-context-5.3.18.jar:5.3.18]
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:586) ~[spring-context-5.3.18.jar:5.3.18]
at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:145) ~[spring-boot-2.6.6.jar:2.6.6]
at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:740) ~[spring-boot-2.6.6.jar:2.6.6]
at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:415) ~[spring-boot-2.6.6.jar:2.6.6]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:303) ~[spring-boot-2.6.6.jar:2.6.6]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1312) ~[spring-boot-2.6.6.jar:2.6.6]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1301) ~[spring-boot-2.6.6.jar:2.6.6]
at com.wen3.dubbonacos.DemoProviderApplication.main(DemoProviderApplication.java:15) ~[classes/:na]
服务实现的接口需要添加javax.ws.rs的注解,在定义接口的工程里面添加如下依赖
<dependency>
<groupId>javax.ws.rsgroupId>
<artifactId>javax.ws.rs-apiartifactId>
<version>${javax.ws.rs-api.version}version>
dependency>
接口上添加相关注解
public interface DemoService {
@GET
@Produces
@Consumes
@Path("/hello")
String helloWorld(@QueryParam("name") String name);
}
现在服务提供者向nacos注册了三个服务,为什么是3个?
所以相当于提供了三个接口,那么消费者可以使用Feign组件访问,也可以实现dubbo协议访问,我们把这三种访问方式都演示一下,改造后的消费者代码如下
@RestController
public class DemoHelloConsumerController {
@Resource
private DemoProviderFeign demoProviderFeign;
@DubboReference(version = "demo-1.0.0", group = "demo-provider", protocol = "dubbo")
private DemoService demoService;
@DubboReference(version = "demo-1.0.0", group = "demo-provider", protocol = "rest")
private DemoService demoServiceRest;
@GetMapping(path = "/hello")
public String hello(String name) {
return demoProviderFeign.hello(name);
}
@GetMapping(path = "/hello-dubbo")
public String helloDubbo(String name) {
return demoService.helloWorld(name);
}
@GetMapping(path = "/hello-rest")
public String helloRest(String name) {
return demoServiceRest.helloWorld(name);
}
}
启动消费者进行测试
$ curl "http://localhost:8081/hello?name=xxx1"
xxx1,hello!
$ curl "http://localhost:8081/hello-dubbo?name=xxx2"
hello xxx2!
$ curl "http://localhost:8081/hello-rest?name=xxx3"
hello xxx3!
本文介绍了一个SpringBoot应用,如何向注册中心nacos注册dubbo服务和rest服务,并且在配置和使用过程中遇到的一些常见的问题,也做了分析和解决。
dubbo框架既可以发布dubbo服务,也能发布rest服务,但是对rest服务有要求,那就是必须使用javax.ws.rs下面的注解。
dubbo框架发布的服务更倾向于微服务内部调用,可以提高内部交互的整体性能。Spring Cloud注册中心Eureka可以无缝替换成nacos,并且使用Feign调用的场景可以不做任何修改。