本文将介绍使用springboot2.3.0集成apache dubbo2.7.7发布rest,dubbo服务,具体可参见apache dubbo官方示例,本文相关内容已在本地测试无误,如有问题欢迎留言拍砖。 属性文件application.yaml 接口api: 服务provider: 启动类: 测试: 完成,觉得有用,点个关注,【码农小麦】公众号同
pom依赖:<properties> <spring-boot.version>2.3.0.RELEASE</spring-boot.version> <dubbo.version>2.7.7</dubbo.version> </properties> <dependencyManagement> <dependencies> <!-- Spring Boot --> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-dependencies</artifactId> <version>${spring-boot.version}</version> <type>pom</type> <scope>import</scope> </dependency> <!-- Apache Dubbo --> <dependency> <groupId>org.apache.dubbo</groupId> <artifactId>dubbo-dependencies-bom</artifactId> <version>${dubbo.version}</version> <type>pom</type> <scope>import</scope> </dependency> </dependencies> </dependencyManagement> <dependencies> <dependency> <groupId>springboot-dubbo</groupId> <artifactId>api</artifactId> <version>1.0-SNAPSHOT</version> <scope>compile</scope> </dependency> <dependency> <groupId>org.apache.dubbo</groupId> <artifactId>dubbo</artifactId> <version>${dubbo.version}</version> </dependency> <dependency> <groupId>org.apache.dubbo</groupId> <artifactId>dubbo-dependencies-zookeeper</artifactId> <version>${dubbo.version}</version> <exclusions> <exclusion> <artifactId>slf4j-log4j12</artifactId> <groupId>org.slf4j</groupId> </exclusion> </exclusions> </dependency> <dependency> <groupId>org.apache.dubbo</groupId> <artifactId>dubbo-spring-boot-starter</artifactId> <version>${dubbo.version}</version> </dependency> <dependency> <groupId>org.apache.dubbo</groupId> <artifactId>dubbo-rpc-rest</artifactId> <version>${dubbo.version}</version> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter</artifactId> <exclusions> <exclusion> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-logging</artifactId> </exclusion> </exclusions> </dependency> <dependency> <groupId>org.apache.tomcat.embed</groupId> <artifactId>tomcat-embed-core</artifactId> <version>8.5.31</version> </dependency> <dependency> <groupId>org.apache.tomcat</groupId> <artifactId>tomcat-annotations-api</artifactId> <version>8.5.31</version> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-log4j2</artifactId> </dependency> </dependencies>
spring: application: name: provider dubbo: application: name: privider registry: address: zookeeper://127.0.0.1:2181 timeout: 20000 protocols: rest: name: rest server: tomcat port: 8080 dubbo: name: dubbo port: 20880 debug: true
import javax.ws.rs.*; import javax.ws.rs.core.MediaType; @Path("hello") @Consumes({MediaType.APPLICATION_JSON,MediaType.TEXT_XML}) @Produces({"application/json;charset=UTF-8"}) public interface IHelloService { @GET @Path("say") String hello(@QueryParam("name") String name); }
import com.star.api.IHelloService; import org.apache.dubbo.config.annotation.DubboService; @DubboService(interfaceClass = IHelloService.class,protocol = {"rest","dubbo"},version = "1.0") public class HelloServiceImpl implements IHelloService { @Override public String hello(String name) { return "hello " + name; } }
import org.apache.dubbo.config.spring.context.annotation.EnableDubbo; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; @SpringBootApplication @EnableDubbo(scanBasePackages = {"com.star.provider.service"}) public class ProviderApp { public static void main(String[] args) { SpringApplication.run(ProviderApp.class, args); } }
public static void main(String[] args) { ReferenceConfig<IHelloService> referenceConfig = new ReferenceConfig<>(); referenceConfig.setApplication(new ApplicationConfig("dubbo-demo-consumer")); RegistryConfig registryConfig = new RegistryConfig("zookeeper://127.0.0.1:2181"); registryConfig.setTimeout(10000); referenceConfig.setRegistry(registryConfig); referenceConfig.setInterface(IHelloService.class); referenceConfig.setTimeout(10000); referenceConfig.setVersion("1.0"); //referenceConfig.setProtocol("rest"); referenceConfig.setProtocol("dubbo"); IHelloService helloService = referenceConfig.get(); System.out.println(helloService.hello("dubbo latest")); }
本网页所有视频内容由 imoviebox边看边下-网页视频下载, iurlBox网页地址收藏管理器 下载并得到。
ImovieBox网页视频下载器 下载地址: ImovieBox网页视频下载器-最新版本下载
本文章由: imapbox邮箱云存储,邮箱网盘,ImageBox 图片批量下载器,网页图片批量下载专家,网页图片批量下载器,获取到文章图片,imoviebox网页视频批量下载器,下载视频内容,为您提供.
阅读和此文章类似的: 全球云计算