dubbo项目正常启动,dubbo却未发布到zookeeper ,dubbo-admin项目发现不了

分享一个坑爹的问题
dubbo分布式项目搭建完成了,服务提供者正常启动
但是却没有发布成功
SpringBoot+Dubbo的项目

INFO 13152 --- [           main] c.a.dubbo.common.logger.LoggerFactory    : using logger: com.alibaba.dubbo.common.logger.log4j.Log4jLoggerAdapter

  ████████▄  ███    █▄  ▀█████████▄  ▀█████████▄   ▄██████▄  
  ███   ▀███ ███    ███   ███    ███   ███    ███ ███    ███ 
  ███    ███ ███    ███   ███    ███   ███    ███ ███    ███ 
  ███    ███ ███    ███  ▄███▄▄▄██▀   ▄███▄▄▄██▀  ███    ███ 
  ███    ███ ███    ███ ▀▀███▀▀▀██▄  ▀▀███▀▀▀██▄  ███    ███ 
  ███    ███ ███    ███   ███    ██▄   ███    ██▄ ███    ███ 
  ███   ▄███ ███    ███   ███    ███   ███    ███ ███    ███ 
  ████████▀  ████████▀  ▄█████████▀  ▄█████████▀   ▀██████▀  
                                                             

 :: Dubbo ::        (v2.6.0)

  .   ____          _            __ _ _
 /\\ / ___'_ __ _ _(_)_ __  __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
 \\/  ___)| |_)| | | | | || (_| |  ) ) ) )
  '  |____| .__|_| |_|_| |_\__, | / / / /
 =========|_|==============|___/=/_/_/_/
 :: Spring Boot ::        (v1.5.7.RELEASE)

2020-04-27 21:22:53.497  INFO 13152 --- [           main] com.hehe.integration.ServerApplication   : Starting ServerApplication on LAP-2SN0OUBM with PID 13152 (E:\CodeRepository\GitHubProject\mm-integration\mm-service\target\classes started by zhangrk in E:\CodeRepository\GitHubProject\mm-integration)
2020-04-27 21:22:53.497  INFO 13152 --- [           main] com.hehe.integration.ServerApplication   : No active profile set, falling back to default profiles: default
2020-04-27 21:22:53.549  INFO 13152 --- [           main] ationConfigEmbeddedWebApplicationContext : Refreshing org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext@41e36e46: startup date [Mon Apr 27 21:22:53 CST 2020]; root of context hierarchy
2020-04-27 21:22:55.026  INFO 13152 --- [           main] trationDelegate$BeanPostProcessorChecker : Bean 'org.springframework.transaction.annotation.ProxyTransactionManagementConfiguration' of type [org.springframework.transaction.annotation.ProxyTransactionManagementConfiguration$$EnhancerBySpringCGLIB$$41fa25a4] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2020-04-27 21:22:55.195  INFO 13152 --- [           main] trationDelegate$BeanPostProcessorChecker : Bean 'spring.dubbo-com.alibaba.dubbo.spring.boot.DubboProperties' of type [com.alibaba.dubbo.spring.boot.DubboProperties] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2020-04-27 21:22:58.255  INFO 13152 --- [           main] o.s.b.a.e.mvc.EndpointHandlerMapping     : Mapped "{[/info || /info.json],methods=[GET],produces=[application/vnd.spring-boot.actuator.v1+json || application/json]}" onto public java.lang.Object org.springframework.boot.actuate.endpoint.mvc.EndpointMvcAdapter.invoke()
2020-04-27 21:22:58.255  INFO 13152 --- [           main] o.s.b.a.e.mvc.EndpointHandlerMapping     : Mapped "{[/trace || /trace.json],methods=[GET],produces=[application/vnd.spring-boot.actuator.v1+json || application/json]}" onto public java.lang.Object org.springframework.boot.actuate.endpoint.mvc.EndpointMvcAdapter.invoke()
2020-04-27 21:22:58.256  INFO 13152 --- [           main] o.s.b.a.e.mvc.EndpointHandlerMapping     : Mapped "{[/dump || /dump.json],methods=[GET],produces=[application/vnd.spring-boot.actuator.v1+json || application/json]}" onto public java.lang.Object org.springframework.boot.actuate.endpoint.mvc.EndpointMvcAdapter.invoke()
2020-04-27 21:22:58.256  INFO 13152 --- [           main] o.s.b.a.e.mvc.EndpointHandlerMapping     : Mapped "{[/auditevents || /auditevents.json],methods=[GET],produces=[application/vnd.spring-boot.actuator.v1+json || application/json]}" onto public org.springframework.http.ResponseEntity<?> org.springframework.boot.actuate.endpoint.mvc.AuditEventsMvcEndpoint.findByPrincipalAndAfterAndType(java.lang.String,java.util.Date,java.lang.String)
2020-04-27 21:22:58.256  INFO 13152 --- [           main] o.s.b.a.e.mvc.EndpointHandlerMapping     : Mapped "{[/configprops || /configprops.json],methods=[GET],produces=[application/vnd.spring-boot.actuator.v1+json || application/json]}" onto public java.lang.Object org.springframework.boot.actuate.endpoint.mvc.EndpointMvcAdapter.invoke()
2020-04-27 21:22:58.426  INFO 13152 --- [           main] o.s.j.e.a.AnnotationMBeanExporter        : Registering beans for JMX exposure on startup
2020-04-27 21:22:58.437  INFO 13152 --- [           main] o.s.c.support.DefaultLifecycleProcessor  : Starting beans in phase 0
2020-04-27 21:22:58.542  INFO 13152 --- [           main] s.b.c.e.t.TomcatEmbeddedServletContainer : Tomcat started on port(s): 8084 (http)
2020-04-27 21:22:58.549  INFO 13152 --- [           main] com.hehe.integration.ServerApplication   : Started ServerApplication in 5.428 seconds (JVM running for 6.405)

在这里插入图片描述
但是dubbo-admin项目控制台却发现不了发布的服务
在这里插入图片描述
在这里插入图片描述
弄了好长时间,特意下载了dubbo-admin工程,结果发现 发布不上去,还以为是虚拟机的ip地址是变化的,导致发布不成功。

最后发现需要在发布的服务Service上加上SpringBoot的
Component注解!!
在这里插入图片描述

package com.hehe.integration.service.impl;

import com.alibaba.dubbo.config.annotation.Service;
import com.hehe.integration.mapper.UserMapper;
import com.hehe.integration.model.User;
import com.hehe.integration.service.IUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * mm-integration-com.hehe.integration.service.impl
 *
 * @date 2020/4/25
 */
@Component  //不加此注解 发布不到dubbo
@Service(version = "1.0.0",timeout = 10000,interfaceClass = IUserService.class)
public class UserService implements IUserService {

    @Autowired
    UserMapper userMapper;

    @Override
    public List<User> list() {
            return userMapper.findAll();
    }
}

重新启动项目
在这里插入图片描述
成功的在dubbo-admin控制台发现发布的服务:
在这里插入图片描述

最后还发现一个问题,启动类上必须加上@EnableDubboConfiguration注解

import com.alibaba.dubbo.spring.boot.annotation.EnableDubboConfiguration;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

@SpringBootApplication
@EnableDubboConfiguration	//TODO 这个注解必须加,注意引入的dubbo包是com.alibaba下的
public class ServerApplication {
    public static void main(String[] args) {
        SpringApplication.run(ServerApplication.class, args);
    }
}

总结一下

  1. 提供者的服务实现类上加上@Component
  2. 提供者的启动类上加上@EnableDubboConfiguration,注意别加错了
  3. 引入的依赖是com.alibaba下的
                <dependency>
                <groupId>com.alibaba.spring.boot</groupId>
                <artifactId>dubbo-spring-boot-starter</artifactId>
                <version>2.0.0</version>
            </dependency>
    
    注意:非org.apache.dubbo下的依赖!!!
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值