<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.0.1.RELEASE</version>
</parent>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>1.8</java.version>
<curator-framework.version>4.0.1</curator-framework.version>
<zookeeper.version>3.4.13</zookeeper.version>
<dubbo.starter.version>0.2.0</dubbo.starter.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>com.alibaba.boot</groupId>
<artifactId>dubbo-spring-boot-starter</artifactId>
<version>${dubbo.starter.version}</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>com.springboot</groupId>
<artifactId>springboot-dubbo-interface</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
</dependencies>
public interface HelloBootDubboService {
public String sayHello();
}
@Service
public class HelloBootDubboServiceImpl implements HelloBootDubboService {
@Override
public String sayHello() {
System.out.println("=========进入服务========");
return "服务调用成功!";
}
}
@EnableDubbo
@SpringBootApplication
public class App {
public static void main(String[] args) {
SpringApplication.run(App.class,args);
}
}
server:
port: 8080
dubbo:
application:
name: testBoot
#表示采用dubbo协议
protocol:
name: dubbo
#端口号
port: 20880
registry:
address: zookeeper://192.168.12.131:2181
@RestController
public class HelloController {
@Reference
private HelloBootDubboService helloBootDubboService;
@RequestMapping("/hello")
public String sayHello(){
return helloBootDubboService.sayHello();
}
}
@EnableDubbo
@SpringBootApplication
public class App {
public static void main(String[] args) {
SpringApplication.run(App.class,args);
}
}
server:
port: 8082 #tomcat的端口号
dubbo:
application:
name: controller #注册服务名称
registry:
address: zookeeper://192.168.12.131:2181
consumer:
timeout: 100000 #调用服务的超时时间
欢迎光临 黑马程序员技术交流社区 (http://bbs.itheima.com/) | 黑马程序员IT技术论坛 X3.2 |