springboot dubbbo 20200327
c# 开源群 328035181
1、springboot-api-provider
https://gitee.com/sf2016/dubbospringboottest
1-1 api-pom api.xml
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>dubbospringboottest</artifactId>
<groupId>com.dubbo</groupId>
<version>1.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>api</artifactId>
<groupId>com.dubbo</groupId>
<version>1.0-SNAPSHOT</version>
</project>
1-2 api-pom ImemberService,java
package com.test;
/**
* @author:
* @Date: 2020/3/26 9:15
*/
public interface ImemberService {
public String getUser();
}
1-3 provideri-pom provideri.xml
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.2.5.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.dubbo</groupId>
<artifactId>provider</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>provider</name>
<description>Demo project for Spring Boot</description>
<properties>
<java.version>1.8</java.version>
<project-build-sourceEncode>UTF-8</project-build-sourceEncode>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<curator-framework.version>4.0.1</curator-framework.version>
<zookeeper.version>3.6.0</zookeeper.version>
<dubbo.starter.version>0.2.0</dubbo.starter.version>
</properties>
<dependencies>
<dependency>
<artifactId>api</artifactId>
<groupId>com.dubbo</groupId>
<version>1.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>org.junit.vintage</groupId>
<artifactId>junit-vintage-engine</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>com.alibaba.boot</groupId>
<artifactId>dubbo-spring-boot-starter</artifactId>
<version>${dubbo.starter.version}</version>
</dependency>
<dependency>
<groupId>org.apache.curator</groupId>
<artifactId>curator-framework</artifactId>
<version>${curator-framework.version}</version>
</dependency>
<dependency>
<groupId>org.apache.zookeeper</groupId>
<artifactId>zookeeper</artifactId>
<version>${zookeeper.version}</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
1-4 provider client-readme.txt
1、provider项目Maven-install Jar包
pom.xml如下:
#<groupId>com.dubbo</groupId>
#<artifactId>provider</artifactId>
#<version>0.0.1-SNAPSHOT</version>
#<name>provider</name>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
2、运行服务 provider.jar
cmd D:\temp\dubbo-case\dubbospringboottest\provider\target
java -jar provider-0.0.1-SNAPSHOT.jar&
3、client项目sprintboot启动
http://localhost:8089/api/member
1-5 provider application.yml
server:
port: 8088
dubbo:
application:
name: member
protocol:
name: dubbo
port: 20880
registry:
address: zookeeper://127.0.0.1:2181
scan:
base-packages: com.dubbo.provider
1-6 provider ImemberServiceImpl.java
package com.dubbo.provider;
/**
* @author:
* @Date: 2020/3/26 9:31
*/
import com.alibaba.dubbo.config.annotation.Service;
import com.test.ImemberService;
import org.springframework.beans.factory.annotation.Value;
/**
* @program: dubbospringboottest
*
* @description:
*
* @author:
*
* @Date: 2020/3/26 9:31
*/
@Service
public class ImemberServiceImpl implements ImemberService {
@Value("${dubbo.protocol.port}")
private String dubboPort;
@Override
public String getUser() {
System.out.println("订单服务调用会员服务.....dubbo服务端口"+dubboPort);
return "订单服务调用会员服务......";
}
}
1-7 provider ProviderApplication.java
package com.dubbo.provider;
import com.alibaba.dubbo.config.spring.context.annotation.EnableDubbo;
import com.alibaba.dubbo.container.Main;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@EnableDubbo
@SpringBootApplication
//@EnableAutoConfiguration
public class ProviderApplication {
public static void main(String[] args)
{
SpringApplication.run(ProviderApplication.class, args);
//Main.main(args);
}
}
2、spring-client
https://gitee.com/sf2016/dubbospringboottestclient
2-1 Imember.java
package com.dubbo.springbootclient;/**
* @author:
* @Date: 2020/3/26 10:50
*/
import com.alibaba.dubbo.config.annotation.Reference;
import com.test.ImemberService;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
/**
* @program: springbootclient
*
* @description:
*
* @author:
*
* @Date: 2020/3/26 10:50
*/
@Controller
@RequestMapping(value = "/api")
public class Imember {
@Reference
private ImemberService imemberService;
@GetMapping("/member")
@ResponseBody
public String getOrder()
{
return imemberService.getUser();
}
}
2-2 SpringbootclientApplication.java
package com.dubbo.springbootclient;
import com.alibaba.dubbo.config.spring.context.annotation.EnableDubbo;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@EnableDubbo
@SpringBootApplication
public class SpringbootclientApplication {
public static void main(String[] args) {
SpringApplication.run(SpringbootclientApplication.class, args);
}
}
2-3 pom.xml
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.2.5.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.dubbo</groupId>
<artifactId>dubbospringboottestclient</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>dubbospringboottestclient</name>
<description>Demo project for Spring Boot</description>
<properties>
<java.version>1.8</java.version>
<project-build-sourceEncode>UTF-8</project-build-sourceEncode>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<curator-framework.version>4.0.1</curator-framework.version>
<zookeeper.version>3.6.0</zookeeper.version>
<dubbo.starter.version>0.2.0</dubbo.starter.version>
</properties>
<dependencies>
<dependency>
<artifactId>api</artifactId>
<groupId>com.dubbo</groupId>
<version>1.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>org.junit.vintage</groupId>
<artifactId>junit-vintage-engine</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>com.alibaba.boot</groupId>
<artifactId>dubbo-spring-boot-starter</artifactId>
<version>${dubbo.starter.version}</version>
</dependency>
<dependency>
<groupId>org.apache.curator</groupId>
<artifactId>curator-framework</artifactId>
<version>${curator-framework.version}</version>
</dependency>
<dependency>
<groupId>org.apache.zookeeper</groupId>
<artifactId>zookeeper</artifactId>
<version>${zookeeper.version}</version>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>jstl</artifactId>
<version>1.2</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.apache.tomcat.embed</groupId>
<artifactId>tomcat-embed-jasper</artifactId>
<version>9.0.33</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
2-4 application.yml
server:
port: 8089
dubbo:
application:
name: order
protocol:
name: dubbo
port: 20880
registry:
address: zookeeper://127.0.0.1:2181
consumer:
timeout: 5000
scan:
base-packages: com.dubbo.client
2-5 client-readme.txt
1)、provider项目Maven-install Jar包
pom.xml如下:
#<groupId>com.dubbo</groupId>
#<artifactId>provider</artifactId>
#<version>0.0.1-SNAPSHOT</version>
#<name>provider</name>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
2)、运行服务 provider.jar
cmd D:\temp\dubbo-case\dubbospringboottest\provider\target
java -jar provider-0.0.1-SNAPSHOT.jar&
3)、client项目sprintboot启动
http://localhost:8089/api/member
3、其他