From e3c92058fb01c95373a41d8a8e5bac5c6dd4a59f Mon Sep 17 00:00:00 2001
From: Button <2740277548@qq.com>
Date: Sun, 25 Jul 2021 17:21:07 +0800
Subject: [PATCH 1/4] =?UTF-8?q?springboot=E5=BC=82=E6=AD=A5=E5=AE=9E?=
=?UTF-8?q?=E7=8E=B0?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
springboot-async/.gitignore | 33 +++++++++++
springboot-async/pom.xml | 58 +++++++++++++++++++
.../button/SpringbootAsyncApplication.java | 15 +++++
.../com/button/controller/TestController.java | 52 +++++++++++++++++
.../main/java/com/button/job/AsyncJob.java | 23 ++++++++
.../com/button/util/SpringContextUtil.java | 30 ++++++++++
.../src/main/resources/application.yml | 2 +
7 files changed, 213 insertions(+)
create mode 100644 springboot-async/.gitignore
create mode 100644 springboot-async/pom.xml
create mode 100644 springboot-async/src/main/java/com/button/SpringbootAsyncApplication.java
create mode 100644 springboot-async/src/main/java/com/button/controller/TestController.java
create mode 100644 springboot-async/src/main/java/com/button/job/AsyncJob.java
create mode 100644 springboot-async/src/main/java/com/button/util/SpringContextUtil.java
create mode 100644 springboot-async/src/main/resources/application.yml
diff --git a/springboot-async/.gitignore b/springboot-async/.gitignore
new file mode 100644
index 0000000..b56f1dd
--- /dev/null
+++ b/springboot-async/.gitignore
@@ -0,0 +1,33 @@
+README.md
+target/
+!.mvn/wrapper/maven-wrapper.jar
+!**/src/main/**/target/
+!**/src/test/**/target/
+
+### STS ###
+.apt_generated
+.classpath
+.factorypath
+.project
+.settings
+.springBeans
+.sts4-cache
+
+### IntelliJ IDEA ###
+.idea
+*.iws
+*.iml
+*.ipr
+
+### NetBeans ###
+/nbproject/private/
+/nbbuild/
+/dist/
+/nbdist/
+/.nb-gradle/
+build/
+!**/src/main/**/build/
+!**/src/test/**/build/
+
+### VS Code ###
+.vscode/
diff --git a/springboot-async/pom.xml b/springboot-async/pom.xml
new file mode 100644
index 0000000..017f829
--- /dev/null
+++ b/springboot-async/pom.xml
@@ -0,0 +1,58 @@
+
+
+ 4.0.0
+
+ org.springframework.boot
+ spring-boot-starter-parent
+ 2.5.2
+
+
+ com.button
+ springboot-async
+ 0.0.1-SNAPSHOT
+ springboot-async
+ springboot-async异步
+
+ 1.8
+
+
+
+ org.springframework.boot
+ spring-boot-starter-data-rest
+
+
+ org.springframework.boot
+ spring-boot-starter-web
+
+
+
+ org.projectlombok
+ lombok
+ true
+
+
+ org.springframework.boot
+ spring-boot-starter-test
+ test
+
+
+
+
+
+
+ org.springframework.boot
+ spring-boot-maven-plugin
+
+
+
+ org.projectlombok
+ lombok
+
+
+
+
+
+
+
+
diff --git a/springboot-async/src/main/java/com/button/SpringbootAsyncApplication.java b/springboot-async/src/main/java/com/button/SpringbootAsyncApplication.java
new file mode 100644
index 0000000..48f9463
--- /dev/null
+++ b/springboot-async/src/main/java/com/button/SpringbootAsyncApplication.java
@@ -0,0 +1,15 @@
+package com.button;
+
+import org.springframework.boot.SpringApplication;
+import org.springframework.boot.autoconfigure.SpringBootApplication;
+import org.springframework.scheduling.annotation.EnableAsync;
+
+@EnableAsync // 开启异步的注解
+@SpringBootApplication
+public class SpringbootAsyncApplication {
+
+ public static void main(String[] args) {
+ SpringApplication.run(SpringbootAsyncApplication.class, args);
+ }
+
+}
diff --git a/springboot-async/src/main/java/com/button/controller/TestController.java b/springboot-async/src/main/java/com/button/controller/TestController.java
new file mode 100644
index 0000000..4bd8f70
--- /dev/null
+++ b/springboot-async/src/main/java/com/button/controller/TestController.java
@@ -0,0 +1,52 @@
+package com.button.controller;
+
+import com.button.job.AsyncJob;
+import com.button.util.SpringContextUtil;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.scheduling.annotation.Async;
+import org.springframework.web.bind.annotation.GetMapping;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RestController;
+
+@Slf4j
+@RestController
+@RequestMapping("/api")
+public class TestController {
+
+ @Autowired
+ AsyncJob asyncJob;
+
+ /**
+ * 异步任务与调用不在同一个类中
+ * @return
+ */
+ @GetMapping("/success")
+ public String getSuccessInfo() {
+ asyncJob.successAsyncJob();
+ return "success";
+ }
+
+ /**
+ * 异步任务与调用在同一个类中
+ * @return
+ */
+ @GetMapping("/same-class")
+ public String getSameClass() {
+ TestController bean = SpringContextUtil.getBean(TestController.class);
+ bean.test();
+ return "same-class";
+ }
+
+ @Async
+ public void test(){
+ try {
+ log.info("=======开始执行异步处理类========");
+ Thread.sleep(5000);
+ log.info("=======执行异步处理类完毕========");
+ }catch (Exception e){
+ log.error("异常. e={}", e);
+ }
+ }
+
+}
diff --git a/springboot-async/src/main/java/com/button/job/AsyncJob.java b/springboot-async/src/main/java/com/button/job/AsyncJob.java
new file mode 100644
index 0000000..8e588a1
--- /dev/null
+++ b/springboot-async/src/main/java/com/button/job/AsyncJob.java
@@ -0,0 +1,23 @@
+package com.button.job;
+
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.scheduling.annotation.Async;
+import org.springframework.stereotype.Component;
+
+@Component
+@Slf4j
+public class AsyncJob {
+
+ @Async
+ public void successAsyncJob() {
+ try {
+ log.info("/success的异步方法开始执行了......");
+ for(int i = 0; i < 1000000; i++) {
+ log.info("打印{}", i);
+ }
+ log.info("/success的异步方法执行完了......");
+ }catch (Exception e){
+ e.printStackTrace();
+ }
+ }
+}
diff --git a/springboot-async/src/main/java/com/button/util/SpringContextUtil.java b/springboot-async/src/main/java/com/button/util/SpringContextUtil.java
new file mode 100644
index 0000000..2c8b97b
--- /dev/null
+++ b/springboot-async/src/main/java/com/button/util/SpringContextUtil.java
@@ -0,0 +1,30 @@
+package com.button.util;
+
+
+import org.springframework.beans.BeansException;
+import org.springframework.context.ApplicationContext;
+import org.springframework.context.ApplicationContextAware;
+import org.springframework.stereotype.Component;
+
+@Component("springContextUtil")
+public class SpringContextUtil implements ApplicationContextAware {
+ private static ApplicationContext applicationContext = null;
+
+ public static ApplicationContext getApplicationContext() {
+ return applicationContext;
+ }
+
+ @SuppressWarnings("unchecked")
+ public static T getBean(String beanId) {
+ return (T) applicationContext.getBean(beanId);
+ }
+
+ public static T getBean(Class requiredType) {
+ return (T) applicationContext.getBean(requiredType);
+ }
+ @Override
+ public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
+ SpringContextUtil.applicationContext = applicationContext;
+ }
+
+}
diff --git a/springboot-async/src/main/resources/application.yml b/springboot-async/src/main/resources/application.yml
new file mode 100644
index 0000000..0a377cf
--- /dev/null
+++ b/springboot-async/src/main/resources/application.yml
@@ -0,0 +1,2 @@
+server:
+ port: 8819
--
Gitee
From cdbbe277707844edada45fe0323bf105de09e05f Mon Sep 17 00:00:00 2001
From: ZhangHang <252861252@qq.com>
Date: Mon, 26 Jul 2021 15:28:26 +0800
Subject: [PATCH 2/4] springboot-nacos
---
springboot-nacos/.gitignore | 33 ++++
springboot-nacos/README.md | 1 +
springboot-nacos/api-gateway/README.md | 3 +
springboot-nacos/api-gateway/pom.xml | 38 +++++
.../com/button/ApiGatewayApplication.java | 54 ++++++
.../com/button/fallback/SystemFallback.java | 79 +++++++++
.../java/com/button/filter/AccessFilter.java | 76 +++++++++
.../src/main/resources/bootstrap.yml | 18 ++
.../src/main/resources/logback-spring.xml | 72 ++++++++
springboot-nacos/api-system/README.md | 1 +
springboot-nacos/api-system/pom.xml | 35 ++++
.../java/com/button/ApiSystemApplication.java | 15 ++
.../java/com/button/config/SwaggerConfig.java | 65 +++++++
.../com/button/controller/TestController.java | 44 +++++
.../src/main/resources/bootstrap.yml | 18 ++
.../src/main/resources/logback-spring.xml | 72 ++++++++
springboot-nacos/common/pom.xml | 69 ++++++++
.../main/java/com/button/domain/vo/User.java | 9 +
springboot-nacos/pom.xml | 159 ++++++++++++++++++
19 files changed, 861 insertions(+)
create mode 100644 springboot-nacos/.gitignore
create mode 100644 springboot-nacos/README.md
create mode 100644 springboot-nacos/api-gateway/README.md
create mode 100644 springboot-nacos/api-gateway/pom.xml
create mode 100644 springboot-nacos/api-gateway/src/main/java/com/button/ApiGatewayApplication.java
create mode 100644 springboot-nacos/api-gateway/src/main/java/com/button/fallback/SystemFallback.java
create mode 100644 springboot-nacos/api-gateway/src/main/java/com/button/filter/AccessFilter.java
create mode 100644 springboot-nacos/api-gateway/src/main/resources/bootstrap.yml
create mode 100644 springboot-nacos/api-gateway/src/main/resources/logback-spring.xml
create mode 100644 springboot-nacos/api-system/README.md
create mode 100644 springboot-nacos/api-system/pom.xml
create mode 100644 springboot-nacos/api-system/src/main/java/com/button/ApiSystemApplication.java
create mode 100644 springboot-nacos/api-system/src/main/java/com/button/config/SwaggerConfig.java
create mode 100644 springboot-nacos/api-system/src/main/java/com/button/controller/TestController.java
create mode 100644 springboot-nacos/api-system/src/main/resources/bootstrap.yml
create mode 100644 springboot-nacos/api-system/src/main/resources/logback-spring.xml
create mode 100644 springboot-nacos/common/pom.xml
create mode 100644 springboot-nacos/common/src/main/java/com/button/domain/vo/User.java
create mode 100644 springboot-nacos/pom.xml
diff --git a/springboot-nacos/.gitignore b/springboot-nacos/.gitignore
new file mode 100644
index 0000000..549e00a
--- /dev/null
+++ b/springboot-nacos/.gitignore
@@ -0,0 +1,33 @@
+HELP.md
+target/
+!.mvn/wrapper/maven-wrapper.jar
+!**/src/main/**/target/
+!**/src/test/**/target/
+
+### STS ###
+.apt_generated
+.classpath
+.factorypath
+.project
+.settings
+.springBeans
+.sts4-cache
+
+### IntelliJ IDEA ###
+.idea
+*.iws
+*.iml
+*.ipr
+
+### NetBeans ###
+/nbproject/private/
+/nbbuild/
+/dist/
+/nbdist/
+/.nb-gradle/
+build/
+!**/src/main/**/build/
+!**/src/test/**/build/
+
+### VS Code ###
+.vscode/
diff --git a/springboot-nacos/README.md b/springboot-nacos/README.md
new file mode 100644
index 0000000..8b17bef
--- /dev/null
+++ b/springboot-nacos/README.md
@@ -0,0 +1 @@
+Springboot整合nacos
\ No newline at end of file
diff --git a/springboot-nacos/api-gateway/README.md b/springboot-nacos/api-gateway/README.md
new file mode 100644
index 0000000..46b4a83
--- /dev/null
+++ b/springboot-nacos/api-gateway/README.md
@@ -0,0 +1,3 @@
+http://localhost:8081/system/api/test/get-list
+http://localhost:8081/system/api/test/get-token
+http://localhost:8081/system/api/test/get-user
\ No newline at end of file
diff --git a/springboot-nacos/api-gateway/pom.xml b/springboot-nacos/api-gateway/pom.xml
new file mode 100644
index 0000000..beab5e6
--- /dev/null
+++ b/springboot-nacos/api-gateway/pom.xml
@@ -0,0 +1,38 @@
+
+
+ 4.0.0
+
+ com.button
+ springboot-nacos
+ 0.0.1-SNAPSHOT
+
+ springboot-nacos
+ api-gateway
+ 0.0.1-SNAPSHOT
+ api-gateway
+ api-gateway
+
+ 1.8
+
+
+
+ org.springframework.cloud
+ spring-cloud-starter-netflix-zuul
+
+
+ com.alibaba
+ fastjson
+
+
+
+
+
+
+ org.springframework.boot
+ spring-boot-maven-plugin
+
+
+
+
+
diff --git a/springboot-nacos/api-gateway/src/main/java/com/button/ApiGatewayApplication.java b/springboot-nacos/api-gateway/src/main/java/com/button/ApiGatewayApplication.java
new file mode 100644
index 0000000..2dde413
--- /dev/null
+++ b/springboot-nacos/api-gateway/src/main/java/com/button/ApiGatewayApplication.java
@@ -0,0 +1,54 @@
+package com.button;
+
+import com.button.filter.AccessFilter;
+import org.springframework.boot.SpringApplication;
+import org.springframework.boot.autoconfigure.SpringBootApplication;
+import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
+import org.springframework.cloud.netflix.zuul.EnableZuulProxy;
+import org.springframework.context.annotation.Bean;
+import org.springframework.web.cors.CorsConfiguration;
+import org.springframework.web.cors.UrlBasedCorsConfigurationSource;
+import org.springframework.web.filter.CorsFilter;
+
+@EnableZuulProxy
+@EnableDiscoveryClient
+@SpringBootApplication
+public class ApiGatewayApplication {
+
+ public static void main(String[] args) {
+ SpringApplication.run(ApiGatewayApplication.class, args);
+ }
+
+ @Bean
+ public AccessFilter accessFilter() {
+ return new AccessFilter();
+ }
+
+ @Bean
+ public CorsFilter corsFilter() {
+ final UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource();
+ final CorsConfiguration config = new CorsConfiguration();
+ // 允许cookies跨域
+ config.setAllowCredentials(true);
+ // #允许向该服务器提交请求的URI,*表示全部允许,在SpringMVC中,如果设成*,会自动转成当前请求头中的Origin
+ config.addAllowedOrigin("*");
+ // #允许访问的头信息,*表示全部
+ config.addAllowedHeader("*");
+ // 预检请求的缓存时间(秒),即在这个时间段里,对于相同的跨域请求不会再预检了
+ config.setMaxAge(18000L);
+ // 允许提交请求的方法,*表示全部允许
+ config.addAllowedMethod("OPTIONS");
+ config.addAllowedMethod("HEAD");
+ // 允许Get的请求方法
+ config.addAllowedMethod("GET");
+ config.addAllowedMethod("PUT");
+ config.addAllowedMethod("POST");
+ config.addAllowedMethod("DELETE");
+ config.addAllowedMethod("PATCH");
+ //预检请求的有效期,单位为秒
+ config.setMaxAge(3600L);
+ source.registerCorsConfiguration("/**", config);
+ return new CorsFilter(source);
+ }
+
+}
diff --git a/springboot-nacos/api-gateway/src/main/java/com/button/fallback/SystemFallback.java b/springboot-nacos/api-gateway/src/main/java/com/button/fallback/SystemFallback.java
new file mode 100644
index 0000000..22cf247
--- /dev/null
+++ b/springboot-nacos/api-gateway/src/main/java/com/button/fallback/SystemFallback.java
@@ -0,0 +1,79 @@
+package com.button.fallback;
+
+import com.alibaba.fastjson.JSONException;
+import com.alibaba.fastjson.JSONObject;
+import lombok.extern.slf4j.Slf4j;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.cloud.netflix.zuul.filters.route.FallbackProvider;
+import org.springframework.http.HttpHeaders;
+import org.springframework.http.HttpStatus;
+import org.springframework.http.MediaType;
+import org.springframework.http.client.ClientHttpResponse;
+import org.springframework.stereotype.Component;
+
+import java.io.ByteArrayInputStream;
+import java.io.IOException;
+import java.io.InputStream;
+
+@Component
+@Slf4j
+public class SystemFallback implements FallbackProvider {
+
+ @Override
+ public String getRoute() {
+ return "system-service";
+ }
+
+ @Override
+ public ClientHttpResponse fallbackResponse() {
+ return new ClientHttpResponse(){
+
+ @Override
+ public void close() {
+ log.info("close");
+ }
+
+ @Override
+ public HttpStatus getStatusCode() throws IOException {
+ return HttpStatus.OK;
+ }
+
+ @Override
+ public int getRawStatusCode() throws IOException {
+
+ return HttpStatus.OK.value();
+ }
+
+ @Override
+ public String getStatusText() throws IOException {
+ return HttpStatus.OK.getReasonPhrase();
+ }
+
+ @Override
+ public InputStream getBody() throws IOException {
+ JSONObject r = new JSONObject();
+ try {
+ r.put("code", "999");
+ r.put("msg", "system不可用,请联系管理员处理!");
+ } catch (JSONException e) {
+ log.error("获取body异常. e={}", e);
+ }
+ return new ByteArrayInputStream(r.toString().getBytes("UTF-8"));
+ }
+
+ @Override
+ public HttpHeaders getHeaders() {
+ HttpHeaders headers = new HttpHeaders();
+ headers.setContentType(MediaType.APPLICATION_JSON_UTF8);
+ return headers;
+ }
+ };
+ }
+
+ @Override
+ public ClientHttpResponse fallbackResponse(Throwable cause) {
+ log.error("system-service error", cause);
+ return fallbackResponse();
+ }
+}
diff --git a/springboot-nacos/api-gateway/src/main/java/com/button/filter/AccessFilter.java b/springboot-nacos/api-gateway/src/main/java/com/button/filter/AccessFilter.java
new file mode 100644
index 0000000..1ca0d78
--- /dev/null
+++ b/springboot-nacos/api-gateway/src/main/java/com/button/filter/AccessFilter.java
@@ -0,0 +1,76 @@
+package com.button.filter;
+
+import com.alibaba.fastjson.JSON;
+import com.netflix.zuul.ZuulFilter;
+import com.netflix.zuul.context.RequestContext;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.beans.factory.annotation.Value;
+import org.springframework.cloud.netflix.zuul.filters.support.FilterConstants;
+
+import javax.servlet.http.HttpServletRequest;
+import java.util.HashMap;
+import java.util.Map;
+
+@Slf4j
+public class AccessFilter extends ZuulFilter {
+
+ @Value("${zuul.ignored-path}")
+ private String ignoredPath;
+
+ @Override
+ public String filterType() {
+ return FilterConstants.PRE_TYPE;
+ }
+
+ @Override
+ public int filterOrder() {
+ return FilterConstants.SEND_ERROR_FILTER_ORDER;
+ }
+
+ @Override
+ public boolean shouldFilter() {
+ return true;
+ }
+
+ @Override
+ public Object run() {
+ RequestContext ctx = RequestContext.getCurrentContext();
+ HttpServletRequest request = ctx.getRequest();
+ String token = request.getParameter("token");
+ // 判断路径是否不需要验证
+ if (isIgnore(request.getRequestURI())) {
+ return null;
+ }
+ // token为空或者无效token
+ if (token == null) {
+ handleLoginException();
+ }
+ return null;
+ }
+
+ private void handleLoginException() {
+ RequestContext requestContext = RequestContext.getCurrentContext();
+ requestContext.setSendZuulResponse(false);
+ requestContext.setResponseStatusCode(400);
+ Map ex = new HashMap<>();
+ ex.put("code", "000");
+ ex.put("msg", "未登录");
+ String response = JSON.toJSONString(ex);
+ requestContext.setResponseBody(response);
+ requestContext.getResponse().setCharacterEncoding("GBK");
+ }
+ /**
+ * 是否忽略url
+ */
+ private boolean isIgnore(String url) {
+ boolean isIgnore = false;
+ String[] ignoreUrls = ignoredPath.split(",");
+ for (String u : ignoreUrls) {
+ if (url.startsWith(u)) {
+ isIgnore = true;
+ break;
+ }
+ }
+ return isIgnore;
+ }
+}
diff --git a/springboot-nacos/api-gateway/src/main/resources/bootstrap.yml b/springboot-nacos/api-gateway/src/main/resources/bootstrap.yml
new file mode 100644
index 0000000..34144dc
--- /dev/null
+++ b/springboot-nacos/api-gateway/src/main/resources/bootstrap.yml
@@ -0,0 +1,18 @@
+spring:
+ cloud:
+ nacos:
+ config:
+ file-extension: yaml
+# shared-dataids: application-gateway.yml
+ server-addr: dev.apibutton.top:8848
+ ext-config:
+ - data-id: gateway-application.yml
+ group: DEFAULT_GROUP
+ refresh: true
+ - data-id: gateway-application-dev.yml
+ group: DEFAULT_GROUP
+ refresh: true
+ namespace: 39b8efb5-95dd-4d75-b320-0f95f9b9074b
+ discovery:
+ server-addr: dev.apibutton.top:8848
+ namespace: 39b8efb5-95dd-4d75-b320-0f95f9b9074b
\ No newline at end of file
diff --git a/springboot-nacos/api-gateway/src/main/resources/logback-spring.xml b/springboot-nacos/api-gateway/src/main/resources/logback-spring.xml
new file mode 100644
index 0000000..659e398
--- /dev/null
+++ b/springboot-nacos/api-gateway/src/main/resources/logback-spring.xml
@@ -0,0 +1,72 @@
+
+
+
+
+
+ ERROR
+ DENY
+ ACCEPT
+
+
+
+
+ [ %-5level] [%date{yyyy-MM-dd HH:mm:ss}] %logger{96} [%line] - %msg%n
+
+
+
+
+ ${LOG_HOME}/gateway.info.%d{yyyy-MM-dd}.%i.log.zip
+
+ 5
+ true
+ 1GB
+
+
+ 30 MB
+
+
+
+
+
+
+
+ ERROR
+
+
+
+
+ [ %-5level] [%date{yyyy-MM-dd HH:mm:ss}] %logger{96} [%line] - %msg%n
+
+
+
+
+ ${LOG_HOME}/gateway.error.%d{yyyy-MM-dd}.%i.log.zip
+
+ 5
+ true
+ 1GB
+
+
+ 30 MB
+
+
+
+
+
+
+ debug
+
+
+ %d{yyyy-MM-dd HH:mm:ss.SSS} %contextName [%thread] %-5level %logger{36} - %msg%n
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/springboot-nacos/api-system/README.md b/springboot-nacos/api-system/README.md
new file mode 100644
index 0000000..038b9a7
--- /dev/null
+++ b/springboot-nacos/api-system/README.md
@@ -0,0 +1 @@
+http://localhost:8082/doc.html#/home
\ No newline at end of file
diff --git a/springboot-nacos/api-system/pom.xml b/springboot-nacos/api-system/pom.xml
new file mode 100644
index 0000000..408d2f9
--- /dev/null
+++ b/springboot-nacos/api-system/pom.xml
@@ -0,0 +1,35 @@
+
+
+ 4.0.0
+
+ com.button
+ springboot-nacos
+ 0.0.1-SNAPSHOT
+
+ springboot-nacos
+ api-system
+ 0.0.1-SNAPSHOT
+ api-system
+ api-system
+
+ 1.8
+
+
+
+ common
+ com.button
+ 0.0.1-SNAPSHOT
+
+
+
+
+
+
+ org.springframework.boot
+ spring-boot-maven-plugin
+
+
+
+
+
diff --git a/springboot-nacos/api-system/src/main/java/com/button/ApiSystemApplication.java b/springboot-nacos/api-system/src/main/java/com/button/ApiSystemApplication.java
new file mode 100644
index 0000000..f681145
--- /dev/null
+++ b/springboot-nacos/api-system/src/main/java/com/button/ApiSystemApplication.java
@@ -0,0 +1,15 @@
+package com.button;
+
+import org.springframework.boot.SpringApplication;
+import org.springframework.boot.autoconfigure.SpringBootApplication;
+import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
+
+@EnableDiscoveryClient
+@SpringBootApplication
+public class ApiSystemApplication {
+
+ public static void main(String[] args) {
+ SpringApplication.run(ApiSystemApplication.class, args);
+ }
+
+}
diff --git a/springboot-nacos/api-system/src/main/java/com/button/config/SwaggerConfig.java b/springboot-nacos/api-system/src/main/java/com/button/config/SwaggerConfig.java
new file mode 100644
index 0000000..7551295
--- /dev/null
+++ b/springboot-nacos/api-system/src/main/java/com/button/config/SwaggerConfig.java
@@ -0,0 +1,65 @@
+package com.button.config;
+
+import com.github.xiaoymin.knife4j.spring.annotations.EnableKnife4j;
+import io.swagger.annotations.Api;
+import org.springframework.beans.factory.annotation.Value;
+import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+import springfox.documentation.builders.ApiInfoBuilder;
+import springfox.documentation.builders.ParameterBuilder;
+import springfox.documentation.builders.PathSelectors;
+import springfox.documentation.builders.RequestHandlerSelectors;
+import springfox.documentation.schema.ModelRef;
+import springfox.documentation.service.ApiInfo;
+import springfox.documentation.service.Parameter;
+import springfox.documentation.spi.DocumentationType;
+import springfox.documentation.spring.web.plugins.Docket;
+import springfox.documentation.swagger2.annotations.EnableSwagger2;
+
+import java.util.ArrayList;
+import java.util.List;
+
+@Configuration
+@EnableSwagger2
+@EnableKnife4j
+@ConditionalOnProperty(name="swagger.enabled", havingValue="true")
+public class SwaggerConfig {
+ @Value("${swagger.enabled}")
+ private boolean enableSwagger;
+ @Value("${swagger.title}")
+ private String swaggerTitle;
+ @Value("${swagger.description}")
+ private String swaggerDesc;
+ @Value("${swagger.version}")
+ private String swaggerVersion;
+
+ @Bean
+ public Docket createRestApi() {
+ ParameterBuilder tokenPar = new ParameterBuilder();
+ List pars = new ArrayList<>();
+ tokenPar.name("token").description("令牌").modelRef(new ModelRef("string")).parameterType("query").required(true).build();
+ pars.add(tokenPar.build());
+
+ return new Docket(DocumentationType.SWAGGER_2)
+ .enable(enableSwagger)
+ .apiInfo(apiInfo())
+ .groupName(swaggerTitle)
+ .useDefaultResponseMessages(false)
+ .select()
+ .apis(RequestHandlerSelectors.withClassAnnotation(Api.class))
+ .paths(PathSelectors.any())
+ .build()
+ .globalOperationParameters(pars)
+ ;
+ }
+
+ private ApiInfo apiInfo() {
+ return new ApiInfoBuilder()
+ .title(swaggerTitle)
+ .description(swaggerDesc)
+ .version(swaggerVersion)
+ .build();
+
+ }
+}
diff --git a/springboot-nacos/api-system/src/main/java/com/button/controller/TestController.java b/springboot-nacos/api-system/src/main/java/com/button/controller/TestController.java
new file mode 100644
index 0000000..0d0f425
--- /dev/null
+++ b/springboot-nacos/api-system/src/main/java/com/button/controller/TestController.java
@@ -0,0 +1,44 @@
+package com.button.controller;
+
+import com.button.domain.vo.User;
+import io.swagger.annotations.Api;
+import io.swagger.annotations.ApiOperation;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.validation.annotation.Validated;
+import org.springframework.web.bind.annotation.GetMapping;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RestController;
+
+import javax.servlet.http.HttpServletRequest;
+
+@RestController
+@Slf4j
+@Validated
+@Api(tags = "测试API")
+@RequestMapping(value = "/api/test", produces = "application/json")
+public class TestController {
+
+ @GetMapping("/get-list")
+ @ApiOperation(value = "测试get", notes = "作者:zh")
+ public String getList(HttpServletRequest request) {
+ log.info("测试");
+ return "SUCCESS";
+ }
+
+
+ @GetMapping("/get-token")
+ @ApiOperation(value = "测试get(需要token)", notes = "作者:zh")
+ public String getListToken(HttpServletRequest request) {
+ log.info("测试");
+ return "SUCCESS-TOKEN";
+ }
+
+ @GetMapping("/get-user")
+ @ApiOperation(value = "测试", notes = "作者:zh")
+ public User getUser(HttpServletRequest request) {
+ User user = new User();
+ user.setName("张三");
+ user.setPassword("123456789");
+ return user;
+ }
+}
diff --git a/springboot-nacos/api-system/src/main/resources/bootstrap.yml b/springboot-nacos/api-system/src/main/resources/bootstrap.yml
new file mode 100644
index 0000000..60928a7
--- /dev/null
+++ b/springboot-nacos/api-system/src/main/resources/bootstrap.yml
@@ -0,0 +1,18 @@
+spring:
+ cloud:
+ nacos:
+ config:
+ file-extension: yaml
+# shared-dataids: application-gateway.yml
+ server-addr: dev.apibutton.top:8848
+ ext-config:
+ - data-id: system-application.yml
+ group: DEFAULT_GROUP
+ refresh: true
+ - data-id: system-application-dev.yml
+ group: DEFAULT_GROUP
+ refresh: true
+ namespace: 39b8efb5-95dd-4d75-b320-0f95f9b9074b
+ discovery:
+ server-addr: dev.apibutton.top:8848
+ namespace: 39b8efb5-95dd-4d75-b320-0f95f9b9074b
\ No newline at end of file
diff --git a/springboot-nacos/api-system/src/main/resources/logback-spring.xml b/springboot-nacos/api-system/src/main/resources/logback-spring.xml
new file mode 100644
index 0000000..fc4af7c
--- /dev/null
+++ b/springboot-nacos/api-system/src/main/resources/logback-spring.xml
@@ -0,0 +1,72 @@
+
+
+
+
+
+ ERROR
+ DENY
+ ACCEPT
+
+
+
+
+ [ %-5level] [%date{yyyy-MM-dd HH:mm:ss}] %logger{96} [%line] - %msg%n
+
+
+
+
+ ${LOG_HOME}/system.info.%d{yyyy-MM-dd}.%i.log.zip
+
+ 5
+ true
+ 1GB
+
+
+ 30 MB
+
+
+
+
+
+
+
+ ERROR
+
+
+
+
+ [ %-5level] [%date{yyyy-MM-dd HH:mm:ss}] %logger{96} [%line] - %msg%n
+
+
+
+
+ ${LOG_HOME}/system.error.%d{yyyy-MM-dd}.%i.log.zip
+
+ 5
+ true
+ 1GB
+
+
+ 30 MB
+
+
+
+
+
+
+ debug
+
+
+ %d{yyyy-MM-dd HH:mm:ss.SSS} %contextName [%thread] %-5level %logger{36} - %msg%n
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/springboot-nacos/common/pom.xml b/springboot-nacos/common/pom.xml
new file mode 100644
index 0000000..3e05f4f
--- /dev/null
+++ b/springboot-nacos/common/pom.xml
@@ -0,0 +1,69 @@
+
+
+
+
+ springboot-nacos
+ com.button
+ 0.0.1-SNAPSHOT
+
+ 4.0.0
+
+ common
+ com.button
+ 0.0.1-SNAPSHOT
+ jar
+ common
+
+
+ UTF-8
+ 1.7
+ 1.7
+
+
+
+
+
+
+
+
+
+ maven-clean-plugin
+ 3.1.0
+
+
+ maven-resources-plugin
+ 3.0.2
+
+
+ maven-compiler-plugin
+ 3.8.0
+
+
+ maven-surefire-plugin
+ 2.22.1
+
+
+ maven-jar-plugin
+ 3.0.2
+
+
+ maven-install-plugin
+ 2.5.2
+
+
+ maven-deploy-plugin
+ 2.8.2
+
+
+ maven-site-plugin
+ 3.7.1
+
+
+ maven-project-info-reports-plugin
+ 3.0.0
+
+
+
+
+
diff --git a/springboot-nacos/common/src/main/java/com/button/domain/vo/User.java b/springboot-nacos/common/src/main/java/com/button/domain/vo/User.java
new file mode 100644
index 0000000..39db796
--- /dev/null
+++ b/springboot-nacos/common/src/main/java/com/button/domain/vo/User.java
@@ -0,0 +1,9 @@
+package com.button.domain.vo;
+
+import lombok.Data;
+
+@Data
+public class User {
+ private String name;
+ private String password;
+}
diff --git a/springboot-nacos/pom.xml b/springboot-nacos/pom.xml
new file mode 100644
index 0000000..ab3e4bd
--- /dev/null
+++ b/springboot-nacos/pom.xml
@@ -0,0 +1,159 @@
+
+
+ 4.0.0
+
+ org.springframework.boot
+ spring-boot-starter-parent
+ 1.5.9.RELEASE
+
+
+
+ com.button
+ springboot-nacos
+ 0.0.1-SNAPSHOT
+ pom
+ springboot-nacos
+ springboot整合nacos
+
+
+ api-gateway
+ common
+ api-system
+
+
+
+ UTF-8
+ UTF-8
+ 1.8
+ Edgware.SR1
+
+
+
+
+ org.springframework.boot
+ spring-boot-starter
+
+
+ org.springframework.boot
+ spring-boot-starter-test
+ test
+
+
+ org.springframework.boot
+ spring-boot-starter-web
+
+
+ org.springframework.cloud
+ spring-cloud-starter
+
+
+ com.alibaba.cloud
+ spring-cloud-starter-alibaba-nacos-discovery
+ 1.5.1.RELEASE
+
+
+ com.alibaba.cloud
+ spring-cloud-starter-alibaba-nacos-config
+ 1.5.1.RELEASE
+
+
+ org.springframework.cloud
+ spring-cloud-starter-openfeign
+
+
+ org.springframework.cloud
+ spring-cloud-starter-netflix-ribbon
+
+
+ org.springframework.cloud
+ spring-cloud-starter-netflix-hystrix
+
+
+ org.springframework.boot
+ spring-boot-configuration-processor
+ true
+
+
+ org.springframework.boot
+ spring-boot-starter-aop
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ org.slf4j
+ slf4j-api
+
+
+ io.springfox
+ springfox-swagger2
+ 2.7.0
+
+
+ io.springfox
+ springfox-swagger-ui
+ 2.7.0
+
+
+ com.github.xiaoymin
+ knife4j-spring-boot-starter
+ 2.0.4
+
+
+
+
+
+
+
+ org.projectlombok
+ lombok
+ provided
+
+
+
+
+
+
+
+ org.springframework.cloud
+ spring-cloud-dependencies
+ ${spring-cloud.version}
+ pom
+ import
+
+
+ org.springframework.cloud
+ spring-cloud-commons
+ 1.3.5.RELEASE
+
+
+ com.alibaba
+ fastjson
+ 1.2.70
+
+
+
+
+
+
+
+ org.springframework.boot
+ spring-boot-maven-plugin
+
+
+
+
+
--
Gitee
From e2480fb7a4cc7bdce8c905836f09869ad9c0b736 Mon Sep 17 00:00:00 2001
From: ZhangHang <252861252@qq.com>
Date: Mon, 26 Jul 2021 15:30:52 +0800
Subject: [PATCH 3/4] =?UTF-8?q?=E6=8F=90=E4=BA=A4readme?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
README.md | 2 ++
1 file changed, 2 insertions(+)
diff --git a/README.md b/README.md
index c0c91f5..9df57bd 100644
--- a/README.md
+++ b/README.md
@@ -29,5 +29,7 @@ SpringBoot应用集合
- [SpringBoot整合ActiveMq](https://gitee.com/superbutton/SpringBoot-Components/tree/develop/Springboot-ActiveMq)
- [SpringBoot整合Knife4j](https://gitee.com/superbutton/SpringBoot-Components/tree/develop/springboot-knife4j)
- [springboot-pagehelper实现分页查询](https://gitee.com/superbutton/SpringBoot-Components/tree/develop/Springboot-pagehelper)
+- [springboot-pagehelper实现分页查询](https://gitee.com/superbutton/SpringBoot-Components/tree/develop/Springboot-pagehelper)
+- [springboot-nacos注册中心](https://gitee.com/superbutton/SpringBoot-Components/tree/develop/springboot-nacos)
--
Gitee
From 3bafecc66e84b6449e33ec5a63f8773a10e09e05 Mon Sep 17 00:00:00 2001
From: ZhangHang <252861252@qq.com>
Date: Mon, 26 Jul 2021 15:32:07 +0800
Subject: [PATCH 4/4] readme
---
README.md | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/README.md b/README.md
index 9df57bd..6bcc1ef 100644
--- a/README.md
+++ b/README.md
@@ -29,7 +29,7 @@ SpringBoot应用集合
- [SpringBoot整合ActiveMq](https://gitee.com/superbutton/SpringBoot-Components/tree/develop/Springboot-ActiveMq)
- [SpringBoot整合Knife4j](https://gitee.com/superbutton/SpringBoot-Components/tree/develop/springboot-knife4j)
- [springboot-pagehelper实现分页查询](https://gitee.com/superbutton/SpringBoot-Components/tree/develop/Springboot-pagehelper)
-- [springboot-pagehelper实现分页查询](https://gitee.com/superbutton/SpringBoot-Components/tree/develop/Springboot-pagehelper)
+- [springboot-async实现异步](https://gitee.com/superbutton/SpringBoot-Components/tree/develop/springboot-async)
- [springboot-nacos注册中心](https://gitee.com/superbutton/SpringBoot-Components/tree/develop/springboot-nacos)
--
Gitee