-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcontent.json
1 lines (1 loc) · 18.1 KB
/
content.json
1
{"meta":{"title":"seepine's blog","subtitle":"","description":"blog,java,vue,qt,docker","author":"seepine","url":"https://seepine.github.io","root":"/"},"pages":[{"title":"404 Not Found","date":"2020-05-15T06:50:31.387Z","updated":"2020-01-06T07:59:24.000Z","comments":true,"path":"404.html","permalink":"https://seepine.github.io/404","excerpt":"","text":"404 Not Found **很抱歉,您访问的页面不存在** 可能是输入地址有误或该地址已被删除"},{"title":"关于","date":"2020-05-15T06:50:31.387Z","updated":"2020-03-22T08:25:32.927Z","comments":true,"path":"about/index.html","permalink":"https://seepine.github.io/about/","excerpt":"","text":" 全\"占\"工程师,主要技术栈包含Java、Vue、Qt、Python、Docker、DockerSwarm、微信小程序 关于主题本站主题是:Material X One More Thing懒加载占位图如果喜欢请拿去:图片链接 欢迎灌水"},{"title":"","date":"2020-05-15T06:50:31.389Z","updated":"2020-01-09T01:06:20.000Z","comments":true,"path":"projects/index.html","permalink":"https://seepine.github.io/projects/","excerpt":"","text":""},{"title":"我的朋友们","date":"2020-05-15T06:50:31.388Z","updated":"2020-03-22T08:52:27.516Z","comments":true,"path":"friends/index.html","permalink":"https://seepine.github.io/friends/","excerpt":"","text":"各位大佬想交换友链的话可以在下方留言,必须要有名称、头像链接、和至少一个标签哦~ 名称: seepine头像: https://www.superbed.cn/item/5e7720705c56091129adb39d.jpg网址: https://seepine.com标签: Java 分组和标签不合适的话可以留言或者发邮件私聊我进行更改。头像尺寸是64px,3倍精细度就足够了,也就是192px,如果文件体积太大可以压缩一下。"},{"title":"","date":"2020-05-15T06:50:31.388Z","updated":"2020-01-06T07:58:49.000Z","comments":true,"path":"mylist/index.html","permalink":"https://seepine.github.io/mylist/","excerpt":"","text":""},{"title":"","date":"2020-05-15T06:50:31.387Z","updated":"2020-01-06T08:01:33.000Z","comments":true,"path":"blog/archives/index.html","permalink":"https://seepine.github.io/blog/archives/","excerpt":"","text":""},{"title":"所有分类","date":"2020-05-15T06:50:31.388Z","updated":"2020-01-06T07:58:15.000Z","comments":true,"path":"blog/categories/index.html","permalink":"https://seepine.github.io/blog/categories/","excerpt":"","text":""},{"title":"所有标签","date":"2020-05-15T06:50:31.388Z","updated":"2020-01-06T07:58:25.000Z","comments":true,"path":"blog/tags/index.html","permalink":"https://seepine.github.io/blog/tags/","excerpt":"","text":""}],"posts":[{"title":"spring-cloud-demo-03-nacos","slug":"spring-cloud-demo-03-nacos","date":"2020-03-22T07:38:40.000Z","updated":"2020-03-22T07:41:46.005Z","comments":true,"path":"2020/03/22/spring-cloud-demo-03-nacos/","link":"","permalink":"https://seepine.github.io/2020/03/22/spring-cloud-demo-03-nacos/","excerpt":"","text":"本Demo演示了Nacos服务端的搭建,以及如何使用其服务发现和配置中心的功能。源码:https://github.com/seepine/spring-cloud-demo 模块介绍spring-cloud-demo-03-nacos模块分为两个子模块,分别为Provider(供应者)和Consumer(消费者)。 一、搭建Nacos服务端本教程是用Docker搭建Nacos,也可到官网使用任意方法搭建。 1.安装Docker点此下载对应系统的docker-ce 2.运行Nacos服务端1docker run --name nacos -e MODE=standalone -p 8848:8848 -d nacos/nacos-server:latest 3.验证输入http://127.0.0.1:8848/nacos/即可看到Nacos控制台 二.创建供应者1.添加依赖1234567891011121314<dependencies> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency> <dependency> <groupId>com.alibaba.cloud</groupId> <artifactId>spring-cloud-starter-alibaba-nacos-config</artifactId> </dependency> <dependency> <groupId>com.alibaba.cloud</groupId> <artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId> </dependency></dependencies> 2.添加配置文件123456789101112spring: application: name: nacos-provider cloud: nacos: discovery: server-addr: 127.0.0.1:8848 config: server-addr: ${spring.cloud.nacos.discovery.server-addr} file-extension: ymlserver: port: 12000 3.在Nacos中创建对应配置文件其中[Data ID]需要与spring.application.name对应 4.创建获取配置文件的实体类1234567@Data@Component@ConfigurationProperties(prefix = \"user\")public class UserConfig { private String username; private String password;} 5.编写测试接口12345678910@RestController@AllArgsConstructorpublic class ApiController { private UserConfig userConfig; @GetMapping(\"/user/config\") public Object getUserConfig() { return userConfig; }} 6.测试服务发现与获取配置文件功能 7.测试配置文件动态刷新使用@RefreshScope或@ConfigurationProperties即可使用动态刷新功能 7.1 进入Nacos修改配置文件参数7.2 此时再次刷新接口 三、创建消费者1.添加依赖123456789101112131415161718<dependencies> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency> <dependency> <groupId>com.alibaba.cloud</groupId> <artifactId>spring-cloud-starter-alibaba-nacos-config</artifactId> </dependency> <dependency> <groupId>com.alibaba.cloud</groupId> <artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId> </dependency> <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter-openfeign</artifactId> </dependency></dependencies> 2.添加配置文件123456789101112spring: application: name: nacos-consumer cloud: nacos: discovery: server-addr: 127.0.0.1:8848 config: server-addr: ${spring.cloud.nacos.discovery.server-addr} file-extension: ymlserver: port: 13000 3.添加Feign1234567@EnableFeignClients@SpringBootApplicationpublic class SpringCloudDemo03NacosConsumerApplication { public static void main(String[] args) { SpringApplication.run(SpringCloudDemo03NacosConsumerApplication.class, args); }} 12345@FeignClient(\"nacos-provider\")public interface RemoteApiService { @GetMapping(\"/user/config\") Object userConfig();} 4.添加消费者接口123456789@RestController@AllArgsConstructorpublic class ApiController { RemoteApiService remoteApiService; @GetMapping(\"/get\") public Object get() { return remoteApiService.userConfig(); }} 5.测试服务发现功能及通过feign获取供应者的配置文件内容","categories":[{"name":"spring cloud","slug":"spring-cloud","permalink":"https://seepine.github.io/categories/spring-cloud/"}],"tags":[{"name":"nacos","slug":"nacos","permalink":"https://seepine.github.io/tags/nacos/"}]},{"title":"spring-cloud-demo-02-config","slug":"spring-cloud-demo-02-config","date":"2020-03-22T07:38:26.000Z","updated":"2020-03-22T07:41:45.996Z","comments":true,"path":"2020/03/22/spring-cloud-demo-02-config/","link":"","permalink":"https://seepine.github.io/2020/03/22/spring-cloud-demo-02-config/","excerpt":"","text":"本Demo演示了Config服务端的搭建,以及客户端如何通过Config服务端获取配置文件。源码:https://github.com/seepine/spring-cloud-demo 模块介绍spring-cloud-demo-02-config模块分为两个子模块,分别为Config-Server(Config服务端)和Config-Client(Config客户端)。 一、搭建Config服务端1.Config-Server1.1 添加依赖 1234<dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-config-server</artifactId></dependency> 1.2 在启动类上添加注解@EnableConfigServer 123456789@EnableConfigServer@SpringBootApplicationpublic class SpringCloudDemo02ConfigServerApplication { public static void main(String[] args) { SpringApplication.run(SpringCloudDemo02ConfigServerApplication.class, args); }} 1.3 添加配置文件 12345678910spring: application: name: config-server cloud: config: server: git: uri: https://github.com/seepine/spring-cloud-demo-configserver: port: 10000 1.4 创建git配置文件仓库(可参考https://github.com/seepine/spring-cloud-demo-config) 创建文件名为config-client-dev.yml 123user: username: seepine password: 123456 1.5 启动ConfigServer并验证 输入地址及文件名:http://127.0.0.1:10000/config-client-dev.yml 2.Config-Client2.1 添加依赖 1234<dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter-config</artifactId></dependency> 2.2 添加配置文件 12345678910spring: application: name: config-client cloud: config: uri: http://localhost:10000 profiles: active: devserver: port: 11000 2.3 创建两个获取配置文件值的实体类 12345678@Data@Componentpublic class User { @Value(\"${user.username}\") private String username; @Value(\"${user.password}\") private String password;} 1234567@Data@Component@ConfigurationProperties(prefix = \"user\")public class UserConfig { private String username; private String password;} 2.4 编写测试接口 123456789101112131415@RestController@AllArgsConstructorpublic class ApiController { private User user; private UserConfig userConfig; @GetMapping(\"/user\") public Object getUser() { return user; } @GetMapping(\"/user/config\") public Object getUserConfig() { return userConfig; }} 2.5 分别测试两个接口 3.整合Eureka3.1 Config-Server与Config-Client添加依赖 1234<dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter-netflix-eureka-client</artifactId></dependency> 3.2 Config-Server与Config-Client添加配置 123456eureka: instance: hostname: localhost #eureka服务端的实例名称 client: service-url: defaultZone: http://seepine:123456@${eureka.instance.hostname}:8761/eureka/ # 与注册中心交互的url 3.3 Config-Server配置文件修改 1234# uri: http://localhost:10000 discovery: enabled: true #默认false,设为true表示使用注册中心中的configserver配置,而不是配置的uri service-id: CONFIG-SERVER #指定config server在服务发现中的serviceId,默认为:configserver 3.4 重启客户端分别测试两个接口","categories":[{"name":"spring cloud","slug":"spring-cloud","permalink":"https://seepine.github.io/categories/spring-cloud/"}],"tags":[{"name":"spring config","slug":"spring-config","permalink":"https://seepine.github.io/tags/spring-config/"}]},{"title":"spring-cloud-demo-01-eureka","slug":"spring-cloud-demo-01-eureka","date":"2020-03-22T07:28:17.000Z","updated":"2020-03-22T07:41:35.735Z","comments":true,"path":"2020/03/22/spring-cloud-demo-01-eureka/","link":"","permalink":"https://seepine.github.io/2020/03/22/spring-cloud-demo-01-eureka/","excerpt":"","text":"本Demo演示了Eureka服务端的搭建,以及消费者如何通过Eureka服务注册中心调用其他供应者提供的接口。源码:https://github.com/seepine/spring-cloud-demo 模块介绍spring-cloud-demo-01-eureka模块分为三个子模块,分别为Eureka-Server(Eureka服务端)、Eureka-Provider(供应者)和Eureka-Consumer(消费者)。 一、Eureka服务注册与发现1.Eureka-Server1.1 添加依赖 123456<dependencies> <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter-netflix-eureka-server</artifactId> </dependency></dependencies> 1.2 在启动类上添加注解@EnableEurekaServer 1234567@EnableEurekaServer@SpringBootApplicationpublic class SpringCloudDemo01EurekaServerApplication { public static void main(String[] args) { SpringApplication.run(SpringCloudDemo01EurekaServerApplication.class, args); }} 1.3 添加配置文件 12345678910server: port: 8761eureka: instance: hostname: localhost client: register-with-eureka: false #该实例是否向EurekaServer注册自己,默认true fetch-registry: false #该实例是否向Eureka服务器获取所有的注册信息表,默认true serviceUrl: defaultZone: http://${eureka.instance.hostname}:${server.port}/eureka/ #配置 Eureka-Server 地址 2.Eureka-Provider1.1 添加依赖 12345678910<dependencies> <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter-netflix-eureka-client</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency></dependencies> 1.2 添加配置文件 12345678910server: port: 8761eureka: instance: hostname: localhost client: register-with-eureka: false #该实例是否向EurekaServer注册自己,默认true fetch-registry: false #该实例是否向Eureka服务器获取所有的注册信息表,默认true serviceUrl: defaultZone: http://${eureka.instance.hostname}:${server.port}/eureka/ #配置 Eureka-Server 地址 启动Demo 1.启动Eureka-Server 2.启动Eureka-Provider 3.启动Eureka-Consumer 结果检验打开http://localhost:8761/,将会看到Eureka的界面以及Eureka-Provider和Eureka-Consumer服务 二、生产者与消费者(RestTemplate)1.Eureka-Provider1.1 添加接口 12345678@RestControllerpublic class ApiController { @RequestMapping(\"/hello/{name}\") public String hello(@PathVariable String name) { System.out.println(\"I am provider , name :\" + name); return \"hello \" + name; }} 1.2 测试接口 2.Eureka-Consumer1.1 添加接口 1234567891011121314151617@RestController@AllArgsConstructorpublic class ApiController { private DiscoveryClient discoveryClient; private RestTemplate restTemplate; @RequestMapping(\"/hello/{name}\") public String hello(@PathVariable String name) { System.out.println(\"I am consumer , name :\" + name); List<ServiceInstance> instances = discoveryClient.getInstances(\"provider\"); if (!instances.isEmpty()) { ServiceInstance serviceInstance = instances.get(0); return restTemplate.getForObject(serviceInstance.getUri().toString() + \"/hello/\" + name, String.class); } return \"not find provider\"; }} 1.2 测试接口 同时Eureka-Provider控制台打印出,说明能够通过Eureka-consumer的接口,调用Eureka-Provider的接口 1I am provider , name :seepine 三、生产者与消费者(Feign)1.Eureka-Consumer1.1 添加Feign依赖 1234<dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter-openfeign</artifactId></dependency> 1.2 启动类添加注解(@EnableFeignClients) 1234567891011121314@EnableEurekaClient@SpringBootApplication@EnableFeignClientspublic class SpringCloudDemo01EurekaConsumerApplication { @Bean public RestTemplate restTemplate() { return new RestTemplate(); } public static void main(String[] args) { SpringApplication.run(SpringCloudDemo01EurekaConsumerApplication.class, args); }} 1.3 添加FeignService 12345678package com.seepine.demo.eureka.consumer.feign;//填写要调用方,即生产者spring.application.name@FeignClient(\"provider\")public interface RemoteApiService { @GetMapping(\"/hello/{name}\") String sayHello(@PathVariable(\"name\") String name);} 1.4 添加接口 12345678910@RestController@AllArgsConstructorpublic class ApiController { private RemoteApiService remoteApiService; @RequestMapping(\"/helloByFeign/{name}\") public String helloByFeign(@PathVariable String name) { return remoteApiService.sayHello(name); }} 1.5 测试接口 同时Eureka-Provider控制台打印出,说明能够通过Eureka-consumer的接口,调用Eureka-Provider的接口 1I am provider , name :seepine-feign 四、Eureka-Server增加用户验证1.添加依赖1234<dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-security</artifactId></dependency> 2.添加配置12345spring: security: user: name: seepine password: 123456 3.打开http://127.0.0.1:8761/验证 4.修改所有Eureka连接url1http://seepine:123456@${eureka.instance.hostname}:${server.port}/eureka/","categories":[{"name":"spring cloud","slug":"spring-cloud","permalink":"https://seepine.github.io/categories/spring-cloud/"}],"tags":[{"name":"eureka","slug":"eureka","permalink":"https://seepine.github.io/tags/eureka/"}]},{"title":"Hello World","slug":"hello-world","date":"2020-01-06T04:12:12.000Z","updated":"2020-01-09T01:06:45.000Z","comments":true,"path":"2020/01/06/hello-world/","link":"","permalink":"https://seepine.github.io/2020/01/06/hello-world/","excerpt":"","text":"Welcome to Hexo! This is your very first post. Check documentation for more info. If you get any problems when using Hexo, you can find the answer in troubleshooting or you can ask me on GitHub. Quick StartCreate a new post1$ hexo new \"My New Post\" More info: Writing Run server1$ hexo server More info: Server Generate static files1$ hexo generate More info: Generating Deploy to remote sites1$ hexo deploy More info: Deployment","categories":[{"name":"教程","slug":"教程","permalink":"https://seepine.github.io/categories/%E6%95%99%E7%A8%8B/"}],"tags":[{"name":"start","slug":"start","permalink":"https://seepine.github.io/tags/start/"}]}],"categories":[{"name":"spring cloud","slug":"spring-cloud","permalink":"https://seepine.github.io/categories/spring-cloud/"},{"name":"教程","slug":"教程","permalink":"https://seepine.github.io/categories/%E6%95%99%E7%A8%8B/"}],"tags":[{"name":"nacos","slug":"nacos","permalink":"https://seepine.github.io/tags/nacos/"},{"name":"spring config","slug":"spring-config","permalink":"https://seepine.github.io/tags/spring-config/"},{"name":"eureka","slug":"eureka","permalink":"https://seepine.github.io/tags/eureka/"},{"name":"start","slug":"start","permalink":"https://seepine.github.io/tags/start/"}]}