代码拉取完成,页面将自动刷新
同步操作将从 还是相信爱过/spring-boot-starter-dubbo 强制同步,此操作会覆盖自 Fork 仓库以来所做的任何修改,且无法恢复!!!
确定后同步将在后台操作,完成时将刷新页面,请耐心等待。
#spring-boot-start-dubbo
Dubbo是阿里开发的一套分布式通讯框架,Spring-boot是业界比较火的微服务框架,两者可以进行结合实现分布式微服务
##如何发布Dubbo服务
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-dubbo</artifactId>
<version>1.3.6.SNAPSHOT</version>
</dependency>
<!--依赖于容器-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<version>1.3.6.RELEASE</version>
</dependency>
#dubbo produce
spring.dubbo.application.name=comment-provider
spring.dubbo.registry.protocol=zookeeper
spring.dubbo.registry.address=monkey:2181,127.0.0.1:2181
spring.dubbo.protocol.name=duubo
spring.dubbo.protocol.port=20880
spring.dubbo.scan=com.vcg.comment.service
spring.dubbo.protocol.host=发布的hostname
在Spring Application的application.properties中添加spring.dubbo.scan即可支持Dubbo服务发布,其中scan表示要扫描的package目录
@SpringBootApplication
@EnableDubboAutoConfiguration
public class Application {
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}
@Service(version = "1.0.0")
public class CommentServiceImpl implements CommentService {
@Override
public String test() {
return "hello";
}
}
如果你不喜欢Dubbo的@Service注解,而是喜欢原生的Spring @Service注解,可以采用以下方式对外发布服务
@Configurable
public class BeanConfiguration {
MonitorConfig monitorConfig;
@Autowire
public void setMonitorConfig(MonitorConfig monitorConfig){
this.monitorConfig=monitorConfig;
}
@Bean
public ServiceBean<CommentService> commentServiceServiceBean(CommentService commentService) {
ServiceBean<CommentService> serviceBean = new ServiceBean<>();
serviceBean.setInterface(CommentService.class);
//开启监控
serviceBean.setMonitor(monitorConfig);
serviceBean.setRef(commentService);
return serviceBean;
}
}
##如何引用Dubbo服务
在Spring Boot项目的pom.xml中添加以下依赖:
org.springframework.boot spring-boot-starter-dubbo 1.3.6.SNAPSHOT在application.properties添加Dubbo的版本信息和客户端超时信息,如下:
#dubbo consumer
spring.dubbo.application.name=comment-consumer
spring.dubbo.registry.protocol=zookeeper
spring.dubbo.registry.address=monkey:2181,127.0.0.1:2181
spring.dubbo.scan=com.vcg
在Spring Application的application.properties中添加spring.dubbo.scan即可支持Dubbo服务发布,其中scan表示要扫描的package目录
@SpringBootApplication
public class Application {
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}
}
@Component
public class UserController {
@Reference(version = "1.0.0")
private CommentService commentService;
}
@Configurable
public class BeanConfiguration {
MonitorConfig monitorConfig;
@Autowire
public void setMonitorConfig(MonitorConfig monitorConfig){
this.monitorConfig=monitorConfig;
}
@Bean
public ReferenceBean<CommentService> commentService(){
ReferenceBean<CommentService> commentServiceBean=new ReferenceBean<>();
commentServiceBean.setInterface(CommentService.class);
commentServiceBean.setMonitor(monitorConfig);
return commentServiceBean;
}
}
@Component
public class UserController {
@Autowired
private CommentService commentService;
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。