├── .gitignore
├── README.md
├── cloud-central
├── README.md
├── pom.xml
└── src
│ ├── main
│ ├── java
│ │ └── com
│ │ │ └── github
│ │ │ └── dreamylost
│ │ │ └── CloudApplication.java
│ └── resources
│ │ ├── application-peer1.properties
│ │ ├── application-peer2.properties
│ │ └── application.properties
│ └── test
│ └── java
│ └── com
│ └── github
│ └── dreamylost
│ └── CloudApplicationTests.java
├── cloud-config-client
├── pom.xml
└── src
│ ├── main
│ ├── java
│ │ └── com
│ │ │ └── github
│ │ │ └── dreamylost
│ │ │ └── config
│ │ │ └── client
│ │ │ ├── ClientApplication.java
│ │ │ └── TestController.java
│ └── resources
│ │ ├── application.properties
│ │ └── bootstrap.properties
│ └── test
│ └── java
│ └── com
│ └── github
│ └── dreamylost
│ └── config
│ └── client
│ └── ClientApplicationTests.java
├── cloud-config-server
├── config-repository
│ ├── springcloudconfigclientdemo-dev.properties
│ ├── springcloudconfigclientdemo-prod.properties
│ ├── springcloudconfigclientdemo-test.properties
│ └── springcloudconfigclientdemo.properties
├── pom.xml
└── src
│ ├── main
│ ├── java
│ │ └── com
│ │ │ └── github
│ │ │ └── dreamylost
│ │ │ └── config
│ │ │ └── server
│ │ │ └── ServerApplication.java
│ └── resources
│ │ └── application.properties
│ └── test
│ └── java
│ └── com
│ └── github
│ └── dreamylost
│ └── config
│ └── server
│ └── SpringCloudConfigDemoApplicationTests.java
├── cloud-hello-provider
├── README.md
├── pom.xml
└── src
│ ├── main
│ ├── java
│ │ └── com
│ │ │ └── github
│ │ │ └── dreamylost
│ │ │ └── HelloApplication.java
│ └── resources
│ │ └── application.properties
│ └── test
│ └── java
│ └── com
│ └── github
│ └── dreamylost
│ └── HelloApplicationTests.java
├── cloud-ribbon-consumer
├── README.md
├── pom.xml
└── src
│ ├── main
│ ├── java
│ │ └── com
│ │ │ └── github
│ │ │ └── dreamylost
│ │ │ ├── ConsumerController.java
│ │ │ ├── HelloService.java
│ │ │ ├── RibbonConsumerApplication.java
│ │ │ └── UserService.java
│ └── resources
│ │ └── application.properties
│ └── test
│ └── java
│ └── com
│ └── github
│ └── dreamylost
│ └── RibbonConsumerApplicationTests.java
├── cloud-user-provider
├── .gitignore
├── pom.xml
└── src
│ ├── main
│ ├── java
│ │ └── com
│ │ │ └── github
│ │ │ └── dreamylost
│ │ │ ├── User.java
│ │ │ └── UserApplication.java
│ └── resources
│ │ └── application.properties
│ └── test
│ └── java
│ └── com
│ └── github
│ └── dreamylost
│ └── UserApplicationTests.java
├── cxf
├── README.md
├── pom.xml
└── src
│ ├── main
│ ├── java
│ │ └── com
│ │ │ └── github
│ │ │ └── dreamylost
│ │ │ ├── Application.java
│ │ │ ├── CxfConfig.java
│ │ │ ├── SpringController.java
│ │ │ ├── dao
│ │ │ └── StudentDao.java
│ │ │ ├── entity
│ │ │ ├── Student.java
│ │ │ └── Students.java
│ │ │ ├── resource
│ │ │ ├── StudentInterface.java
│ │ │ └── StudentInterfaceImpl.java
│ │ │ ├── service
│ │ │ └── StudentService.java
│ │ │ └── serviceImpl
│ │ │ └── StudentServiceImpl.java
│ └── resources
│ │ ├── application.properties
│ │ ├── cxf-config.xml
│ │ ├── demo.sql
│ │ ├── mapper
│ │ └── StudentMapper.xml
│ │ └── mybatis-config.xml
│ └── test
│ └── java
│ └── com
│ └── github
│ └── dreamylost
│ └── CxfSpec.java
├── dubbo-api
├── pom.xml
└── src
│ └── main
│ └── java
│ └── com
│ └── github
│ └── dreamylost
│ ├── City.java
│ ├── CityDubboService.java
│ └── IHelloService.java
├── dubbo-consumer
├── pom.xml
└── src
│ └── main
│ ├── java
│ └── com
│ │ └── github
│ │ └── dreamylost
│ │ ├── CityConsumer.java
│ │ ├── ConsumerApplication.java
│ │ └── HelloConsumer.java
│ └── resources
│ └── application.properties
├── dubbo-provider
├── pom.xml
└── src
│ └── main
│ ├── java
│ └── com
│ │ └── github
│ │ └── dreamylost
│ │ ├── CityDubboServiceImpl.java
│ │ ├── HelloServiceImpl.java
│ │ └── ProviderApplication.java
│ └── resources
│ └── application.properties
├── graphql-complete
├── pom.xml
└── src
│ └── main
│ ├── java
│ └── com
│ │ └── github
│ │ └── dreamylost
│ │ ├── GraphQLController.java
│ │ ├── GraphQLProvider.java
│ │ ├── HttpExampleApplication.java
│ │ ├── Instrumentation
│ │ ├── CustomInstrumentation.java
│ │ └── FieldValidationBuilder.java
│ │ ├── StarWarsWiring.java
│ │ ├── cache
│ │ ├── GraphQLCacheHelper.java
│ │ └── LRUCache.java
│ │ ├── context
│ │ ├── Context.java
│ │ └── ContextProvider.java
│ │ ├── dao
│ │ └── StarWarsData.java
│ │ ├── domain
│ │ ├── Droid.java
│ │ ├── Episode.java
│ │ ├── FilmCharacter.java
│ │ └── Human.java
│ │ ├── fetcher
│ │ └── GraphQLFetcherHelper.java
│ │ ├── resolver
│ │ └── GraphQLResolverHelper.java
│ │ └── scalar
│ │ └── EmailScalar.java
│ └── resources
│ ├── application.properties
│ ├── starWarsSchemaAnnotated.graphqls
│ └── static
│ └── index.html
├── graphql
├── pom.xml
└── src
│ └── main
│ ├── java
│ └── com
│ │ └── github
│ │ └── dreamylost
│ │ ├── Application.java
│ │ ├── DateFormatting.java
│ │ ├── GraphQLController.java
│ │ ├── GraphQLDataFetchers.java
│ │ └── GraphQLProvider.java
│ └── resources
│ ├── application.properties
│ ├── schema.graphql
│ └── static
│ └── index.html
├── mongodb
├── pom.xml
└── src
│ └── main
│ ├── java
│ └── com
│ │ └── github
│ │ └── dreamylost
│ │ ├── Application.java
│ │ ├── controller
│ │ └── TestController.java
│ │ ├── entity
│ │ └── User.java
│ │ ├── repository
│ │ └── UserRepository.java
│ │ └── service
│ │ ├── UserService.java
│ │ └── impl
│ │ └── UserServiceImpl.java
│ └── resources
│ └── application.yml
├── pom.xml
├── redis
├── pom.xml
└── src
│ └── main
│ ├── java
│ └── com
│ │ └── github
│ │ └── dreamylost
│ │ ├── Application.java
│ │ ├── RedisConfig.java
│ │ ├── TestController.java
│ │ └── User.java
│ └── resources
│ └── application.yml
├── swagger
├── pom.xml
└── src
│ ├── main
│ ├── java
│ │ └── com
│ │ │ └── github
│ │ │ └── dreamylost
│ │ │ ├── Application.java
│ │ │ ├── SwaggerConfig.java
│ │ │ └── TestController.java
│ └── resources
│ │ └── application.properties
│ └── test
│ └── java
│ └── com
│ └── github
│ └── dreamylost
│ └── ApplicationTests.java
├── undertow
├── pom.xml
└── src
│ └── main
│ ├── java
│ └── com
│ │ └── github
│ │ └── dreamylost
│ │ ├── Application.java
│ │ └── TestController.java
│ └── resources
│ └── application.yml
├── webflow-booking
├── pom.xml
└── src
│ ├── main
│ ├── java
│ │ └── com
│ │ │ └── github
│ │ │ └── dreamylost
│ │ │ └── booking
│ │ │ ├── config
│ │ │ ├── DataSourceConfig.java
│ │ │ ├── DispatcherServletInitializer.java
│ │ │ ├── SecurityConfig.java
│ │ │ ├── SecurityWebApplicationInitializer.java
│ │ │ ├── WebFlowConfig.java
│ │ │ └── WebMvcConfig.java
│ │ │ ├── controller
│ │ │ └── HotelsController.java
│ │ │ ├── mode
│ │ │ ├── Booking.java
│ │ │ ├── Hotel.java
│ │ │ ├── SearchCriteria.java
│ │ │ └── User.java
│ │ │ ├── service
│ │ │ ├── BookingService.java
│ │ │ └── BookingServiceImpl.java
│ │ │ └── util
│ │ │ ├── Amenity.java
│ │ │ ├── BookingDateRange.java
│ │ │ ├── BookingDateRangeValidator.java
│ │ │ └── BookingFlowHandler.java
│ ├── resources
│ │ ├── META-INF
│ │ │ └── persistence.xml
│ │ ├── import.sql
│ │ └── log4j2.xml
│ └── webapp
│ │ ├── META-INF
│ │ └── MANIFEST.MF
│ │ ├── WEB-INF
│ │ ├── hotels
│ │ │ ├── booking
│ │ │ │ ├── booking-flow.xml
│ │ │ │ ├── enterBookingDetails.jsp
│ │ │ │ ├── messages.jsp
│ │ │ │ ├── messages.properties
│ │ │ │ ├── reviewBooking.jsp
│ │ │ │ └── views.xml
│ │ │ ├── bookingsTable.jsp
│ │ │ ├── list.jsp
│ │ │ ├── search.jsp
│ │ │ ├── searchForm.jsp
│ │ │ ├── show.jsp
│ │ │ └── views.xml
│ │ ├── intro.jsp
│ │ ├── layouts
│ │ │ ├── standard.jsp
│ │ │ └── views.xml
│ │ ├── login.jsp
│ │ ├── logoutSuccess.jsp
│ │ └── views.xml
│ │ ├── images
│ │ ├── bg.gif
│ │ ├── btn.bg.gif
│ │ ├── diplomat.jpg
│ │ ├── header.jpg
│ │ ├── input.bg.gif
│ │ ├── powered-by-spring.png
│ │ ├── spring-logo.jpg
│ │ ├── springone2gx.jpeg
│ │ ├── th.bg.gif
│ │ ├── tse.gif
│ │ └── webflow-logo.jpg
│ │ └── styles
│ │ ├── blueprint
│ │ ├── icons
│ │ │ ├── cross.png
│ │ │ ├── key.png
│ │ │ └── tick.png
│ │ ├── ie.css
│ │ ├── plugins
│ │ │ ├── buttons
│ │ │ │ ├── icons
│ │ │ │ │ ├── cross.png
│ │ │ │ │ ├── key.png
│ │ │ │ │ └── tick.png
│ │ │ │ ├── readme.txt
│ │ │ │ └── screen.css
│ │ │ ├── fancy-type
│ │ │ │ ├── readme.txt
│ │ │ │ └── screen.css
│ │ │ ├── link-icons
│ │ │ │ ├── icons
│ │ │ │ │ ├── doc.png
│ │ │ │ │ ├── email.png
│ │ │ │ │ ├── external.png
│ │ │ │ │ ├── feed.png
│ │ │ │ │ ├── im.png
│ │ │ │ │ ├── pdf.png
│ │ │ │ │ ├── visited.png
│ │ │ │ │ └── xls.png
│ │ │ │ ├── readme.txt
│ │ │ │ └── screen.css
│ │ │ └── rtl
│ │ │ │ ├── readme.txt
│ │ │ │ └── screen.css
│ │ ├── print.css
│ │ ├── screen.css
│ │ └── src
│ │ │ ├── forms.css
│ │ │ ├── grid.css
│ │ │ ├── grid.png
│ │ │ ├── ie.css
│ │ │ ├── print.css
│ │ │ ├── reset.css
│ │ │ └── typography.css
│ │ └── booking.css
│ └── test
│ └── java
│ └── com
│ └── github
│ └── dreamylost
│ └── booking
│ └── BookingFlowExecutionTests.java
├── webflux-functional
├── pom.xml
└── src
│ ├── main
│ ├── java
│ │ └── com
│ │ │ └── github
│ │ │ └── dreamylost
│ │ │ └── webflux
│ │ │ ├── SpringbootWebfluxApplication.java
│ │ │ ├── funtctional
│ │ │ ├── handler
│ │ │ │ └── UserHandler.java
│ │ │ └── router
│ │ │ │ └── RoutingConfiguration.java
│ │ │ ├── model
│ │ │ └── User.java
│ │ │ └── service
│ │ │ ├── IUserService.java
│ │ │ └── impl
│ │ │ └── UserServiceImpl.java
│ └── resources
│ │ └── application.yml
│ └── test
│ └── java
│ └── com
│ └── github
│ └── dreamylost
│ └── webflux
│ └── SpringbootWebfluxApplicationTests.java
└── webflux
├── README.md
├── pom.xml
└── src
├── main
├── java
│ └── com
│ │ └── github
│ │ └── dreamylost
│ │ └── webflux
│ │ ├── SpringbootWebfluxApplication.java
│ │ ├── User.java
│ │ └── WebFluxController.java
└── resources
│ └── application.yml
└── test
└── java
└── com
└── github
└── dreamylost
└── webflux
└── SpringbootWebfluxApplicationTests.java
/.gitignore:
--------------------------------------------------------------------------------
1 | /target/
2 | !.mvn/wrapper/maven-wrapper.jar
3 |
4 | ### STS ###
5 | .apt_generated
6 | .classpath
7 | .factorypath
8 | .project
9 | .settings
10 | .springBeans
11 | .sts4-cache
12 |
13 | ### IntelliJ IDEA ###
14 | .idea
15 | *.iws
16 | *.iml
17 | *.ipr
18 |
19 | ### NetBeans ###
20 | /nbproject/private/
21 | /build/
22 | /nbbuild/
23 | /dist/
24 | /nbdist/
25 | /.nb-gradle/
26 |
27 | mvnw
28 | mvnw.cmd
29 | target/
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | springboot-exmaples
2 | --
3 |
4 | $ 表示子模块是依赖父级项目的(子模块本身就是多个模块组成的,如dubbo)
5 |
6 | > cxf
7 |
8 | ```
9 | 整合SpringBoot MySQL Mybatis CXF/JSR-RS
10 | 实现WebServices
11 | 实现Restful
12 | ```
13 |
14 | * 使用
15 | ```
16 | 1.mysql中新建demo库运行resources下sql文件
17 | 2.修改application.properties修改数据源
18 | 3.启动Application.java类
19 | ```
20 |
21 | > mongodb
22 |
23 | * 使用
24 | ```
25 | 1.启动Application.java类
26 | 1.新增 127.0.0.1:9000/save
27 | 2.查询单个 127.0.0.1:9000/findByName
28 | 3.查询List 127.0.0.1:9000/find
29 | ```
30 |
31 | > swagger
32 |
33 | * 使用
34 | ```
35 | 1.启动Application.java类
36 | 2.访问localhost:8080/swagger-ui.html
37 | ```
38 |
39 | > graphql
40 |
41 | * 使用
42 | ```
43 | 1.启动Application.java类
44 | 2.访问http://localhost:8080/
45 | 3.查询
46 | 调用方法hello:无参方法
47 | {
48 | hello
49 | }
50 | 调用方法echo:有参方法
51 | {
52 | echo(toEcho:"charming")
53 | }
54 | ```
55 |
56 | > graphql-complete
57 |
58 | * 使用
59 | ```
60 | 1.启动 Application.java
61 | 2.访问http://localhost:8080/
62 | 3.查询
63 | 调用droid方法:
64 | {
65 | droid(id: "1001") {
66 | id
67 | }
68 | }
69 | 调用hero方法:枚举参数
70 | {
71 | hero(episode: NEWHOPE) {
72 | id
73 | }
74 | }
75 | 其他方法参考 starWarsSchemaAnnotated.graphqls
76 | ```
77 |
78 | > dubbo $
79 |
80 | * 使用
81 | ```
82 | 1.启动zookeeper
83 | 2.启动dubbo-admin客户端(需自己将官方的war放进tomcat的webapps/ROOT下) tomcat端口
84 | 3.启动生产者(dubbo-provider) 端口8081
85 | 4.启动消费者(duboo-consumer) 端口8082
86 | 5.查询
87 | 1)浏览器输入: http://127.0.0.1:8082/sayHello/dubbo
88 | 2)返回String: Hello dubbo
89 | 3)浏览器输入:http://localhost:8082/getCity
90 | 4)返回JSON对象:
91 | {
92 | "id": 1,
93 | "provinceId": 2,
94 | "cityName": "南昌",
95 | "description": "是我的故乡"
96 | }
97 | 使用dubbo的管理平台(dubbo-admin应用放在ROOT下则路径:http://localhost:8088) 查看结果,初始账户为:root/root
98 | ```
99 | > spring cloud
100 |
101 | 包含组件说明
102 |
103 | * Eureka
104 | * Ribbon
105 | * Config
106 | * Hystrix
107 |
108 | 模块说明
109 |
110 | * 服务注册中心(cloud-central)
111 | * hello服务提供者(cloud-hello-provider)
112 | * user服务提供者(cloud-user-provider)
113 | * 负载均衡/断路器(cloud-ribbon-consumer)
114 | * 配置中心 服务端(cloud-config-server)
115 | * 配置调用 客户端(cloud-config-client)
116 |
117 | ```
118 | 1.启动cloud-central,修改 spring.profiles.active=peer2,再运行一个实例
119 | 2.启动cloud-hello-provider 支持启动多实例(随机端口)
120 | 3.启动cloud-user-provider 支持启动多实例(随机端口)
121 | 4.启动cloud-ribbon-consumer
122 | 5.启动cloud-config-server
123 | 6.启动cloud-config-client
124 | ```
125 |
126 | > undertow
127 |
128 | * 使用
129 | ```
130 | 1.启动Application.java类
131 | 2.访问 http://localhost:8084/
132 | ```
133 |
134 | > redis
135 |
136 | * 使用
137 | ```
138 | 1.启动redis-server
139 | 2.启动Application.java类
140 | 3.请求http://localhost:8081/?p=参数
141 | 4.连接redis-cli,查看key=hello value=[\"com.github.dreamylost.User\",{\"uid\":123,\"userName\":\"zhangsan\",\"passWord\":\"pwd\"}]
142 | ```
143 |
--------------------------------------------------------------------------------
/cloud-central/README.md:
--------------------------------------------------------------------------------
1 |
2 |
3 | 服务注册中心: Eureka提供的服务端,提供服务注册与发现功能
4 |
--------------------------------------------------------------------------------
/cloud-central/src/main/java/com/github/dreamylost/CloudApplication.java:
--------------------------------------------------------------------------------
1 | package com.github.dreamylost;
2 |
3 | import org.springframework.boot.SpringApplication;
4 | import org.springframework.boot.autoconfigure.SpringBootApplication;
5 | import org.springframework.cloud.netflix.eureka.server.EnableEurekaServer;
6 |
7 | @EnableEurekaServer // 启动服务注册中心
8 | @SpringBootApplication
9 | public class CloudApplication {
10 |
11 | public static void main(String[] args) {
12 | SpringApplication.run(CloudApplication.class, args);
13 | }
14 | }
15 |
--------------------------------------------------------------------------------
/cloud-central/src/main/resources/application-peer1.properties:
--------------------------------------------------------------------------------
1 | spring.application.name=cloud-central
2 | server.port=1111
3 | eureka.instance.hostname=peer1
4 | #指向peer2 在etc hosts配置 127.0.0.1 peer2,
5 | #使用ip eureka.instance.prefer-ip-address=true
6 | eureka.client.serviceUrl.defaultZone=http://peer2:1112/eureka/
7 | spring.profiles.active=peer1
8 | #必须加上,分别为注册自己,寻找服务
9 | eureka.client.register-with-eureka=true
10 | eureka.client.fetch-registry=true
11 | #本地调试,关闭注册中心的自我保护
12 | eureka.server.enable-self-preservation=false
--------------------------------------------------------------------------------
/cloud-central/src/main/resources/application-peer2.properties:
--------------------------------------------------------------------------------
1 | spring.application.name=cloud-central
2 | server.port=1112
3 | eureka.instance.hostname=peer2
4 | #指向peer1
5 | eureka.client.serviceUrl.defaultZone=http://peer1:1111/eureka/
6 | spring.profiles.active=peer2
7 | eureka.client.register-with-eureka=true
8 | eureka.client.fetch-registry=true
9 | eureka.server.enable-self-preservation=false
--------------------------------------------------------------------------------
/cloud-central/src/main/resources/application.properties:
--------------------------------------------------------------------------------
1 | #actuator
2 | #关闭权限,才能访问端点
3 | management.security.enabled=false
4 |
5 | #eureka,默认将自己作为客户端注册自己
6 | server.port=1111
7 | eureka.instance.hostname=localhost
8 | #向注册中心注册自己
9 | #高可用模式下 在 application-peer1.properties 与 application-peer2.properties 中显示 指定 这两个属性值为true即可。
10 | eureka.client.register-with-eureka=true
11 | #不需要检索服务
12 | eureka.client.fetch-registry=true
13 | #访问路径
14 | eureka.client.serverUrl.defaultZone=http://${euraka.instance.hostname}:${server.port}/eureka/
15 | #修改active,模拟启动2个不同的服务注册中心
16 | spring.profiles.active=peer1
17 |
--------------------------------------------------------------------------------
/cloud-central/src/test/java/com/github/dreamylost/CloudApplicationTests.java:
--------------------------------------------------------------------------------
1 | package com.github.dreamylost;
2 |
3 | import org.junit.Test;
4 | import org.junit.runner.RunWith;
5 | import org.springframework.boot.test.context.SpringBootTest;
6 | import org.springframework.test.context.junit4.SpringRunner;
7 |
8 | @RunWith(SpringRunner.class)
9 | @SpringBootTest
10 | public class CloudApplicationTests {
11 |
12 | @Test
13 | public void contextLoads() {
14 | }
15 |
16 | }
17 |
--------------------------------------------------------------------------------
/cloud-config-client/src/main/java/com/github/dreamylost/config/client/ClientApplication.java:
--------------------------------------------------------------------------------
1 | package com.github.dreamylost.config.client;
2 |
3 | import org.springframework.boot.SpringApplication;
4 | import org.springframework.boot.autoconfigure.SpringBootApplication;
5 | import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
6 |
7 | /**
8 | * 通过bootstrap.properties实现在配置中心获取额外配置来代替本地配置
9 | *
10 | * 而不是在application配置文件中,bootstrap配置文件会比application更加早的加载。
11 | */
12 | @SpringBootApplication
13 | @EnableDiscoveryClient
14 | public class ClientApplication {
15 |
16 | public static void main(String[] args) {
17 | SpringApplication.run(ClientApplication.class, args);
18 | }
19 | }
20 |
--------------------------------------------------------------------------------
/cloud-config-client/src/main/java/com/github/dreamylost/config/client/TestController.java:
--------------------------------------------------------------------------------
1 | package com.github.dreamylost.config.client;
2 |
3 | import org.springframework.beans.factory.annotation.Autowired;
4 | import org.springframework.beans.factory.annotation.Value;
5 | import org.springframework.cloud.context.config.annotation.RefreshScope;
6 | import org.springframework.core.env.Environment;
7 | import org.springframework.web.bind.annotation.RequestMapping;
8 | import org.springframework.web.bind.annotation.RestController;
9 |
10 | /**
11 | * @date: 2018-07-11
12 | * @author: liguobin
13 | * @description: 测试配置中心
14 | */
15 | @RefreshScope//如果代码中需要动态刷新配置,在需要的类上加上该注解就行
16 | @RestController
17 | public class TestController {
18 |
19 | @Value("${from}")
20 | private String form;
21 |
22 | @Autowired
23 | private Environment env;
24 |
25 | @RequestMapping("from")
26 | public String from() {
27 | String env1 = env.getProperty("from", "undefined");
28 | String env2 = this.form;
29 | return "@Value:" + env1 + "------" + "Env:" + env2;
30 | }
31 | }
32 |
33 |
--------------------------------------------------------------------------------
/cloud-config-client/src/main/resources/application.properties:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jxnu-liguobin/springboot-examples/ae7150ec95a2d16829e80b200eb90c26a1572f57/cloud-config-client/src/main/resources/application.properties
--------------------------------------------------------------------------------
/cloud-config-client/src/main/resources/bootstrap.properties:
--------------------------------------------------------------------------------
1 | #对应配置文件的application部分
2 | spring.application.name=cloud-config-client
3 | #profile
4 | spring.cloud.config.profile=test
5 | #label
6 | spring.cloud.config.label=master
7 | #配置中心的地址
8 | #spring.cloud-central.config.uri=http://127.0.0.1:8088/
9 | server.port=8089
10 | #模拟的是一个客户端向两个服务注册中心【peer1,peer2】进行注册,可以使用随机数端口多次启动项目,模拟多个客户端,构成多个服务向多个服务注册中心进行注册,实现高可用
11 | #但是这里我没有使用随机数/0端口
12 | eureka.client.serviceUrl.defaultZone=http://peer1:1111/eureka/,http://peer2:1112/eureka/
13 | #开启通过服务来访问config的功能,并指定服务名
14 | spring.cloud.config.discovery.enabled=true
15 | spring.cloud.config.discovery.service-id=cloud-config-server
16 | #关闭权限验证,访问actuator端点,使用http://localhost:8089/refresh 刷新git仓库配置
17 | management.security.enabled=false
18 |
19 |
--------------------------------------------------------------------------------
/cloud-config-client/src/test/java/com/github/dreamylost/config/client/ClientApplicationTests.java:
--------------------------------------------------------------------------------
1 | package com.github.dreamylost.config.client;
2 |
3 | import org.junit.Test;
4 | import org.junit.runner.RunWith;
5 | import org.springframework.boot.test.context.SpringBootTest;
6 | import org.springframework.test.context.junit4.SpringRunner;
7 |
8 | @RunWith(SpringRunner.class)
9 | @SpringBootTest
10 | public class ClientApplicationTests {
11 |
12 | @Test
13 | public void contextLoads() {
14 | }
15 |
16 | }
17 |
--------------------------------------------------------------------------------
/cloud-config-server/config-repository/springcloudconfigclientdemo-dev.properties:
--------------------------------------------------------------------------------
1 | from=git-dev-1.0
--------------------------------------------------------------------------------
/cloud-config-server/config-repository/springcloudconfigclientdemo-prod.properties:
--------------------------------------------------------------------------------
1 | from=git-prod-1.0
--------------------------------------------------------------------------------
/cloud-config-server/config-repository/springcloudconfigclientdemo-test.properties:
--------------------------------------------------------------------------------
1 | from=git-test-1.0
--------------------------------------------------------------------------------
/cloud-config-server/config-repository/springcloudconfigclientdemo.properties:
--------------------------------------------------------------------------------
1 | from=git-default-1.0
--------------------------------------------------------------------------------
/cloud-config-server/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 | 4.0.0
5 |
6 | com.github.dreamylost
7 | cloud-config-server
8 | 0.0.1-SNAPSHOT
9 | jar
10 |
11 | cloud-config-server
12 | Demo project for Spring Boot
13 |
14 |
15 | org.springframework.boot
16 | spring-boot-starter-parent
17 | 1.5.13.RELEASE
18 |
19 |
20 |
21 |
22 | UTF-8
23 | UTF-8
24 | Dalston.SR5
25 |
26 |
27 |
28 |
29 |
30 | org.springframework.cloud
31 | spring-cloud-config-server
32 |
33 |
34 |
35 | org.springframework.boot
36 | spring-boot-starter-test
37 | test
38 |
39 |
40 |
41 | org.springframework.cloud
42 | spring-cloud-starter-eureka
43 |
44 |
45 |
46 |
47 |
48 |
49 | org.springframework.cloud
50 | spring-cloud-dependencies
51 | ${spring-cloud.version}
52 | pom
53 | import
54 |
55 |
56 |
57 |
58 |
59 |
60 |
61 | org.springframework.boot
62 | spring-boot-maven-plugin
63 |
64 |
65 | org.apache.maven.plugins
66 | maven-compiler-plugin
67 |
68 | 8
69 | 8
70 |
71 |
72 |
73 |
74 |
75 |
76 |
77 |
--------------------------------------------------------------------------------
/cloud-config-server/src/main/java/com/github/dreamylost/config/server/ServerApplication.java:
--------------------------------------------------------------------------------
1 | package com.github.dreamylost.config.server;
2 |
3 | import org.springframework.boot.SpringApplication;
4 | import org.springframework.boot.autoconfigure.SpringBootApplication;
5 | import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
6 | import org.springframework.cloud.config.server.EnableConfigServer;
7 |
8 | /**
9 | * 为了方便不再加分支的config版本控制
10 | * 只记录匹配规则:其中label分支名,profile是环境名
11 | * /{application}/{profile}[/{label}]
12 | * /{application}-{profile}.yml
13 | * /{label}/{application}-{profile}.yml
14 | * /{application}-{profile}.properties
15 | * /{label}/{application}-{profile}.properties
16 | *
17 | * config-repository文件是需要放在git上的配置文件
18 | */
19 | @SpringBootApplication
20 | @EnableConfigServer//开启SpringCloud Config 服务端功能
21 | @EnableDiscoveryClient
22 | public class ServerApplication {
23 |
24 | public static void main(String[] args) {
25 | SpringApplication.run(ServerApplication.class, args);
26 | }
27 | }
28 |
--------------------------------------------------------------------------------
/cloud-config-server/src/main/resources/application.properties:
--------------------------------------------------------------------------------
1 | spring.application.name=cloud-config-server
2 | server.port=8088
3 | spring.cloud.config.server.git.uri=https://github.com/jxnu-liguobin/springboot-examples/
4 | spring.cloud.config.server.git.search-paths=cloud-config-server/config-repository
5 | spring.cloud.config.server.git.username=jxnu-liguobin
6 | spring.cloud.config.server.git.password=xxxxxxx
7 | #cloud是整个仓库项目的服务注册中心,peer1,peer2是os的host文件中配置的域名
8 | eureka.client.serviceUrl.defaultZone=http://peer1:1111/eureka/,http://peer2:1112/eureka/
--------------------------------------------------------------------------------
/cloud-config-server/src/test/java/com/github/dreamylost/config/server/SpringCloudConfigDemoApplicationTests.java:
--------------------------------------------------------------------------------
1 | package com.github.dreamylost.config.server;
2 |
3 | import org.junit.Test;
4 | import org.junit.runner.RunWith;
5 | import org.springframework.boot.test.context.SpringBootTest;
6 | import org.springframework.test.context.junit4.SpringRunner;
7 |
8 | @RunWith(SpringRunner.class)
9 | @SpringBootTest
10 | public class SpringCloudConfigDemoApplicationTests {
11 |
12 | @Test
13 | public void contextLoads() {
14 | }
15 |
16 | }
17 |
--------------------------------------------------------------------------------
/cloud-hello-provider/README.md:
--------------------------------------------------------------------------------
1 |
2 |
3 | 服务提供者: 可以是SpringBoot应用,也可以是其他技术平台且遵循Eureka通信机制的应用。
4 | 将自己提供的服务注册到Eureka,以提供其他应用发现和使用
5 |
--------------------------------------------------------------------------------
/cloud-hello-provider/src/main/java/com/github/dreamylost/HelloApplication.java:
--------------------------------------------------------------------------------
1 | package com.github.dreamylost;
2 |
3 | import org.springframework.beans.factory.annotation.Autowired;
4 | import org.springframework.boot.SpringApplication;
5 | import org.springframework.boot.autoconfigure.SpringBootApplication;
6 | import org.springframework.cloud.client.ServiceInstance;
7 | import org.springframework.cloud.client.discovery.DiscoveryClient;
8 | import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
9 | import org.springframework.web.bind.annotation.RequestMapping;
10 | import org.springframework.web.bind.annotation.RequestMethod;
11 | import org.springframework.web.bind.annotation.RestController;
12 |
13 | @RestController
14 | @SpringBootApplication
15 | @EnableDiscoveryClient // 激活发现
16 | public class HelloApplication {
17 |
18 | public static void main(String[] args) {
19 | SpringApplication.run(HelloApplication.class, args);
20 | }
21 |
22 | @Autowired
23 | private DiscoveryClient client;
24 |
25 | @SuppressWarnings("deprecation")
26 | @RequestMapping(value = "/cloud-central-hello-provider", method = RequestMethod.GET)
27 | public String index() {
28 | ServiceInstance instance = client.getLocalServiceInstance();
29 | System.out.println("生成者:/cloud-central-hello-provider,host:" + instance.getHost() + ", service_id:" + instance.getServiceId());
30 | return "生产者 <<<" + " Hello World >>>";
31 | }
32 |
33 | }
34 |
--------------------------------------------------------------------------------
/cloud-hello-provider/src/main/resources/application.properties:
--------------------------------------------------------------------------------
1 | #关闭权限,才能访问端点
2 | management.security.enabled=false
3 | #server.port=8080
4 | #服务命名
5 | spring.application.name=cloud-hello-provider
6 | #指定服务注册中心的地址
7 | eureka.client.serviceUrl.defaultZone=http://peer1:1111/eureka/,http://peer2:1112/eureka/
8 | #修改端口,模拟启动第二个服务8081
9 | #使用随机造成注册与tomcat端口不同,server.port=${random.int[10000,19999]}但是服务注册端口与tomcat端口不同
10 | server.port=0
11 | #使用随机数,生成随机端口,指定服务的实例名
12 | eureka.instance.instanceId=${spring.application.name}:${random.int[10000,19999]}
13 | #使用随机数,生成随机端口,指定服务的实例名
14 | #使用actuator代替默认心跳
15 | eureka.client.healthcheck.enabled=true
--------------------------------------------------------------------------------
/cloud-hello-provider/src/test/java/com/github/dreamylost/HelloApplicationTests.java:
--------------------------------------------------------------------------------
1 | package com.github.dreamylost;
2 |
3 | import org.junit.Test;
4 | import org.junit.runner.RunWith;
5 | import org.springframework.boot.test.context.SpringBootTest;
6 | import org.springframework.test.context.junit4.SpringRunner;
7 |
8 | @RunWith(SpringRunner.class)
9 | @SpringBootTest
10 | public class HelloApplicationTests {
11 |
12 | @Test
13 | public void contextLoads() {
14 | }
15 |
16 | }
17 |
--------------------------------------------------------------------------------
/cloud-ribbon-consumer/README.md:
--------------------------------------------------------------------------------
1 |
2 |
3 | 服务消费者: 消费者从服务注册中心获取服务列表,从而消费者可以知道去何处调用其所需要的服务。
4 | 使用Ribbon,很多时候,客户端既是服务提供者,也是服务消费者
5 |
--------------------------------------------------------------------------------
/cloud-ribbon-consumer/src/main/java/com/github/dreamylost/ConsumerController.java:
--------------------------------------------------------------------------------
1 | package com.github.dreamylost;
2 |
3 | import org.springframework.beans.factory.annotation.Autowired;
4 | import org.springframework.web.bind.annotation.RequestMapping;
5 | import org.springframework.web.bind.annotation.RequestMethod;
6 | import org.springframework.web.bind.annotation.RestController;
7 | import org.springframework.web.client.RestTemplate;
8 |
9 | import java.util.concurrent.ExecutionException;
10 |
11 | /**
12 | * @author 梦境迷离
13 | * @description
14 | * @time 2018年4月5日
15 | */
16 | @RestController
17 | public class ConsumerController {
18 |
19 | @Autowired
20 | private RestTemplate restTemplate;
21 |
22 | @Autowired
23 | private HelloService helloService;
24 |
25 | @Autowired
26 | private UserService userService;
27 |
28 |
29 | //测试断路器
30 | @RequestMapping(value = "/ribbon-consumer2", method = RequestMethod.GET)
31 | public String helloConsumer2() {
32 | return helloService.hellService();
33 | }
34 |
35 |
36 | @RequestMapping(value = "/cloud-ribbon-consumer", method = RequestMethod.GET)
37 | public String helloConsumer() {
38 | String string = restTemplate.getForEntity("http://CLOUD-HELLO-PROVIDER/hello", String.class).getBody();
39 | System.out.println("消费者:" + string);
40 | return "消费者 <<<" + string + " >>>";
41 | }
42 |
43 |
44 | @RequestMapping(value = "/user-consumer", method = RequestMethod.GET)
45 | public String userConsumer() {
46 | String user = restTemplate.getForEntity("http://CLOUD-USER-PROVIDER/user", String.class).getBody();
47 | System.out.println("消费者:" + user);
48 |
49 | return "消费者 <<<" + user + " >>>";
50 | }
51 |
52 | @RequestMapping(value = "/user-consumer2", method = RequestMethod.GET)
53 | public String userConsumer2() throws ExecutionException, InterruptedException {
54 | return userService.userService().get();
55 | }
56 | }
57 |
--------------------------------------------------------------------------------
/cloud-ribbon-consumer/src/main/java/com/github/dreamylost/HelloService.java:
--------------------------------------------------------------------------------
1 | package com.github.dreamylost;
2 |
3 | import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
4 | import org.springframework.beans.factory.annotation.Autowired;
5 | import org.springframework.stereotype.Service;
6 | import org.springframework.web.client.RestTemplate;
7 |
8 | /**
9 | * Hystrix断路器
10 | *
11 | * 错误回调处理的请求
12 | *
13 | * @author 梦境迷离
14 | * @title: HelloService
15 | * @description:
16 | * @date 2018-07-29
17 | */
18 | @Service
19 | public class HelloService {
20 |
21 | @Autowired
22 | private RestTemplate restTemplate;
23 |
24 | //同步执行
25 | @HystrixCommand(fallbackMethod = "helloFallback")//使用注解配置服务降级实现方法
26 | public String hellService() {
27 | return restTemplate.getForEntity("http://CLOUD-HELLO-PROVIDER/hello", String.class).getBody();
28 | }
29 |
30 | //错误回调
31 | public String helloFallback() {
32 | return "error";
33 | }
34 | }
35 |
--------------------------------------------------------------------------------
/cloud-ribbon-consumer/src/main/java/com/github/dreamylost/RibbonConsumerApplication.java:
--------------------------------------------------------------------------------
1 | package com.github.dreamylost;
2 |
3 | import org.springframework.boot.SpringApplication;
4 | import org.springframework.boot.autoconfigure.SpringBootApplication;
5 | import org.springframework.cloud.client.circuitbreaker.EnableCircuitBreaker;
6 | import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
7 | import org.springframework.cloud.client.loadbalancer.LoadBalanced;
8 | import org.springframework.context.annotation.Bean;
9 | import org.springframework.web.client.RestTemplate;
10 |
11 | @EnableCircuitBreaker//开启断路器
12 | @EnableDiscoveryClient//服务发现
13 | @SpringBootApplication
14 | public class RibbonConsumerApplication {
15 |
16 | @Bean // 创建RestTemplate实例
17 | @LoadBalanced
18 | // 开启客户端负载均衡
19 | RestTemplate restTemplate() {
20 | return new RestTemplate();
21 | }
22 |
23 | public static void main(String[] args) {
24 | SpringApplication.run(RibbonConsumerApplication.class, args);
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/cloud-ribbon-consumer/src/main/java/com/github/dreamylost/UserService.java:
--------------------------------------------------------------------------------
1 | package com.github.dreamylost;
2 |
3 | import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
4 | import com.netflix.hystrix.contrib.javanica.command.AsyncResult;
5 | import org.springframework.beans.factory.annotation.Autowired;
6 | import org.springframework.stereotype.Service;
7 | import org.springframework.web.client.RestTemplate;
8 |
9 | import java.util.concurrent.Future;
10 |
11 | /**
12 | * Hystrix断路器
13 | *
14 | * 异步方法
15 | *
16 | * @author 梦境迷离
17 | * @title: UserService
18 | * @description:
19 | * @date 2018-07-29
20 | */
21 |
22 | @Service
23 | public class UserService {
24 |
25 | @Autowired
26 | private RestTemplate restTemplate;
27 |
28 | //异步执行
29 | @HystrixCommand
30 | public Future userService() {
31 | return new AsyncResult() {
32 | @Override
33 | public String invoke() {
34 | return restTemplate.getForEntity("http://CLOUD-USER-SERVICE/user", String.class).getBody();
35 | }
36 | };
37 | }
38 |
39 | }
40 |
--------------------------------------------------------------------------------
/cloud-ribbon-consumer/src/main/resources/application.properties:
--------------------------------------------------------------------------------
1 | spring.application.name=cloud-ribbon-consumer
2 | server.port=9000
3 | eureka.client.serviceUrl.defaultZone=http://peer1:1111/eureka/,http://peer2:1112/eureka/
4 |
--------------------------------------------------------------------------------
/cloud-ribbon-consumer/src/test/java/com/github/dreamylost/RibbonConsumerApplicationTests.java:
--------------------------------------------------------------------------------
1 | package com.github.dreamylost;
2 |
3 | import org.junit.Test;
4 | import org.junit.runner.RunWith;
5 | import org.springframework.boot.test.context.SpringBootTest;
6 | import org.springframework.test.context.junit4.SpringRunner;
7 |
8 | @RunWith(SpringRunner.class)
9 | @SpringBootTest
10 | public class RibbonConsumerApplicationTests {
11 |
12 | @Test
13 | public void contextLoads() {
14 | }
15 |
16 | }
17 |
--------------------------------------------------------------------------------
/cloud-user-provider/.gitignore:
--------------------------------------------------------------------------------
1 | /target/
2 | !.mvn/wrapper/maven-wrapper.jar
3 |
4 | ### STS ###
5 | .apt_generated
6 | .classpath
7 | .factorypath
8 | .settings
9 | .springBeans
10 | .sts4-cache
11 |
12 | ### IntelliJ IDEA ###
13 | .idea
14 | *.iws
15 | *.iml
16 | *.ipr
17 |
18 | ### NetBeans ###
19 | /nbproject/private/
20 | /build/
21 | /nbbuild/
22 | /dist/
23 | /nbdist/
24 | /.nb-gradle/
--------------------------------------------------------------------------------
/cloud-user-provider/src/main/java/com/github/dreamylost/User.java:
--------------------------------------------------------------------------------
1 | package com.github.dreamylost;
2 |
3 | /**
4 | * @author 梦境迷离
5 | * @version V1.0
6 | * @time 018年4月18日
7 | */
8 | public class User {
9 |
10 | private Integer id;
11 |
12 | private String name;
13 |
14 | @Override
15 | public String toString() {
16 | return "User [id=" + id + ", name=" + name + "]";
17 | }
18 |
19 | public Integer getId() {
20 | return id;
21 | }
22 |
23 | public void setId(Integer id) {
24 | this.id = id;
25 | }
26 |
27 | public String getName() {
28 | return name;
29 | }
30 |
31 | public void setName(String name) {
32 | this.name = name;
33 | }
34 |
35 | public User(Integer id, String name) {
36 | super();
37 | this.id = id;
38 | this.name = name;
39 | }
40 |
41 | public User() {
42 | super();
43 | }
44 | }
45 |
--------------------------------------------------------------------------------
/cloud-user-provider/src/main/java/com/github/dreamylost/UserApplication.java:
--------------------------------------------------------------------------------
1 | package com.github.dreamylost;
2 |
3 | import org.springframework.beans.factory.annotation.Autowired;
4 | import org.springframework.boot.SpringApplication;
5 | import org.springframework.boot.autoconfigure.SpringBootApplication;
6 | import org.springframework.cloud.client.ServiceInstance;
7 | import org.springframework.cloud.client.discovery.DiscoveryClient;
8 | import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
9 | import org.springframework.web.bind.annotation.RequestMapping;
10 | import org.springframework.web.bind.annotation.RequestMethod;
11 | import org.springframework.web.bind.annotation.RestController;
12 |
13 | @RestController
14 | @EnableDiscoveryClient
15 | @SpringBootApplication
16 | public class UserApplication {
17 |
18 | public static void main(String[] args) {
19 | SpringApplication.run(UserApplication.class, args);
20 | }
21 |
22 | @Autowired
23 | private DiscoveryClient client;
24 |
25 | @SuppressWarnings("deprecation")
26 | @RequestMapping(value = "/user", method = RequestMethod.GET)
27 | public String user() {
28 | ServiceInstance instance = client.getLocalServiceInstance();
29 | System.out.println("生产者:/user,host:" + instance.getHost() + ", service_id:" + instance.getServiceId());
30 | User user = new User(1, "张三");
31 | return "生产者 <<< " + user.toString()+" >>>";
32 | }
33 |
34 | }
35 |
--------------------------------------------------------------------------------
/cloud-user-provider/src/main/resources/application.properties:
--------------------------------------------------------------------------------
1 | #服务命名
2 | #关闭权限,才能访问端点
3 | management.security.enabled=false
4 | #server.port=8080
5 | spring.application.name=cloud-user-provider
6 | #指定服务注册中心的地址
7 | eureka.client.serviceUrl.defaultZone=http://peer1:1111/eureka/,http://peer2:1112/eureka/
8 | #修改端口,模拟启动第二个服务8081
9 | #使用随机造成注册与tomcat端口不同,server.port=${random.int[10000,19999]}但是服务注册端口与tomcat端口不同
10 | server.port=0
11 | #使用随机数,生成随机端口,指定服务的实例名
12 | eureka.instance.instanceId=${spring.application.name}:${random.int[10000,19999]}
13 | #使用actuator代替默认心跳
14 | eureka.client.healthcheck.enabled=true
--------------------------------------------------------------------------------
/cloud-user-provider/src/test/java/com/github/dreamylost/UserApplicationTests.java:
--------------------------------------------------------------------------------
1 | package com.github.dreamylost;
2 |
3 | import org.junit.Test;
4 | import org.junit.runner.RunWith;
5 | import org.springframework.boot.test.context.SpringBootTest;
6 | import org.springframework.test.context.junit4.SpringRunner;
7 |
8 | @RunWith(SpringRunner.class)
9 | @SpringBootTest
10 | public class UserApplicationTests {
11 |
12 | @Test
13 | public void contextLoads() {
14 | }
15 |
16 | }
17 |
--------------------------------------------------------------------------------
/cxf/README.md:
--------------------------------------------------------------------------------
1 | # 整合SpringBoot Mysql Mybatis CXF/JSR-RS
2 |
3 | # 1、mysql中新建demo库运行resources下sql文件
4 | # 2、修改application.properties修改数据源
5 | # 3、启动主类
6 |
--------------------------------------------------------------------------------
/cxf/src/main/java/com/github/dreamylost/Application.java:
--------------------------------------------------------------------------------
1 | package com.github.dreamylost;
2 |
3 | import org.mybatis.spring.annotation.MapperScan;
4 | import org.springframework.boot.SpringApplication;
5 | import org.springframework.boot.autoconfigure.SpringBootApplication;
6 | import org.springframework.context.annotation.ImportResource;
7 | import org.springframework.stereotype.Controller;
8 |
9 | /**
10 | * 启动类
11 | *
12 | * @author: liguobin
13 | * @Description:
14 | * @时间: 2018-3-7 下午3:41:24
15 | * @version: V1.0
16 | */
17 | @Controller
18 | @MapperScan("com.github.dreamylost.dao")
19 | @SpringBootApplication
20 | // / 没有这个rest失效 只存在soap
21 | @ImportResource(locations = {"classpath:cxf-config.xml"})
22 | public class Application {
23 |
24 | public static void main(String[] args) {
25 | SpringApplication.run(Application.class, args);
26 | }
27 | }
28 |
--------------------------------------------------------------------------------
/cxf/src/main/java/com/github/dreamylost/CxfConfig.java:
--------------------------------------------------------------------------------
1 | package com.github.dreamylost;
2 |
3 | import com.fasterxml.jackson.jaxrs.json.JacksonJsonProvider;
4 | import com.github.dreamylost.serviceImpl.StudentServiceImpl;
5 | import org.apache.cxf.Bus;
6 | import org.apache.cxf.bus.spring.SpringBus;
7 | import org.apache.cxf.jaxws.EndpointImpl;
8 | import org.apache.cxf.transport.servlet.CXFServlet;
9 | import org.springframework.beans.factory.annotation.Qualifier;
10 | import org.springframework.boot.web.servlet.ServletRegistrationBean;
11 | import org.springframework.context.annotation.Bean;
12 | import org.springframework.context.annotation.Configuration;
13 |
14 | import javax.xml.ws.Endpoint;
15 |
16 | /**
17 | * @author liguobin
18 | * @version V1.0
19 | * @time 2018-3-7 下午4:11:57
20 | */
21 | @Configuration
22 | public class CxfConfig {
23 |
24 | @Bean
25 | public ServletRegistrationBean newServlet() {
26 | return new ServletRegistrationBean(new CXFServlet(), "/cxf/*");
27 | }
28 |
29 | @Bean(name = Bus.DEFAULT_BUS_ID)
30 | public SpringBus springBus() {
31 | return new SpringBus();
32 | }
33 |
34 | /**
35 | * @return
36 | */
37 | @Bean
38 | @Qualifier("studentServiceImpl") // 注入webService
39 | public Endpoint endpoint(StudentServiceImpl studentServiceImpl) {
40 | EndpointImpl endpoint = new EndpointImpl(springBus(), studentServiceImpl);
41 | endpoint.publish("/webService");// 暴露webService api
42 | return endpoint;
43 | }
44 |
45 | @Bean("jsonProvider") // 构造一个json转化bean,用于将student转化为json
46 | public JacksonJsonProvider getJacksonJsonProvider() {
47 | return new JacksonJsonProvider();
48 |
49 | }
50 | }
--------------------------------------------------------------------------------
/cxf/src/main/java/com/github/dreamylost/SpringController.java:
--------------------------------------------------------------------------------
1 | package com.github.dreamylost;
2 |
3 | import com.alibaba.fastjson.JSONObject;
4 | import com.github.dreamylost.entity.Student;
5 | import com.github.dreamylost.entity.Students;
6 | import com.github.dreamylost.service.StudentService;
7 | import org.springframework.beans.factory.annotation.Autowired;
8 | import org.springframework.stereotype.Controller;
9 | import org.springframework.web.bind.annotation.PathVariable;
10 | import org.springframework.web.bind.annotation.RequestMapping;
11 | import org.springframework.web.bind.annotation.RequestMethod;
12 | import org.springframework.web.bind.annotation.ResponseBody;
13 |
14 | import javax.ws.rs.Consumes;
15 | import javax.ws.rs.Produces;
16 | import javax.ws.rs.core.MediaType;
17 |
18 | /**
19 | * Spring 前端控制
20 | *
21 | * 通过这个返回正确,作对比
22 | *
23 | * @author: liguobin
24 | * @Description:
25 | * @时间: 2018-3-7 下午3:35:17
26 | * @version: V1.0
27 | */
28 | @Controller
29 | public class SpringController {
30 |
31 | @Autowired
32 | private StudentService studentRestfulService;
33 |
34 | @ResponseBody
35 | @Produces({MediaType.APPLICATION_JSON + "charset='utf-8'"})
36 | @RequestMapping(value = "get/{id}", method = RequestMethod.GET)
37 | public String getStudent(@PathVariable("id") Integer id) {
38 | Student student = studentRestfulService.getStudent(id);
39 | Object json = JSONObject.toJSON(student);
40 | return json.toString();
41 | }
42 |
43 | /**
44 | * @param ids
45 | * @return
46 | * @参数:{"ids":{"id":[1,2,3,4]
47 | */
48 | @ResponseBody
49 | @Produces({MediaType.APPLICATION_JSON + "charset='utf-8'"})
50 | @Consumes({MediaType.APPLICATION_JSON})
51 | @RequestMapping(value = "gets/{ids}", method = RequestMethod.GET)
52 | public String getAll(@PathVariable("ids") String ids) {
53 | Students students = studentRestfulService.getAllStudent(ids);
54 | Object json = JSONObject.toJSON(students);
55 | return json.toString();
56 | }
57 | }
58 |
--------------------------------------------------------------------------------
/cxf/src/main/java/com/github/dreamylost/dao/StudentDao.java:
--------------------------------------------------------------------------------
1 | package com.github.dreamylost.dao;
2 |
3 | import com.github.dreamylost.entity.Student;
4 | import org.apache.ibatis.annotations.Param;
5 |
6 | /**
7 | * dao层数据操作接口
8 | *
9 | * @author: liguobin
10 | * @Description:
11 | * @时间: 2018-3-7 下午3:41:43
12 | * @version: V1.0
13 | */
14 | public interface StudentDao {
15 |
16 | Student getStudentById(@Param("id") Integer id);
17 | }
18 |
--------------------------------------------------------------------------------
/cxf/src/main/java/com/github/dreamylost/entity/Student.java:
--------------------------------------------------------------------------------
1 | package com.github.dreamylost.entity;
2 |
3 | import javax.xml.bind.annotation.XmlRootElement;
4 | import java.io.Serializable;
5 |
6 | /**
7 | * 学生实体类
8 | *
9 | * @author: liguobin
10 | * @Description:
11 | * @时间: 2018-3-7 下午3:42:04
12 | * @version: V1.0
13 | */
14 | @XmlRootElement(name = "Student")
15 | public class Student implements Serializable {
16 | private static final long serialVersionUID = 1L;
17 | private Integer id;
18 | private String name;
19 | private char sex;
20 | private String address;
21 | private Integer age;
22 |
23 | public Student() {
24 | super();
25 | }
26 |
27 | public Student(Integer id, String name, char sex, String address,
28 | Integer age) {
29 | super();
30 | this.id = id;
31 | this.name = name;
32 | this.sex = sex;
33 | this.address = address;
34 | this.age = age;
35 | }
36 |
37 | public Integer getId() {
38 | return id;
39 | }
40 |
41 | public void setId(Integer id) {
42 | this.id = id;
43 | }
44 |
45 | public String getName() {
46 | return name;
47 | }
48 |
49 | public void setName(String name) {
50 | this.name = name;
51 | }
52 |
53 | public char getSex() {
54 | return sex;
55 | }
56 |
57 | public void setSex(char sex) {
58 | this.sex = sex;
59 | }
60 |
61 | public String getAddress() {
62 | return address;
63 | }
64 |
65 | public void setAddress(String address) {
66 | this.address = address;
67 | }
68 |
69 | public Integer getAge() {
70 | return age;
71 | }
72 |
73 | public void setAge(Integer age) {
74 | this.age = age;
75 | }
76 |
77 | @Override
78 | public String toString() {
79 | return "Student [id=" + id + ", name=" + name + ", sex=" + sex
80 | + ", address=" + address + ", age=" + age + "]";
81 | }
82 |
83 | }
84 |
--------------------------------------------------------------------------------
/cxf/src/main/java/com/github/dreamylost/entity/Students.java:
--------------------------------------------------------------------------------
1 | package com.github.dreamylost.entity;
2 |
3 | import javax.xml.bind.annotation.XmlElement;
4 | import javax.xml.bind.annotation.XmlRootElement;
5 | import java.util.List;
6 |
7 | /**
8 | * 封装多个学生实体类
9 | *
10 | * @author: liguobin
11 | * @Description:
12 | * @时间: 2018-3-7 下午3:42:14
13 | * @version: V1.0
14 | */
15 | @XmlRootElement(name = "Students")
16 | public class Students {
17 |
18 | private List students;
19 |
20 | public Students(List students) {
21 | super();
22 | this.students = students;
23 | }
24 |
25 | @XmlElement(name = "Student")
26 | public List getStudents() {
27 | return students;
28 | }
29 |
30 | public Students() {
31 | super();
32 | }
33 |
34 | public void setStudents(List students) {
35 | this.students = students;
36 | }
37 |
38 | }
39 |
--------------------------------------------------------------------------------
/cxf/src/main/java/com/github/dreamylost/resource/StudentInterface.java:
--------------------------------------------------------------------------------
1 | package com.github.dreamylost.resource;
2 |
3 | import com.github.dreamylost.entity.Student;
4 | import com.github.dreamylost.entity.Students;
5 |
6 | import javax.ws.rs.*;
7 | import javax.ws.rs.core.MediaType;
8 |
9 | /**
10 | * @author: liguobin
11 | * @Description:
12 | * @时间: 2018-3-7 下午3:59:15
13 | * @version: V1.0
14 | */
15 | @Consumes({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})
16 | public interface StudentInterface {
17 |
18 | /**
19 | * @param id
20 | * @return
21 | */
22 | @GET
23 | @Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})
24 | @Path("/getone/{id:[0-9]{0,10}}") // 限制id只能是0~9的数组 不超过10位
25 | public Student getStudent(@PathParam("id") Integer id);
26 |
27 | /**
28 | * 查找多个学生
29 | *
30 | * @param ids
31 | * @return
32 | */
33 |
34 | @GET
35 | @Produces({MediaType.APPLICATION_JSON})
36 | @Path("/getmany/{ids}")
37 | public Students getAllStudent(@PathParam("ids") String ids);
38 | }
39 |
--------------------------------------------------------------------------------
/cxf/src/main/java/com/github/dreamylost/resource/StudentInterfaceImpl.java:
--------------------------------------------------------------------------------
1 | package com.github.dreamylost.resource;
2 |
3 | import com.alibaba.fastjson.JSONArray;
4 | import com.alibaba.fastjson.JSONObject;
5 | import com.github.dreamylost.entity.Student;
6 | import com.github.dreamylost.entity.Students;
7 | import com.github.dreamylost.service.StudentService;
8 | import org.springframework.beans.factory.annotation.Autowired;
9 |
10 | import javax.ws.rs.GET;
11 | import javax.ws.rs.Path;
12 | import javax.ws.rs.PathParam;
13 | import javax.ws.rs.Produces;
14 | import javax.ws.rs.core.MediaType;
15 | import java.util.ArrayList;
16 |
17 | @Path("/")
18 | public class StudentInterfaceImpl implements StudentInterface {
19 |
20 | @Autowired
21 | private StudentService studentService;
22 |
23 | // 获取json
24 | @Override
25 | @GET
26 | @Path("/getjson/{id:[0-9]{0,10}}")
27 | @Produces({MediaType.APPLICATION_JSON})
28 | public Student getStudent(@PathParam("id") Integer id) {
29 | return studentService.getStudent(id);
30 | }
31 |
32 | // 获取xml
33 | @GET
34 | @Path("/getxml/{id}")
35 | @Produces({MediaType.APPLICATION_XML})
36 | public Student getStudent2(@PathParam("id") Integer id) {
37 | return studentService.getStudent(id);
38 | }
39 |
40 | /**
41 | * 返回students集合,此方法没有测试,参数是一个json对象,该对象包含一个name为id的数组
42 | */
43 | @Override
44 | @GET
45 | @Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})
46 | @Path("/getmany/{ids}")
47 | public Students getAllStudent(@PathParam("ids") String ids) {
48 | Students students = new Students(new ArrayList());
49 | // 得到json对象
50 | JSONObject json = JSONObject.parseObject(ids);
51 | // 获取对象的id列表
52 | JSONArray sid = json.getJSONArray("id");
53 |
54 | for (int i = 0; i < sid.size(); i++) {
55 | Integer s = sid.getInteger(0);
56 | if (s != null) {
57 | students.getStudents().add(studentService.getStudent(s));
58 | } else {
59 | continue;
60 | }
61 | }
62 | return students;
63 |
64 | }
65 |
66 | }
67 |
--------------------------------------------------------------------------------
/cxf/src/main/java/com/github/dreamylost/service/StudentService.java:
--------------------------------------------------------------------------------
1 | package com.github.dreamylost.service;
2 |
3 | import com.github.dreamylost.entity.Student;
4 | import com.github.dreamylost.entity.Students;
5 |
6 | import javax.jws.WebMethod;
7 | import javax.jws.WebParam;
8 | import javax.jws.WebService;
9 | import javax.ws.rs.Consumes;
10 | import javax.ws.rs.Produces;
11 | import javax.ws.rs.core.MediaType;
12 |
13 | /**
14 | * @author liguobin
15 | * @description WebService接口定义 soap
16 | */
17 | @Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML}) // 返回类型
18 | @Consumes({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML}) // 请求类型
19 | @WebService
20 | public interface StudentService {
21 |
22 | /**
23 | * 查找一个学生
24 | *
25 | * @param id
26 | * @return
27 | */
28 | @WebMethod
29 | public Student getStudent(@WebParam(name = "id") Integer id);
30 |
31 | /**
32 | * 查找多个学生
33 | *
34 | * @param ids
35 | * @return
36 | */
37 | @WebMethod
38 | public Students getAllStudent(@WebParam(name = "ids") String ids);
39 |
40 | }
41 |
--------------------------------------------------------------------------------
/cxf/src/main/java/com/github/dreamylost/serviceImpl/StudentServiceImpl.java:
--------------------------------------------------------------------------------
1 | package com.github.dreamylost.serviceImpl;
2 |
3 | import com.alibaba.fastjson.JSONArray;
4 | import com.alibaba.fastjson.JSONObject;
5 | import com.github.dreamylost.dao.StudentDao;
6 | import com.github.dreamylost.entity.Student;
7 | import com.github.dreamylost.entity.Students;
8 | import com.github.dreamylost.service.StudentService;
9 | import org.springframework.beans.factory.annotation.Autowired;
10 | import org.springframework.stereotype.Component;
11 |
12 | import javax.jws.WebService;
13 | import java.util.ArrayList;
14 |
15 | /**
16 | * 实现webservice接口,对外暴露 soap
17 | *
18 | * @author: liguobin
19 | * @Description:
20 | * @时间: 2018-3-7 下午3:43:06
21 | * @version: V1.0
22 | */
23 | @Component//由Spring管理
24 | @WebService(endpointInterface = "com.github.dreamylost.service.StudentService") // webservice接口的全类名
25 | public class StudentServiceImpl implements StudentService {
26 |
27 | /**
28 | * 注入spring bean
29 | */
30 | @Autowired
31 | private StudentDao studentDao;
32 |
33 | @Override
34 | public Student getStudent(Integer id) {
35 | return studentDao.getStudentById(id);
36 | }
37 |
38 | /**
39 | * 没有测试正确性,不是本文重点
40 | */
41 | @Override
42 | public Students getAllStudent(String ids) {
43 | Students students = new Students(new ArrayList());
44 | // 得到json对象
45 | JSONObject json = JSONObject.parseObject(ids);
46 | // 获取对象的id列表
47 | JSONArray sid = json.getJSONArray("id");
48 |
49 | for (int i = 0; i < sid.size(); i++) {
50 | Integer s = sid.getInteger(0);
51 | if (s != null) {
52 | students.getStudents().add(studentDao.getStudentById(s));
53 | } else {
54 | continue;
55 | }
56 | }
57 | return students;
58 |
59 | }
60 |
61 | }
62 |
--------------------------------------------------------------------------------
/cxf/src/main/resources/application.properties:
--------------------------------------------------------------------------------
1 | #server port set
2 | server.port:8082
3 | #mysql datasource set
4 | spring.datasource.
5 | spring.datasource.url=jdbc:mysql://localhost:3306/demo?useUnicode=true&characterEncoding=utf8
6 | spring.datasource.username=root
7 | spring.datasource.password=root
8 | spring.datasource.driver-class-name=com.mysql.jdbc.Driver
9 | mybatis.typeAliasesPackage=com.github.dreamylost.entity
10 | mybatis.mapperLocations=classpath\:mapper/*.xml
11 | mybatis.config-location=classpath\:mybatis-config.xml
12 | spring.jackson.serialization.indent_output=true
13 | logging.level.org.springframework.web=WARN
14 | #logging.file = C\:\\web\\temp\\log\\log.log
15 | logging.level.org.springframework=WARN
16 | logging.level.cn.edu.jxnu.dao=INFO
17 | logging.level.cn.edu.jxnu.resource=WARN
18 |
--------------------------------------------------------------------------------
/cxf/src/main/resources/cxf-config.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
--------------------------------------------------------------------------------
/cxf/src/main/resources/demo.sql:
--------------------------------------------------------------------------------
1 | /*
2 | Navicat MySQL Data Transfer
3 |
4 | Source Server : root
5 | Source Server Version : 50540
6 | Source Host : localhost:3306
7 | Source Database : demo
8 |
9 | Target Server Type : MYSQL
10 | Target Server Version : 50540
11 | File Encoding : 65001
12 |
13 | Date: 2018-03-23 16:21:20
14 | */
15 |
16 | SET FOREIGN_KEY_CHECKS=0;
17 | -- ----------------------------
18 | -- Table structure for `student`
19 | -- ----------------------------
20 | DROP TABLE IF EXISTS `student`;
21 | CREATE TABLE `student` (
22 | `id` int(10) NOT NULL,
23 | `name` varchar(100) DEFAULT NULL,
24 | `sex` char(6) DEFAULT NULL,
25 | `address` varchar(255) DEFAULT NULL,
26 | `age` int(10) DEFAULT NULL,
27 | PRIMARY KEY (`id`)
28 | ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
29 |
30 | -- ----------------------------
31 | -- Records of student
32 | -- ----------------------------
33 | INSERT INTO `student` VALUES ('1', '李斯', '男', '江西南昌', '22');
34 |
--------------------------------------------------------------------------------
/cxf/src/main/resources/mapper/StudentMapper.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 | id,name,sex,address,age
16 |
17 |
23 |
24 |
25 |
--------------------------------------------------------------------------------
/cxf/src/main/resources/mybatis-config.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
--------------------------------------------------------------------------------
/cxf/src/test/java/com/github/dreamylost/CxfSpec.java:
--------------------------------------------------------------------------------
1 | package com.github.dreamylost;
2 |
3 | import com.github.dreamylost.entity.Student;
4 | import com.github.dreamylost.service.StudentService;
5 | import junit.framework.TestCase;
6 | import org.junit.Test;
7 | import org.junit.runner.RunWith;
8 | import org.springframework.beans.factory.annotation.Autowired;
9 | import org.springframework.boot.test.context.SpringBootTest;
10 | import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
11 | import org.springframework.test.context.web.WebAppConfiguration;
12 |
13 | /**
14 | * 单元测试 测试整合
15 | */
16 | @RunWith(SpringJUnit4ClassRunner.class)
17 | @SpringBootTest(classes = Application.class)
18 | @WebAppConfiguration
19 | public class CxfSpec extends TestCase {
20 | @Autowired
21 | private StudentService studentRestfulService;
22 |
23 | /**
24 | * 测试service与dao层
25 | */
26 | @Test
27 | public void Test() {
28 | Student s = studentRestfulService.getStudent(1);
29 | System.out.println(s.toString());
30 | }
31 |
32 | }
33 |
--------------------------------------------------------------------------------
/dubbo-api/pom.xml:
--------------------------------------------------------------------------------
1 |
3 | 4.0.0
4 |
5 | com.github.dreamylost
6 | springboot-examples
7 | 1.0-SNAPSHOT
8 |
9 | dubbo-api
10 |
--------------------------------------------------------------------------------
/dubbo-api/src/main/java/com/github/dreamylost/City.java:
--------------------------------------------------------------------------------
1 | package com.github.dreamylost;
2 |
3 | import java.io.Serializable;
4 |
5 | /**
6 | * @author 梦境迷离
7 | * @title: City
8 | * @description: 城市实体类
9 | * @date 2018-07-08
10 | */
11 | public class City implements Serializable {
12 |
13 | private static final long serialVersionUID = -1L;
14 |
15 | /**
16 | * 城市编号
17 | */
18 | private Long id;
19 |
20 | /**
21 | * 省份编号
22 | */
23 | private Long provinceId;
24 |
25 | /**
26 | * 城市名称
27 | */
28 | private String cityName;
29 |
30 | /**
31 | * 描述
32 | */
33 | private String description;
34 |
35 | public Long getId() {
36 |
37 | return id;
38 | }
39 |
40 | public void setId(Long id) {
41 |
42 | this.id = id;
43 | }
44 |
45 | public Long getProvinceId() {
46 |
47 | return provinceId;
48 | }
49 |
50 | public void setProvinceId(Long provinceId) {
51 |
52 | this.provinceId = provinceId;
53 | }
54 |
55 | public String getCityName() {
56 |
57 | return cityName;
58 | }
59 |
60 |
61 | public void setCityName(String cityName) {
62 |
63 | this.cityName = cityName;
64 |
65 | }
66 |
67 | public String getDescription() {
68 |
69 | return description;
70 | }
71 |
72 | public void setDescription(String description) {
73 |
74 | this.description = description;
75 | }
76 |
77 | public City(Long id, Long provinceId, String cityName, String description) {
78 | this.id = id;
79 | this.provinceId = provinceId;
80 | this.cityName = cityName;
81 | this.description = description;
82 | }
83 |
84 | @Override
85 | public String toString() {
86 | return "City{" +
87 | "id=" + id +
88 | ", provinceId=" + provinceId +
89 | ", cityName='" + cityName + '\'' +
90 | ", description='" + description + '\'' +
91 | '}';
92 | }
93 | }
--------------------------------------------------------------------------------
/dubbo-api/src/main/java/com/github/dreamylost/CityDubboService.java:
--------------------------------------------------------------------------------
1 | package com.github.dreamylost;
2 |
3 | /**
4 | * @author 梦境迷离
5 | * @title: CityDubboService
6 | * @description: 城市接口
7 | * @date 2018-07-08
8 | */
9 | public interface CityDubboService {
10 |
11 | /**
12 | * 根据城市名称,查询城市信息
13 | *
14 | * @param cityName
15 | */
16 | City findCityByName(String cityName);
17 | }
18 |
--------------------------------------------------------------------------------
/dubbo-api/src/main/java/com/github/dreamylost/IHelloService.java:
--------------------------------------------------------------------------------
1 | package com.github.dreamylost;
2 |
3 | public interface IHelloService {
4 |
5 | String sayHello(String name);
6 |
7 | }
8 |
--------------------------------------------------------------------------------
/dubbo-consumer/pom.xml:
--------------------------------------------------------------------------------
1 |
3 | 4.0.0
4 |
5 | com.github.dreamylost
6 | springboot-examples
7 | 1.0-SNAPSHOT
8 |
9 | dubbo-consumer
10 |
11 |
12 |
13 | org.springframework.boot
14 | spring-boot-starter-web
15 |
16 |
17 |
18 | com.alibaba.spring.boot
19 | dubbo-spring-boot-starter
20 |
21 |
22 |
23 | org.apache.zookeeper
24 | zookeeper
25 |
26 |
27 |
28 | org.apache.curator
29 | curator-framework
30 |
31 |
32 | com.github.dreamylost
33 | dubbo-api
34 | 1.0-SNAPSHOT
35 | compile
36 |
37 |
38 |
39 |
40 |
--------------------------------------------------------------------------------
/dubbo-consumer/src/main/java/com/github/dreamylost/CityConsumer.java:
--------------------------------------------------------------------------------
1 | package com.github.dreamylost;
2 |
3 | import com.alibaba.dubbo.config.annotation.Reference;
4 | import org.springframework.web.bind.annotation.RequestMapping;
5 | import org.springframework.web.bind.annotation.RestController;
6 |
7 | /**
8 | * @author 梦境迷离
9 | * @title: CityConsumer
10 | * @description: 消费者-得到对象
11 | * @date 2018-07-08
12 | */
13 | @RestController
14 | public class CityConsumer {
15 |
16 | @Reference
17 | private CityDubboService cityDubboService;
18 |
19 | @RequestMapping("/getCity")
20 | public City TestCity() {
21 |
22 | System.out.println(cityDubboService);
23 | City city = cityDubboService.findCityByName("南昌");
24 | System.out.println(city);
25 | return city;
26 |
27 | }
28 | }
29 |
--------------------------------------------------------------------------------
/dubbo-consumer/src/main/java/com/github/dreamylost/ConsumerApplication.java:
--------------------------------------------------------------------------------
1 | package com.github.dreamylost;
2 |
3 | import com.alibaba.dubbo.spring.boot.annotation.EnableDubboConfiguration;
4 | import org.springframework.boot.SpringApplication;
5 | import org.springframework.boot.autoconfigure.SpringBootApplication;
6 |
7 | /**
8 | * @author 梦境迷离
9 | * @title: DubboConsumerLauncher
10 | * @description: 消费者
11 | * @date 2018-07-08
12 | */
13 | @SpringBootApplication
14 | @EnableDubboConfiguration
15 | public class ConsumerApplication {
16 |
17 | public static void main(String[] args) throws Exception {
18 | SpringApplication.run(ConsumerApplication.class, args);
19 | }
20 |
21 | }
22 |
--------------------------------------------------------------------------------
/dubbo-consumer/src/main/java/com/github/dreamylost/HelloConsumer.java:
--------------------------------------------------------------------------------
1 | package com.github.dreamylost;
2 |
3 | import com.alibaba.dubbo.config.annotation.Reference;
4 | import org.springframework.web.bind.annotation.GetMapping;
5 | import org.springframework.web.bind.annotation.PathVariable;
6 | import org.springframework.web.bind.annotation.RestController;
7 |
8 | /**
9 | * @author 梦境迷离
10 | * @title: HelloConsumer
11 | * @description: 消费者-得到字符串
12 | * @date 2018-07-08
13 | */
14 | @RestController
15 | public class HelloConsumer {
16 |
17 | @Reference
18 | private IHelloService helloService;
19 |
20 | @GetMapping("sayHello/{name}")
21 | public String sayHello(@PathVariable("name") String name) {
22 | return helloService.sayHello(name);
23 | }
24 | }
25 |
--------------------------------------------------------------------------------
/dubbo-consumer/src/main/resources/application.properties:
--------------------------------------------------------------------------------
1 | server.port=8082
2 | spring.application.name=dubbo-consumer-test
3 | spring.dubbo.registry=zookeeper://127.0.0.1:2181?client=curator
4 | spring.dubbo.protocol=dubbo
--------------------------------------------------------------------------------
/dubbo-provider/pom.xml:
--------------------------------------------------------------------------------
1 |
3 | 4.0.0
4 |
5 | com.github.dreamylost
6 | springboot-examples
7 | 1.0-SNAPSHOT
8 |
9 | dubbo-provider
10 |
11 |
12 |
13 | org.springframework.boot
14 | spring-boot-starter-web
15 |
16 |
17 |
18 | com.alibaba.spring.boot
19 | dubbo-spring-boot-starter
20 |
21 |
22 |
23 | org.apache.zookeeper
24 | zookeeper
25 |
26 |
27 |
28 | org.apache.curator
29 | curator-framework
30 |
31 |
32 | com.github.dreamylost
33 | dubbo-api
34 | 1.0-SNAPSHOT
35 | compile
36 |
37 |
38 |
39 |
40 |
--------------------------------------------------------------------------------
/dubbo-provider/src/main/java/com/github/dreamylost/CityDubboServiceImpl.java:
--------------------------------------------------------------------------------
1 | package com.github.dreamylost;
2 |
3 | import com.alibaba.dubbo.config.annotation.Service;
4 | import org.springframework.stereotype.Component;
5 |
6 | /**
7 | * @author 梦境迷离
8 | * @title: CityDubboServiceImpl
9 | * @description: 提供者-City具体实现
10 | * @date 2018-07-08
11 | */
12 | @Service
13 | @Component// 注册为 Dubbo 服务
14 | public class CityDubboServiceImpl implements CityDubboService {
15 |
16 | @Override
17 | public City findCityByName(String cityName) {
18 |
19 | return new City(1L, 2L, "南昌", "是我的故乡");
20 | }
21 | }
--------------------------------------------------------------------------------
/dubbo-provider/src/main/java/com/github/dreamylost/HelloServiceImpl.java:
--------------------------------------------------------------------------------
1 | package com.github.dreamylost;
2 |
3 | import com.alibaba.dubbo.config.annotation.Service;
4 | import org.springframework.stereotype.Component;
5 |
6 | /**
7 | * @author 梦境迷离
8 | * @title: HelloServiceImpl
9 | * @description: 提供者-Hello具体实现
10 | * @date 2018-07-08
11 | */
12 | @Service
13 | @Component
14 | public class HelloServiceImpl implements IHelloService {
15 |
16 | @Override
17 | public String sayHello(String name) {
18 | return "Hello " + name + " !";
19 | }
20 |
21 | }
22 |
--------------------------------------------------------------------------------
/dubbo-provider/src/main/java/com/github/dreamylost/ProviderApplication.java:
--------------------------------------------------------------------------------
1 | package com.github.dreamylost;
2 |
3 | import com.alibaba.dubbo.spring.boot.annotation.EnableDubboConfiguration;
4 | import org.springframework.boot.SpringApplication;
5 | import org.springframework.boot.autoconfigure.SpringBootApplication;
6 |
7 | /**
8 | * @author 梦境迷离
9 | * @title: DubboProviderLauncher
10 | * @description: 提供者(生产者)
11 | * @date 2018-07-08
12 | */
13 | @SpringBootApplication
14 | @EnableDubboConfiguration
15 | public class ProviderApplication {
16 |
17 | public static void main(String[] args) throws Exception {
18 | SpringApplication.run(ProviderApplication.class, args);
19 | }
20 |
21 | }
22 |
--------------------------------------------------------------------------------
/dubbo-provider/src/main/resources/application.properties:
--------------------------------------------------------------------------------
1 | server.port=8081
2 | spring.application.name=dubbo-provider-test
3 | spring.dubbo.registry=zookeeper://127.0.0.1:2181?client=curator
4 | spring.dubbo.protocol=dubbo
--------------------------------------------------------------------------------
/graphql-complete/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 | 4.0.0
7 | com.github.dreamylost
8 | graphql-complete
9 | 0.0.1-SNAPSHOT
10 |
11 |
12 |
13 | org.apache.maven.plugins
14 | maven-compiler-plugin
15 |
16 | 8
17 | 8
18 |
19 |
20 |
21 |
22 | jar
23 |
24 |
25 | org.springframework.boot
26 | spring-boot-starter-parent
27 | 1.5.10.RELEASE
28 |
29 |
30 |
31 |
32 | UTF-8
33 | UTF-8
34 |
35 |
36 |
37 |
38 | org.springframework.boot
39 | spring-boot-starter-web
40 |
41 |
42 | com.graphql-java
43 | graphql-java
44 | 10.0
45 |
46 |
47 | com.google.guava
48 | guava
49 | 29.0-jre
50 |
51 |
52 |
53 |
--------------------------------------------------------------------------------
/graphql-complete/src/main/java/com/github/dreamylost/GraphQLController.java:
--------------------------------------------------------------------------------
1 | package com.github.dreamylost;
2 |
3 | import com.fasterxml.jackson.core.type.TypeReference;
4 | import com.fasterxml.jackson.databind.ObjectMapper;
5 | import org.springframework.beans.factory.annotation.Autowired;
6 | import org.springframework.http.MediaType;
7 | import org.springframework.web.bind.annotation.*;
8 |
9 | import javax.servlet.http.HttpServletRequest;
10 | import javax.servlet.http.HttpServletResponse;
11 | import java.io.IOException;
12 | import java.util.LinkedHashMap;
13 | import java.util.Map;
14 |
15 | /**
16 | * 处理/graphql请求
17 | *
18 | * @author 梦境迷离
19 | * @time 2020年03月24日17:57:08
20 | */
21 | @RestController
22 | public class GraphQLController {
23 |
24 | @Autowired
25 | private ObjectMapper objectMapper;
26 |
27 | @Autowired
28 | private GraphQLProvider graphQLProvider;
29 |
30 | //前端js中写死该URI
31 | @RequestMapping(value = "/graphql", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
32 | @CrossOrigin
33 | public void graphqlGET(@RequestParam("query") String query,
34 | @RequestParam(value = "operationName", required = false) String operationName,
35 | @RequestParam("variables") String variablesJson,
36 | HttpServletResponse httpServletResponse) throws IOException {
37 | if (query == null) {
38 | query = "";
39 | }
40 | Map variables = new LinkedHashMap<>();
41 | ;
42 | if (variablesJson != null) {
43 | variables = objectMapper.readValue(variablesJson, new TypeReference