“看看星空,会觉得自己很渺小,可能我们在宇宙中从来就是一个偶然。所以,无论什么事情,仔细想一想,都没有什么大不了的。这能帮助自己在遇到挫折时稳定心态,想得更开。” – 《腾讯传》
一、为啥整合 Dubbo 实现 SOA二、运行 springboot-dubbo-server 和 springboot-dubbo-client 工程三、springboot-dubbo-server 和 springboot-dubbo-client 工程配置详解
Spring Boot 系列文章:《Spring Boot 那些事》
1 | tar zxvf zookeeper-3.4.8. tar .gz |
1 2 | cd zookeeper-3.3.6 /conf vim zoo.cfg |
1 2 3 4 | tickTime=2000 dataDir= /javaee/zookeeper/data dataLogDir= /javaee/zookeeper/log clientPort=2181 |
1 2 | cd zookeeper-3.3.6 /bin . /zkServer .sh start |
然后,Maven 编译安装这个工程:
1 2 | cd springboot-learning-example mvn clean install |
右键运行 springboot-dubbo-client 工程 ClientApplication 应用启动类的 main 函数。Console 中出现如下:
1 2 3 4 5 | ... 2017-03-01 16:31:38.473 INFO 9896 --- [ main] o.s.j.e.a.AnnotationMBeanExporter : Registering beans for JMX exposure on startup 2017-03-01 16:31:38.538 INFO 9896 --- [ main] s.b.c.e.t.TomcatEmbeddedServletContainer : Tomcat started on port(s): 8081 (http) 2017-03-01 16:31:38.547 INFO 9896 --- [ main] org.spring.springboot.ClientApplication : Started ClientApplication in 6.055 seconds (JVM running for 7.026) City{ id =1, provinceId=2, cityName= '温岭' , description= '是我的故乡' } |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 | ├── pom.xml └── src └── main ├── java │ └── org │ └── spring │ └── springboot │ ├── ServerApplication.java │ ├── domain │ │ └── City.java │ └── dubbo │ ├── CityDubboService.java │ └── impl │ └── CityDubboServiceImpl.java └── resources └── application.properties |
pom.xml 中依赖了 spring-boot-starter-dubbo 工程,该项目地址是 https://github.com/teaey/spring-boot-starter-dubbo。pom.xml 配置如下
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 | <?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" > <modelVersion>4.0.0< /modelVersion > <groupId>springboot< /groupId > <artifactId>springboot-dubbo-server< /artifactId > <version>0.0.1-SNAPSHOT< /version > <name>springboot-dubbo 服务端:: 整合 Dubbo /ZooKeeper 详解 SOA 案例< /name > <!-- Spring Boot 启动父依赖 --> <parent> <groupId>org.springframework.boot< /groupId > <artifactId>spring-boot-starter-parent< /artifactId > <version>1.5.1.RELEASE< /version > < /parent > <properties> <dubbo-spring-boot>1.0.0< /dubbo-spring-boot > < /properties > <dependencies> <!-- Spring Boot Dubbo 依赖 --> <dependency> <groupId>io.dubbo.springboot< /groupId > <artifactId>spring-boot-starter-dubbo< /artifactId > <version>${dubbo-spring-boot}< /version > < /dependency > <!-- Spring Boot Web 依赖 --> <dependency> <groupId>org.springframework.boot< /groupId > <artifactId>spring-boot-starter-web< /artifactId > < /dependency > <!-- Spring Boot Test 依赖 --> <dependency> <groupId>org.springframework.boot< /groupId > <artifactId>spring-boot-starter- test < /artifactId > <scope> test < /scope > < /dependency > <!-- Junit --> <dependency> <groupId>junit< /groupId > <artifactId>junit< /artifactId > <version>4.12< /version > < /dependency > < /dependencies > < /project > |
1 2 3 4 5 6 | ## Dubbo 服务提供者配置 spring.dubbo.application.name=provider spring.dubbo.registry.address=zookeeper: //127 .0.0.1:2181 spring.dubbo.protocol.name=dubbo spring.dubbo.protocol.port=20880 spring.dubbo.scan=org.spring.springboot.dubbo |
1 2 3 4 5 6 7 8 | // 注册为 Dubbo 服务 @Service (version = "1.0.0" ) public class CityDubboServiceImpl implements CityDubboService { public City findCityByName(String cityName) { return new City(1L,2L, "温岭" , "是我的故乡" ); } } |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 | ├── pom.xml └── src └── main ├── java │ └── org │ └── spring │ └── springboot │ ├── ClientApplication.java │ ├── domain │ │ └── City.java │ └── dubbo │ ├── CityDubboConsumerService.java │ └── CityDubboService.java └── resources └── application.properties |
1 2 3 4 5 6 7 | ## 避免和 server 工程端口冲突 server.port=8081 ## Dubbo 服务消费者配置 spring.dubbo.application.name=consumer spring.dubbo.registry.address=zookeeper: //127 .0.0.1:2181 spring.dubbo.scan=org.spring.springboot.dubbo |
1 2 3 4 5 6 7 8 9 10 11 12 | @Component public class CityDubboConsumerService { @Reference (version = "1.0.0" ) CityDubboService cityDubboService; public void printCity() { String cityName= "温岭" ; City city = cityDubboService.findCityByName(cityName); System.out.println(city.toString()); } } |
1 2 3 4 5 6 7 8 9 10 11 | @SpringBootApplication public class ClientApplication { public static void main(String[] args) { // 程序启动入口 // 启动嵌入式的 Tomcat 并初始化 Spring 环境及其各 Spring 组件 ConfigurableApplicationContext run = SpringApplication.run(ClientApplication. class , args); CityDubboConsumerService cityService = run.getBean(CityDubboConsumerService. class ); cityService.printCity(); } } |
MyBatis-Plus 条件构造器-AbstractWrapperexists(String existsSql)exists(boolean condition, String existsSql)拼接EXISTS(sql...
该功能为了保护数据库配置及数据安全,在一定的程度上控制开发人员流动导致敏感信息泄露。3.3.2开始支持配置安全YML配置:// 加...
mybatis-mate为mp企业级模块,旨在更敏捷优雅处理数据。mybatis-mate示例:传送门数据审计(对账)mybatis-mate-audit对比两对...
MyBatis-Plus(简称 MP)是一个 MyBatis的增强工具,在 MyBatis 的基础上只做增强不做改变,为简化开发、提高效率而生。特性无侵...
多数据库支持如果配置了databaseIdProvider,你就可以在动态代码中使用名为“_databaseId”的变量来为不同的数据库构建...
问题Java程序员面对的最痛苦的事情之一就是在Java代码中嵌入SQL语句。这通常是因为需要动态生成SQL语句,不然我们可以将它们放到...
架构Hibernate 架构是分层的,作为数据访问层,你不必知道底层 API 。Hibernate 利用数据库以及配置数据来为应用程序提供持续性...
简介Hibernate 是由 Gavin King 于 2001 年创建的开放源代码的对象关系框架。它强大且高效的构建具有关系对象持久性和查询服务的...