分享一个坑爹的问题
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);
}
}
总结一下
- 提供者的服务实现类上加上@Component
- 提供者的启动类上加上@EnableDubboConfiguration,注意别加错了
- 引入的依赖是com.alibaba下的
注意:非org.apache.dubbo下的依赖!!!<dependency> <groupId>com.alibaba.spring.boot</groupId> <artifactId>dubbo-spring-boot-starter</artifactId> <version>2.0.0</version> </dependency>