在SpringMVC框架下提供dubbo服务(提供者)

本文档详细介绍了如何在SpringMVC框架下配置Dubbo服务提供者,包括XML配置项如应用名、注册中心地址、暴露端口等。确保正确配置bean以避免NoSuchBeanDefinitionException错误。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

dubbo服务提供者xml配置
********************************************** **********************************************
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns=" http://www.springframework.org/schema/beans" xmlns:xsi=" http://www.w3.org/2001/XMLSchema-instance"                    
             xmlns:dubbo=" http://code.alibabatech.com/schema/dubbo"
             xsi:schemaLocation=" http://www.springframework.org/schema/beans
                                                  http://www.springframework.org/schema/beans/spring-beans.xsd
                                                  http://code.alibabatech.com/schema/dubbo
                                                  http://code.alibabatech.com/schema/dubbo/dubbo.xsd">

    <dubbo:application name="${dubbo.application.name}" owner="${dubbo.application.owner}" />
    <!-- 使用zookper暴露发现服务地址 -->
    <dubbo:registry address="${user.dubbo.registry.address}" check="false" />
    <!-- 用dubbo协议在XXX端口暴露服务 -->
    <dubbo:protocol name="dubbo" port="${user.dubbo.export.port}" />
    <bean id="testservice" class="com.user.push.services.TestCalledImpl" />   
    <dubbo:service timeout="5000" loadbalance="random" actives="0" interface="com.user.push.services.TestService"         
    ref="testservice" />
</beans>
********************************************** **********************************************
说明
application name对应你的应用名;owner对应该应用的维护人员
registry address对应即将发布的服务的目标注册地址,这里使用zooker注册中心
push.dubbo.export.port对应dubbo服务暴露的端口

这样启动服务后,你就能在dubbo管理后台看到你的服务信息了


点击服务,可看到服务详情



注:
如果在xml配置文件中没有添加红色语句,则会报错,提示找不到相应的bean
Error creating bean with name 'com.user.push.services.TestService': Cannot resolve reference to bean 'testservice' while setting bean property 'ref'; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'testservice' is defined
 at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:328)
 at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveValueIfNecessary(BeanDefinitionValueResolver.java:106)
 at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1360)
 at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1118)
 at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:517)
 at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:456)
 at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:294)
 at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:225)
 at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:291)
 at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:193)
 at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:585)
 at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:913)
 at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:464)
 at org.springframework.web.context.ContextLoader.configureAndRefreshWebApplicationContext(ContextLoader.java:385)
 at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:284)
 at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:111)
 at org.eclipse.jetty.server.handler.ContextHandler.callContextInitialized(ContextHandler.java:760)
 at org.eclipse.jetty.servlet.ServletContextHandler.callContextInitialized(ServletContextHandler.java:403)
 at org.eclipse.jetty.server.handler.ContextHandler.startContext(ContextHandler.java:752)
 at org.eclipse.jetty.servlet.ServletContextHandler.startContext(ServletContextHandler.java:239)
 at org.eclipse.jetty.webapp.WebAppContext.startContext(WebAppContext.java:1213)
 at org.eclipse.jetty.server.handler.ContextHandler.doStart(ContextHandler.java:695)
 at org.eclipse.jetty.webapp.WebAppContext.doStart(WebAppContext.java:454)
 at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:59)
 at org.eclipse.jetty.server.handler.HandlerWrapper.doStart(HandlerWrapper.java:90)
 at org.eclipse.jetty.server.Server.doStart(Server.java:262)
 at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:59)
 at jetty.PushServiceJetty.start(PushServiceJetty.java:79)
 at jetty.PushServiceJetty.main(PushServiceJetty.java:88)
Caused by:
org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'testservice' is defined
 at org.springframework.beans.factory.support.DefaultListableBeanFactory.getBeanDefinition(DefaultListableBeanFactory.java:529)
 at org.springframework.beans.factory.support.AbstractBeanFactory.getMergedLocalBeanDefinition(AbstractBeanFactory.java:1095)
 at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:277)
 at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:193)
 at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:322)
 at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveValueIfNecessary(BeanDefinitionValueResolver.java:106)
 at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1360)
 at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1118)
 at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:517)
 at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:456)
 at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:294)
 at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:225)
 at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:291)
 at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:193)
 at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:585)
 at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:913)
 at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:464)
 at org.springframework.web.context.ContextLoader.configureAndRefreshWebApplicationContext(ContextLoader.java:385)
 at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:284)
 at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:111)
 at org.eclipse.jetty.server.handler.ContextHandler.callContextInitialized(ContextHandler.java:760)
 at org.eclipse.jetty.servlet.ServletContextHandler.callContextInitialized(ServletContextHandler.java:403)
 at org.eclipse.jetty.server.handler.ContextHandler.startContext(ContextHandler.java:752)
 at org.eclipse.jetty.servlet.ServletContextHandler.startContext(ServletContextHandler.java:239)
 at org.eclipse.jetty.webapp.WebAppContext.startContext(WebAppContext.java:1213)
 at org.eclipse.jetty.server.handler.ContextHandler.doStart(ContextHandler.java:695)
 at org.eclipse.jetty.webapp.WebAppContext.doStart(WebAppContext.java:454)
 at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:59)
 at org.eclipse.jetty.server.handler.HandlerWrapper.doStart(HandlerWrapper.java:90)
 at org.eclipse.jetty.server.Server.doStart(Server.java:262)
 at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:59)
 at jetty.PushServiceJetty.start(PushServiceJetty.java:79)
 at jetty.PushServiceJetty.main(PushServiceJetty.java:88)


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值