# Conflicts: # sop-auth/pom.xml # sop-example/sop-book/sop-book-web/pom.xml # sop-example/sop-book/sop-book-web/src/main/resources/application-dev.properties # sop-example/sop-easyopen/pom.xml # sop-example/sop-easyopen/src/main/resources/application-dev.properties # sop-example/sop-story/sop-story-web/pom.xml # sop-example/sop-story/src/main/resources/application-dev.properties # sop-gateway/pom.xml # sop-website/pom.xmleureka
commit
1245f830dd
@ -1,39 +1,39 @@ |
|||||||
* [首页](/?t=1589794156310) |
* [首页](/?t=1591927043815) |
||||||
* 开发文档 |
* 开发文档 |
||||||
* [快速体验](files/10010_快速体验.md?t=1589794156312) |
* [快速体验](files/10010_快速体验.md?t=1591927043817) |
||||||
* [项目接入到SOP](files/10011_项目接入到SOP.md?t=1589794156333) |
* [项目接入到SOP](files/10011_项目接入到SOP.md?t=1591927043835) |
||||||
* [新增接口](files/10020_新增接口.md?t=1589794156333) |
* [新增接口](files/10020_新增接口.md?t=1591927043836) |
||||||
* [开发流程](files/10021_开发流程.md?t=1589794156333) |
* [开发流程](files/10021_开发流程.md?t=1591927043836) |
||||||
* [业务参数校验](files/10030_业务参数校验.md?t=1589794156333) |
* [业务参数校验](files/10030_业务参数校验.md?t=1591927043836) |
||||||
* [错误处理](files/10040_错误处理.md?t=1589794156333) |
* [错误处理](files/10040_错误处理.md?t=1591927043836) |
||||||
* [编写文档](files/10041_编写文档.md?t=1589794156333) |
* [编写文档](files/10041_编写文档.md?t=1591927043836) |
||||||
* [接口交互详解](files/10050_接口交互详解.md?t=1589794156333) |
* [接口交互详解](files/10050_接口交互详解.md?t=1591927043836) |
||||||
* [easyopen支持](files/10070_easyopen支持.md?t=1589794156333) |
* [easyopen支持](files/10070_easyopen支持.md?t=1591927043836) |
||||||
* [使用签名校验工具](files/10080_使用签名校验工具.md?t=1589794156334) |
* [使用签名校验工具](files/10080_使用签名校验工具.md?t=1591927043836) |
||||||
* [ISV管理](files/10085_ISV管理.md?t=1589794156334) |
* [ISV管理](files/10085_ISV管理.md?t=1591927043836) |
||||||
* [自定义返回结果](files/10087_自定义返回结果.md?t=1589794156334) |
* [自定义返回结果](files/10087_自定义返回结果.md?t=1591927043837) |
||||||
* [自定义过滤器](files/10088_自定义过滤器.md?t=1589794156334) |
* [自定义过滤器](files/10088_自定义过滤器.md?t=1591927043837) |
||||||
* [自定义校验token](files/10089_自定义校验token.md?t=1589794156334) |
* [自定义校验token](files/10089_自定义校验token.md?t=1591927043837) |
||||||
* [网关拦截器](files/10090_网关拦截器.md?t=1589794156334) |
* [网关拦截器](files/10090_网关拦截器.md?t=1591927043837) |
||||||
* [路由授权](files/10090_路由授权.md?t=1589794156335) |
* [路由授权](files/10090_路由授权.md?t=1591927043837) |
||||||
* [接口限流](files/10092_接口限流.md?t=1589794156335) |
* [接口限流](files/10092_接口限流.md?t=1591927043837) |
||||||
* [路由监控](files/10093_路由监控.md?t=1589794156335) |
* [路由监控](files/10093_路由监控.md?t=1591927043837) |
||||||
* [SDK开发](files/10095_SDK开发.md?t=1589794156335) |
* [SDK开发](files/10095_SDK开发.md?t=1591927043837) |
||||||
* [使用SpringCloudGateway](files/10096_使用SpringCloudGateway.md?t=1589794156335) |
* [使用SpringCloudGateway](files/10096_使用SpringCloudGateway.md?t=1591927043837) |
||||||
* [应用授权](files/10097_应用授权.md?t=1589794156335) |
* [应用授权](files/10097_应用授权.md?t=1591927043837) |
||||||
* [提供restful接口](files/10100_提供restful接口.md?t=1589794156335) |
* [提供restful接口](files/10100_提供restful接口.md?t=1591927043838) |
||||||
* [文件上传](files/10104_文件上传.md?t=1589794156336) |
* [文件上传](files/10104_文件上传.md?t=1591927043838) |
||||||
* [配置Sleuth链路追踪](files/10109_配置Sleuth链路追踪.md?t=1589794156336) |
* [配置Sleuth链路追踪](files/10109_配置Sleuth链路追踪.md?t=1591927043838) |
||||||
* [预发布灰度发布](files/10110_预发布灰度发布.md?t=1589794156336) |
* [预发布灰度发布](files/10110_预发布灰度发布.md?t=1591927043838) |
||||||
* [动态修改请求参数](files/10111_动态修改请求参数.md?t=1589794156336) |
* [动态修改请求参数](files/10111_动态修改请求参数.md?t=1591927043838) |
||||||
* [使用eureka](files/10112_使用eureka.md?t=1589794156336) |
* [使用eureka](files/10112_使用eureka.md?t=1591927043838) |
||||||
* [扩展其它注册中心](files/10113_扩展其它注册中心.md?t=1589794156336) |
* [扩展其它注册中心](files/10113_扩展其它注册中心.md?t=1591927043838) |
||||||
* 原理分析 |
* 原理分析 |
||||||
* [网关性能测试](files/90001_网关性能测试.md?t=1589794156336) |
* [网关性能测试](files/90001_网关性能测试.md?t=1591927043838) |
||||||
* [原理分析之@ApiMapping](files/90010_原理分析之@ApiMapping.md?t=1589794156337) |
* [原理分析之@ApiMapping](files/90010_原理分析之@ApiMapping.md?t=1591927043838) |
||||||
* [原理分析之如何存储路由](files/90011_原理分析之如何存储路由.md?t=1589794156337) |
* [原理分析之如何存储路由](files/90011_原理分析之如何存储路由.md?t=1591927043838) |
||||||
* [原理分析之如何路由](files/90012_原理分析之如何路由.md?t=1589794156337) |
* [原理分析之如何路由](files/90012_原理分析之如何路由.md?t=1591927043839) |
||||||
* [原理分析之文档归纳](files/90013_原理分析之文档归纳.md?t=1589794156337) |
* [原理分析之文档归纳](files/90013_原理分析之文档归纳.md?t=1591927043839) |
||||||
* [原理分析之预发布灰度发布](files/90014_原理分析之预发布灰度发布.md?t=1589794156337) |
* [原理分析之预发布灰度发布](files/90014_原理分析之预发布灰度发布.md?t=1591927043839) |
||||||
* [2.x升3.x注意事项](files/90099_2.x升3.x注意事项.md?t=1589794156337) |
* [2.x升3.x注意事项](files/90099_2.x升3.x注意事项.md?t=1591927043839) |
||||||
* [常见问题](files/90100_常见问题.md?t=1589794156337) |
* [常见问题](files/90100_常见问题.md?t=1591927043839) |
||||||
|
@ -1 +1 @@ |
|||||||
<!DOCTYPE html><html><head><meta charset=utf-8><meta http-equiv=X-UA-Compatible content="IE=edge,chrome=1"><meta name=viewport content="width=device-width,initial-scale=1,maximum-scale=1,user-scalable=no"><link rel=icon href=favicon.ico><title>SOP Admin</title><link href=static/css/chunk-elementUI.81cf475c.css rel=stylesheet><link href=static/css/chunk-libs.3dfb7769.css rel=stylesheet><link href=static/css/app.c6dfb7ee.css rel=stylesheet></head><body><noscript><strong>We're sorry but SOP Admin doesn't work properly without JavaScript enabled. Please enable it to continue.</strong></noscript><div id=app></div><script>(function(e){function n(n){for(var r,c,a=n[0],f=n[1],i=n[2],d=0,l=[];d<a.length;d++)c=a[d],u[c]&&l.push(u[c][0]),u[c]=0;for(r in f)Object.prototype.hasOwnProperty.call(f,r)&&(e[r]=f[r]);h&&h(n);while(l.length)l.shift()();return o.push.apply(o,i||[]),t()}function t(){for(var e,n=0;n<o.length;n++){for(var t=o[n],r=!0,c=1;c<t.length;c++){var a=t[c];0!==u[a]&&(r=!1)}r&&(o.splice(n--,1),e=f(f.s=t[0]))}return e}var r={},c={runtime:0},u={runtime:0},o=[];function a(e){return f.p+"static/js/"+({}[e]||e)+"."+{"chunk-25908fca":"66819987","chunk-2c1f2e8f":"f092c0a0","chunk-2d0d32e7":"213708f2","chunk-2d2085ef":"91d75f3c","chunk-2d221c34":"20057287","chunk-4de1c2b6":"e74e3d03","chunk-626b7094":"97d3a892","chunk-73b2dcec":"60c5d8e9","chunk-9b31c83a":"52bc6b2c","chunk-9f479afe":"51cf2439","chunk-c3ce42fe":"9517b588"}[e]+".js"}function f(n){if(r[n])return r[n].exports;var t=r[n]={i:n,l:!1,exports:{}};return e[n].call(t.exports,t,t.exports,f),t.l=!0,t.exports}f.e=function(e){var n=[],t={"chunk-25908fca":1,"chunk-2c1f2e8f":1,"chunk-4de1c2b6":1,"chunk-626b7094":1,"chunk-73b2dcec":1,"chunk-9b31c83a":1,"chunk-c3ce42fe":1};c[e]?n.push(c[e]):0!==c[e]&&t[e]&&n.push(c[e]=new Promise(function(n,t){for(var r="static/css/"+({}[e]||e)+"."+{"chunk-25908fca":"a66354ec","chunk-2c1f2e8f":"0314067f","chunk-2d0d32e7":"31d6cfe0","chunk-2d2085ef":"31d6cfe0","chunk-2d221c34":"31d6cfe0","chunk-4de1c2b6":"a37cd815","chunk-626b7094":"e41ad972","chunk-73b2dcec":"ed391cc5","chunk-9b31c83a":"3b12267b","chunk-9f479afe":"31d6cfe0","chunk-c3ce42fe":"6b789903"}[e]+".css",u=f.p+r,o=document.getElementsByTagName("link"),a=0;a<o.length;a++){var i=o[a],d=i.getAttribute("data-href")||i.getAttribute("href");if("stylesheet"===i.rel&&(d===r||d===u))return n()}var l=document.getElementsByTagName("style");for(a=0;a<l.length;a++){i=l[a],d=i.getAttribute("data-href");if(d===r||d===u)return n()}var h=document.createElement("link");h.rel="stylesheet",h.type="text/css",h.onload=n,h.onerror=function(n){var r=n&&n.target&&n.target.src||u,o=new Error("Loading CSS chunk "+e+" failed.\n("+r+")");o.code="CSS_CHUNK_LOAD_FAILED",o.request=r,delete c[e],h.parentNode.removeChild(h),t(o)},h.href=u;var s=document.getElementsByTagName("head")[0];s.appendChild(h)}).then(function(){c[e]=0}));var r=u[e];if(0!==r)if(r)n.push(r[2]);else{var o=new Promise(function(n,t){r=u[e]=[n,t]});n.push(r[2]=o);var i,d=document.createElement("script");d.charset="utf-8",d.timeout=120,f.nc&&d.setAttribute("nonce",f.nc),d.src=a(e),i=function(n){d.onerror=d.onload=null,clearTimeout(l);var t=u[e];if(0!==t){if(t){var r=n&&("load"===n.type?"missing":n.type),c=n&&n.target&&n.target.src,o=new Error("Loading chunk "+e+" failed.\n("+r+": "+c+")");o.type=r,o.request=c,t[1](o)}u[e]=void 0}};var l=setTimeout(function(){i({type:"timeout",target:d})},12e4);d.onerror=d.onload=i,document.head.appendChild(d)}return Promise.all(n)},f.m=e,f.c=r,f.d=function(e,n,t){f.o(e,n)||Object.defineProperty(e,n,{enumerable:!0,get:t})},f.r=function(e){"undefined"!==typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},f.t=function(e,n){if(1&n&&(e=f(e)),8&n)return e;if(4&n&&"object"===typeof e&&e&&e.__esModule)return e;var t=Object.create(null);if(f.r(t),Object.defineProperty(t,"default",{enumerable:!0,value:e}),2&n&&"string"!=typeof e)for(var r in e)f.d(t,r,function(n){return e[n]}.bind(null,r));return t},f.n=function(e){var n=e&&e.__esModule?function(){return e["default"]}:function(){return e};return f.d(n,"a",n),n},f.o=function(e,n){return Object.prototype.hasOwnProperty.call(e,n)},f.p="",f.oe=function(e){throw console.error(e),e};var i=window["webpackJsonp"]=window["webpackJsonp"]||[],d=i.push.bind(i);i.push=n,i=i.slice();for(var l=0;l<i.length;l++)n(i[l]);var h=d;t()})([]);</script><script src=static/js/chunk-elementUI.298ac98c.js></script><script src=static/js/chunk-libs.75deb05f.js></script><script src=static/js/app.c6e80241.js></script></body></html> |
<!DOCTYPE html><html><head><meta charset=utf-8><meta http-equiv=X-UA-Compatible content="IE=edge,chrome=1"><meta name=viewport content="width=device-width,initial-scale=1,maximum-scale=1,user-scalable=no"><link rel=icon href=favicon.ico><title>SOP Admin</title><link href=static/css/chunk-elementUI.81cf475c.css rel=stylesheet><link href=static/css/chunk-libs.3dfb7769.css rel=stylesheet><link href=static/css/app.c6dfb7ee.css rel=stylesheet></head><body><noscript><strong>We're sorry but SOP Admin doesn't work properly without JavaScript enabled. Please enable it to continue.</strong></noscript><div id=app></div><script>(function(e){function n(n){for(var r,c,a=n[0],f=n[1],i=n[2],d=0,l=[];d<a.length;d++)c=a[d],u[c]&&l.push(u[c][0]),u[c]=0;for(r in f)Object.prototype.hasOwnProperty.call(f,r)&&(e[r]=f[r]);h&&h(n);while(l.length)l.shift()();return o.push.apply(o,i||[]),t()}function t(){for(var e,n=0;n<o.length;n++){for(var t=o[n],r=!0,c=1;c<t.length;c++){var a=t[c];0!==u[a]&&(r=!1)}r&&(o.splice(n--,1),e=f(f.s=t[0]))}return e}var r={},c={runtime:0},u={runtime:0},o=[];function a(e){return f.p+"static/js/"+({}[e]||e)+"."+{"chunk-25908fca":"66819987","chunk-2c1f2e8f":"f092c0a0","chunk-2d0d32e7":"213708f2","chunk-2d2085ef":"91d75f3c","chunk-2d221c34":"20057287","chunk-4de1c2b6":"e74e3d03","chunk-626b7094":"97d3a892","chunk-73b2dcec":"60c5d8e9","chunk-9b31c83a":"52bc6b2c","chunk-9f479afe":"4609bf8b","chunk-c3ce42fe":"9517b588"}[e]+".js"}function f(n){if(r[n])return r[n].exports;var t=r[n]={i:n,l:!1,exports:{}};return e[n].call(t.exports,t,t.exports,f),t.l=!0,t.exports}f.e=function(e){var n=[],t={"chunk-25908fca":1,"chunk-2c1f2e8f":1,"chunk-4de1c2b6":1,"chunk-626b7094":1,"chunk-73b2dcec":1,"chunk-9b31c83a":1,"chunk-c3ce42fe":1};c[e]?n.push(c[e]):0!==c[e]&&t[e]&&n.push(c[e]=new Promise(function(n,t){for(var r="static/css/"+({}[e]||e)+"."+{"chunk-25908fca":"a66354ec","chunk-2c1f2e8f":"0314067f","chunk-2d0d32e7":"31d6cfe0","chunk-2d2085ef":"31d6cfe0","chunk-2d221c34":"31d6cfe0","chunk-4de1c2b6":"a37cd815","chunk-626b7094":"e41ad972","chunk-73b2dcec":"ed391cc5","chunk-9b31c83a":"3b12267b","chunk-9f479afe":"31d6cfe0","chunk-c3ce42fe":"6b789903"}[e]+".css",u=f.p+r,o=document.getElementsByTagName("link"),a=0;a<o.length;a++){var i=o[a],d=i.getAttribute("data-href")||i.getAttribute("href");if("stylesheet"===i.rel&&(d===r||d===u))return n()}var l=document.getElementsByTagName("style");for(a=0;a<l.length;a++){i=l[a],d=i.getAttribute("data-href");if(d===r||d===u)return n()}var h=document.createElement("link");h.rel="stylesheet",h.type="text/css",h.onload=n,h.onerror=function(n){var r=n&&n.target&&n.target.src||u,o=new Error("Loading CSS chunk "+e+" failed.\n("+r+")");o.code="CSS_CHUNK_LOAD_FAILED",o.request=r,delete c[e],h.parentNode.removeChild(h),t(o)},h.href=u;var s=document.getElementsByTagName("head")[0];s.appendChild(h)}).then(function(){c[e]=0}));var r=u[e];if(0!==r)if(r)n.push(r[2]);else{var o=new Promise(function(n,t){r=u[e]=[n,t]});n.push(r[2]=o);var i,d=document.createElement("script");d.charset="utf-8",d.timeout=120,f.nc&&d.setAttribute("nonce",f.nc),d.src=a(e),i=function(n){d.onerror=d.onload=null,clearTimeout(l);var t=u[e];if(0!==t){if(t){var r=n&&("load"===n.type?"missing":n.type),c=n&&n.target&&n.target.src,o=new Error("Loading chunk "+e+" failed.\n("+r+": "+c+")");o.type=r,o.request=c,t[1](o)}u[e]=void 0}};var l=setTimeout(function(){i({type:"timeout",target:d})},12e4);d.onerror=d.onload=i,document.head.appendChild(d)}return Promise.all(n)},f.m=e,f.c=r,f.d=function(e,n,t){f.o(e,n)||Object.defineProperty(e,n,{enumerable:!0,get:t})},f.r=function(e){"undefined"!==typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},f.t=function(e,n){if(1&n&&(e=f(e)),8&n)return e;if(4&n&&"object"===typeof e&&e&&e.__esModule)return e;var t=Object.create(null);if(f.r(t),Object.defineProperty(t,"default",{enumerable:!0,value:e}),2&n&&"string"!=typeof e)for(var r in e)f.d(t,r,function(n){return e[n]}.bind(null,r));return t},f.n=function(e){var n=e&&e.__esModule?function(){return e["default"]}:function(){return e};return f.d(n,"a",n),n},f.o=function(e,n){return Object.prototype.hasOwnProperty.call(e,n)},f.p="",f.oe=function(e){throw console.error(e),e};var i=window["webpackJsonp"]=window["webpackJsonp"]||[],d=i.push.bind(i);i.push=n,i=i.slice();for(var l=0;l<i.length;l++)n(i[l]);var h=d;t()})([]);</script><script src=static/js/chunk-elementUI.298ac98c.js></script><script src=static/js/chunk-libs.75deb05f.js></script><script src=static/js/app.c6e80241.js></script></body></html> |
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
@ -1,119 +0,0 @@ |
|||||||
package com.gitee.sop.gatewaycommon.manager; |
|
||||||
|
|
||||||
import com.alibaba.fastjson.JSON; |
|
||||||
import com.alibaba.nacos.api.annotation.NacosInjected; |
|
||||||
import com.alibaba.nacos.api.config.ConfigService; |
|
||||||
import com.alibaba.nacos.api.config.listener.AbstractListener; |
|
||||||
import com.alibaba.nacos.api.exception.NacosException; |
|
||||||
import com.gitee.sop.gatewaycommon.bean.ChannelMsg; |
|
||||||
import com.gitee.sop.gatewaycommon.bean.NacosConfigs; |
|
||||||
import com.gitee.sop.gatewaycommon.secret.IsvManager; |
|
||||||
import lombok.extern.slf4j.Slf4j; |
|
||||||
import org.springframework.beans.factory.annotation.Autowired; |
|
||||||
|
|
||||||
import javax.annotation.PostConstruct; |
|
||||||
|
|
||||||
/** |
|
||||||
* 用不到了,这个类的作用是监听消息推送用的。由admin推送一条config配置,然后这里触发事件。 |
|
||||||
* 现在改为直接由admin请求网关提供的接口进行配置修改。 |
|
||||||
* 考虑 |
|
||||||
* |
|
||||||
* @author tanghc |
|
||||||
*/ |
|
||||||
@Slf4j |
|
||||||
@Deprecated |
|
||||||
public class NacosEventProcessor { |
|
||||||
|
|
||||||
@NacosInjected |
|
||||||
private ConfigService configService; |
|
||||||
|
|
||||||
@Autowired |
|
||||||
private EnvGrayManager envGrayManager; |
|
||||||
|
|
||||||
@Autowired |
|
||||||
private IPBlacklistManager ipBlacklistManager; |
|
||||||
|
|
||||||
@Autowired |
|
||||||
private IsvManager isvManager; |
|
||||||
|
|
||||||
@Autowired |
|
||||||
private IsvRoutePermissionManager isvRoutePermissionManager; |
|
||||||
|
|
||||||
@Autowired |
|
||||||
private LimitConfigManager limitConfigManager; |
|
||||||
|
|
||||||
@Autowired |
|
||||||
private RouteConfigManager routeConfigManager; |
|
||||||
|
|
||||||
@PostConstruct |
|
||||||
public void after() throws NacosException { |
|
||||||
log.debug("初始化nacos事件监听"); |
|
||||||
initEnvGray(); |
|
||||||
initIPBlack(); |
|
||||||
initIsv(); |
|
||||||
initIsvRoutePermission(); |
|
||||||
initLimitConfig(); |
|
||||||
initRouteConfig(); |
|
||||||
} |
|
||||||
|
|
||||||
private void initEnvGray() throws NacosException { |
|
||||||
configService.addListener(NacosConfigs.DATA_ID_GRAY, NacosConfigs.GROUP_CHANNEL, new AbstractListener() { |
|
||||||
@Override |
|
||||||
public void receiveConfigInfo(String configInfo) { |
|
||||||
ChannelMsg channelMsg = JSON.parseObject(configInfo, ChannelMsg.class); |
|
||||||
envGrayManager.process(channelMsg); |
|
||||||
} |
|
||||||
}); |
|
||||||
} |
|
||||||
|
|
||||||
private void initIPBlack() throws NacosException { |
|
||||||
configService.addListener(NacosConfigs.DATA_ID_IP_BLACKLIST, NacosConfigs.GROUP_CHANNEL, new AbstractListener() { |
|
||||||
@Override |
|
||||||
public void receiveConfigInfo(String configInfo) { |
|
||||||
ChannelMsg channelMsg = JSON.parseObject(configInfo, ChannelMsg.class); |
|
||||||
ipBlacklistManager.process(channelMsg); |
|
||||||
} |
|
||||||
}); |
|
||||||
} |
|
||||||
|
|
||||||
private void initIsv() throws NacosException { |
|
||||||
configService.addListener(NacosConfigs.DATA_ID_ISV, NacosConfigs.GROUP_CHANNEL, new AbstractListener() { |
|
||||||
@Override |
|
||||||
public void receiveConfigInfo(String configInfo) { |
|
||||||
ChannelMsg channelMsg = JSON.parseObject(configInfo, ChannelMsg.class); |
|
||||||
isvManager.process(channelMsg); |
|
||||||
} |
|
||||||
}); |
|
||||||
} |
|
||||||
|
|
||||||
private void initIsvRoutePermission() throws NacosException { |
|
||||||
configService.addListener(NacosConfigs.DATA_ID_ROUTE_PERMISSION, NacosConfigs.GROUP_CHANNEL, new AbstractListener() { |
|
||||||
@Override |
|
||||||
public void receiveConfigInfo(String configInfo) { |
|
||||||
ChannelMsg channelMsg = JSON.parseObject(configInfo, ChannelMsg.class); |
|
||||||
isvRoutePermissionManager.process(channelMsg); |
|
||||||
} |
|
||||||
}); |
|
||||||
} |
|
||||||
|
|
||||||
private void initLimitConfig() throws NacosException { |
|
||||||
configService.addListener(NacosConfigs.DATA_ID_LIMIT_CONFIG, NacosConfigs.GROUP_CHANNEL, new AbstractListener() { |
|
||||||
@Override |
|
||||||
public void receiveConfigInfo(String configInfo) { |
|
||||||
ChannelMsg channelMsg = JSON.parseObject(configInfo, ChannelMsg.class); |
|
||||||
limitConfigManager.process(channelMsg); |
|
||||||
} |
|
||||||
}); |
|
||||||
} |
|
||||||
|
|
||||||
private void initRouteConfig() throws NacosException { |
|
||||||
configService.addListener(NacosConfigs.DATA_ID_ROUTE_CONFIG, NacosConfigs.GROUP_CHANNEL, new AbstractListener() { |
|
||||||
@Override |
|
||||||
public void receiveConfigInfo(String configInfo) { |
|
||||||
ChannelMsg channelMsg = JSON.parseObject(configInfo, ChannelMsg.class); |
|
||||||
routeConfigManager.process(channelMsg); |
|
||||||
} |
|
||||||
}); |
|
||||||
} |
|
||||||
|
|
||||||
} |
|
@ -1,183 +0,0 @@ |
|||||||
package com.gitee.sop.gatewaycommon.manager; |
|
||||||
|
|
||||||
import com.alibaba.fastjson.JSON; |
|
||||||
import com.alibaba.nacos.api.annotation.NacosInjected; |
|
||||||
import com.alibaba.nacos.api.config.ConfigService; |
|
||||||
import com.alibaba.nacos.api.exception.NacosException; |
|
||||||
import com.alibaba.nacos.api.naming.NamingService; |
|
||||||
import com.alibaba.nacos.api.naming.pojo.Instance; |
|
||||||
import com.alibaba.nacos.api.naming.pojo.ServiceInfo; |
|
||||||
import com.gitee.sop.gatewaycommon.bean.NacosConfigs; |
|
||||||
import com.gitee.sop.gatewaycommon.bean.ServiceRouteInfo; |
|
||||||
import com.gitee.sop.gatewaycommon.bean.SopConstants; |
|
||||||
import com.gitee.sop.gatewaycommon.bean.TargetRoute; |
|
||||||
import com.gitee.sop.gatewaycommon.route.RegistryMetadata; |
|
||||||
import com.gitee.sop.gatewaycommon.route.RegistryListener; |
|
||||||
import lombok.extern.slf4j.Slf4j; |
|
||||||
import org.apache.commons.lang.StringUtils; |
|
||||||
import org.springframework.beans.factory.annotation.Autowired; |
|
||||||
import org.springframework.cloud.alibaba.nacos.NacosDiscoveryProperties; |
|
||||||
import org.springframework.context.ApplicationEvent; |
|
||||||
import org.springframework.http.HttpStatus; |
|
||||||
import org.springframework.http.ResponseEntity; |
|
||||||
import org.springframework.util.CollectionUtils; |
|
||||||
import org.springframework.util.DigestUtils; |
|
||||||
import org.springframework.web.client.DefaultResponseErrorHandler; |
|
||||||
import org.springframework.web.client.RestTemplate; |
|
||||||
|
|
||||||
import java.util.HashMap; |
|
||||||
import java.util.List; |
|
||||||
import java.util.Map; |
|
||||||
import java.util.Objects; |
|
||||||
|
|
||||||
/** |
|
||||||
* 发现新服务,更新路由信息 |
|
||||||
* |
|
||||||
* @author tanghc |
|
||||||
* |
|
||||||
* @deprecated |
|
||||||
* @see RegistryListener |
|
||||||
*/ |
|
||||||
@Deprecated |
|
||||||
@Slf4j |
|
||||||
public class ServiceRoutesLoader<T extends TargetRoute> implements RegistryMetadata { |
|
||||||
|
|
||||||
private static final String SOP_ROUTES_PATH = "/sop/routes"; |
|
||||||
|
|
||||||
private static final String SECRET = "a3d9sf!1@odl90zd>fkASwq"; |
|
||||||
|
|
||||||
private static final int FIVE_SECONDS = 1000 * 5; |
|
||||||
|
|
||||||
private static final String METADATA_SOP_ROUTES_PATH = "sop.routes.path"; |
|
||||||
|
|
||||||
@Autowired |
|
||||||
private NacosDiscoveryProperties nacosDiscoveryProperties; |
|
||||||
|
|
||||||
@NacosInjected |
|
||||||
private ConfigService configService; |
|
||||||
|
|
||||||
@Autowired |
|
||||||
private BaseRouteCache<T> baseRouteCache; |
|
||||||
|
|
||||||
private RestTemplate restTemplate = new RestTemplate(); |
|
||||||
|
|
||||||
private Map<String, Long> updateTimeMap = new HashMap<>(16); |
|
||||||
|
|
||||||
public ServiceRoutesLoader() { |
|
||||||
// 解决statusCode不等于200,就抛异常问题
|
|
||||||
restTemplate.setErrorHandler(new DefaultResponseErrorHandler() { |
|
||||||
@Override |
|
||||||
protected boolean hasError(HttpStatus statusCode) { |
|
||||||
return statusCode == null; |
|
||||||
} |
|
||||||
}); |
|
||||||
} |
|
||||||
|
|
||||||
public synchronized void load(ApplicationEvent event) { |
|
||||||
NamingService namingService = nacosDiscoveryProperties.namingServiceInstance(); |
|
||||||
List<ServiceInfo> subscribes = null; |
|
||||||
try { |
|
||||||
subscribes = namingService.getSubscribeServices(); |
|
||||||
} catch (NacosException e) { |
|
||||||
log.error("namingService.getSubscribeServices()错误", e); |
|
||||||
} |
|
||||||
if (CollectionUtils.isEmpty(subscribes)) { |
|
||||||
return; |
|
||||||
} |
|
||||||
// subscribe
|
|
||||||
String thisServiceId = nacosDiscoveryProperties.getService(); |
|
||||||
for (ServiceInfo serviceInfo : subscribes) { |
|
||||||
String serviceName = serviceInfo.getName(); |
|
||||||
// 如果是本机服务,跳过
|
|
||||||
if (Objects.equals(thisServiceId, serviceName)) { |
|
||||||
continue; |
|
||||||
} |
|
||||||
// nacos会不停的触发事件,这里做了一层拦截
|
|
||||||
// 同一个serviceId5秒内允许访问一次
|
|
||||||
Long lastUpdateTime = updateTimeMap.getOrDefault(serviceName, 0L); |
|
||||||
long now = System.currentTimeMillis(); |
|
||||||
if (now - lastUpdateTime < FIVE_SECONDS) { |
|
||||||
continue; |
|
||||||
} |
|
||||||
updateTimeMap.put(serviceName, now); |
|
||||||
try { |
|
||||||
String dataId = NacosConfigs.getRouteDataId(serviceName); |
|
||||||
String groupId = NacosConfigs.GROUP_ROUTE; |
|
||||||
List<Instance> allInstances = namingService.getAllInstances(serviceName); |
|
||||||
if (CollectionUtils.isEmpty(allInstances)) { |
|
||||||
// 如果没有服务列表,则删除所有路由信息
|
|
||||||
log.info("服务下线,删除路由配置,serviceId: {}", serviceName); |
|
||||||
baseRouteCache.remove(serviceName); |
|
||||||
configService.removeConfig(dataId, groupId); |
|
||||||
} else { |
|
||||||
for (Instance instance : allInstances) { |
|
||||||
String url = getRouteRequestUrl(instance); |
|
||||||
log.info("拉取路由配置,serviceId: {}, url: {}", serviceName, url); |
|
||||||
ResponseEntity<String> responseEntity = restTemplate.getForEntity(url, String.class); |
|
||||||
if (responseEntity.getStatusCode() == HttpStatus.OK) { |
|
||||||
String body = responseEntity.getBody(); |
|
||||||
ServiceRouteInfo serviceRouteInfo = JSON.parseObject(body, ServiceRouteInfo.class); |
|
||||||
baseRouteCache.load(serviceRouteInfo, callback -> { |
|
||||||
try { |
|
||||||
log.info("推送路由配置到nacos,dataId: {}, groupId: {}", dataId, groupId); |
|
||||||
configService.publishConfig(dataId, groupId, body); |
|
||||||
} catch (NacosException e) { |
|
||||||
log.error("nacos推送失败,serviceId: {}, instance: {}", serviceName, instance); |
|
||||||
} |
|
||||||
}); |
|
||||||
} else { |
|
||||||
log.error("拉取路由配置异常,url: {}, status: {}, body: {}", url, responseEntity.getStatusCodeValue(), responseEntity.getBody()); |
|
||||||
} |
|
||||||
} |
|
||||||
} |
|
||||||
} catch (Exception e) { |
|
||||||
log.error("选择服务实例失败,serviceName: {}", serviceName, e); |
|
||||||
} |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
/** |
|
||||||
* 拉取路由请求url |
|
||||||
* @param instance 服务实例 |
|
||||||
* @return 返回最终url |
|
||||||
*/ |
|
||||||
private String getRouteRequestUrl(Instance instance) { |
|
||||||
Map<String, String> metadata = instance.getMetadata(); |
|
||||||
String customPath = metadata.get(METADATA_SOP_ROUTES_PATH); |
|
||||||
String homeUrl; |
|
||||||
String servletPath; |
|
||||||
// 如果metadata中指定了获取路由的url
|
|
||||||
if (StringUtils.isNotBlank(customPath)) { |
|
||||||
// 自定义完整的url
|
|
||||||
if (customPath.startsWith("http")) { |
|
||||||
homeUrl = customPath; |
|
||||||
servletPath = ""; |
|
||||||
} else { |
|
||||||
homeUrl = getHomeUrl(instance); |
|
||||||
servletPath = customPath; |
|
||||||
} |
|
||||||
} else { |
|
||||||
// 默认处理
|
|
||||||
homeUrl = getHomeUrl(instance); |
|
||||||
String contextPath = this.getContextPath(metadata); |
|
||||||
servletPath = contextPath + SOP_ROUTES_PATH; |
|
||||||
} |
|
||||||
if (StringUtils.isNotBlank(servletPath) && !servletPath.startsWith("/")) { |
|
||||||
servletPath = '/' + servletPath; |
|
||||||
} |
|
||||||
String query = buildQuery(SECRET); |
|
||||||
return homeUrl + servletPath + query; |
|
||||||
} |
|
||||||
|
|
||||||
private static String getHomeUrl(Instance instance) { |
|
||||||
return "http://" + instance.getIp() + ":" + instance.getPort(); |
|
||||||
} |
|
||||||
|
|
||||||
private static String buildQuery(String secret) { |
|
||||||
String time = String.valueOf(System.currentTimeMillis()); |
|
||||||
String source = secret + time + secret; |
|
||||||
String sign = DigestUtils.md5DigestAsHex(source.getBytes()); |
|
||||||
return "?time=" + time + "&sign=" + sign; |
|
||||||
} |
|
||||||
|
|
||||||
} |
|
@ -0,0 +1,23 @@ |
|||||||
|
package com.gitee.sop.gatewaycommon.route; |
||||||
|
|
||||||
|
import com.gitee.sop.gatewaycommon.bean.InstanceDefinition; |
||||||
|
|
||||||
|
/** |
||||||
|
* 新的实例注册事件 |
||||||
|
* |
||||||
|
* @author tanghc |
||||||
|
*/ |
||||||
|
public interface RegistryEvent { |
||||||
|
|
||||||
|
/** |
||||||
|
* 新实例注册进来时触发 |
||||||
|
* @param instanceDefinition 实例信息 |
||||||
|
*/ |
||||||
|
void onRegistry(InstanceDefinition instanceDefinition); |
||||||
|
|
||||||
|
/** |
||||||
|
* 服务下线时触发 |
||||||
|
* @param serviceId 服务id |
||||||
|
*/ |
||||||
|
void onRemove(String serviceId); |
||||||
|
} |
@ -0,0 +1,11 @@ |
|||||||
|
package com.gitee.sop.gatewaycommon.route; |
||||||
|
|
||||||
|
import lombok.AllArgsConstructor; |
||||||
|
import lombok.Data; |
||||||
|
|
||||||
|
@Data |
||||||
|
@AllArgsConstructor |
||||||
|
public class ServiceHolder { |
||||||
|
private String serviceId; |
||||||
|
private long lastUpdatedTimestamp; |
||||||
|
} |
@ -1,30 +0,0 @@ |
|||||||
package com.gitee.sop.servercommon.manager; |
|
||||||
|
|
||||||
import com.alibaba.fastjson.JSON; |
|
||||||
import com.gitee.sop.servercommon.bean.ServiceApiInfo; |
|
||||||
import lombok.extern.slf4j.Slf4j; |
|
||||||
import org.springframework.data.redis.core.StringRedisTemplate; |
|
||||||
|
|
||||||
/** |
|
||||||
* @author tanghc |
|
||||||
*/ |
|
||||||
@Slf4j |
|
||||||
public class RedisApiMetaManager implements ApiMetaManager { |
|
||||||
public static final String API_STORE_KEY = "com.gitee.sop.api"; |
|
||||||
public static final String API_CHANGE_CHANNEL = "channel.sop.api.change"; |
|
||||||
|
|
||||||
private StringRedisTemplate redisTemplate; |
|
||||||
|
|
||||||
public RedisApiMetaManager(StringRedisTemplate redisTemplate) { |
|
||||||
this.redisTemplate = redisTemplate; |
|
||||||
} |
|
||||||
|
|
||||||
@Override |
|
||||||
public void uploadApi(ServiceApiInfo serviceApiInfo) { |
|
||||||
log.info("上传接口信息到Redis,serviceId:{}, 接口数量:{}", serviceApiInfo.getServiceId(), serviceApiInfo.getApis().size()); |
|
||||||
String serviceApiInfoJson = JSON.toJSONString(serviceApiInfo); |
|
||||||
redisTemplate.opsForHash().put(API_STORE_KEY, serviceApiInfo.getServiceId(), serviceApiInfoJson); |
|
||||||
// 发送订阅事件
|
|
||||||
redisTemplate.convertAndSend(API_CHANGE_CHANNEL, serviceApiInfoJson); |
|
||||||
} |
|
||||||
} |
|
@ -1,15 +0,0 @@ |
|||||||
<?xml version="1.0" encoding="UTF-8"?> |
|
||||||
<project xmlns="http://maven.apache.org/POM/4.0.0" |
|
||||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" |
|
||||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> |
|
||||||
<modelVersion>4.0.0</modelVersion> |
|
||||||
<groupId>com.gitee.sop</groupId> |
|
||||||
<artifactId>sop-book-parent</artifactId> |
|
||||||
<version>1.0.0-SNAPSHOT</version> |
|
||||||
<packaging>pom</packaging> |
|
||||||
|
|
||||||
<modules> |
|
||||||
<module>sop-book-api</module> |
|
||||||
<module>sop-book-web</module> |
|
||||||
</modules> |
|
||||||
</project> |
|
@ -1,25 +0,0 @@ |
|||||||
/target/ |
|
||||||
!.mvn/wrapper/maven-wrapper.jar |
|
||||||
|
|
||||||
### 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/ |
|
@ -1,46 +0,0 @@ |
|||||||
<?xml version="1.0" encoding="UTF-8"?> |
|
||||||
<project xmlns="http://maven.apache.org/POM/4.0.0" |
|
||||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" |
|
||||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> |
|
||||||
<modelVersion>4.0.0</modelVersion> |
|
||||||
<parent> |
|
||||||
<groupId>org.springframework.boot</groupId> |
|
||||||
<artifactId>spring-boot-starter-parent</artifactId> |
|
||||||
<version>2.1.2.RELEASE</version> |
|
||||||
<relativePath/> <!-- lookup parent from repository --> |
|
||||||
</parent> |
|
||||||
<groupId>com.gitee.sop</groupId> |
|
||||||
<artifactId>sop-book-api</artifactId> |
|
||||||
<version>1.0-SNAPSHOT</version> |
|
||||||
|
|
||||||
<properties> |
|
||||||
<java.version>1.8</java.version> |
|
||||||
<spring-cloud.version>Greenwich.RELEASE</spring-cloud.version> |
|
||||||
</properties> |
|
||||||
|
|
||||||
<dependencies> |
|
||||||
<dependency> |
|
||||||
<groupId>org.springframework.boot</groupId> |
|
||||||
<artifactId>spring-boot-starter-web</artifactId> |
|
||||||
</dependency> |
|
||||||
|
|
||||||
<dependency> |
|
||||||
<groupId>org.projectlombok</groupId> |
|
||||||
<artifactId>lombok</artifactId> |
|
||||||
<version>1.18.4</version> |
|
||||||
<scope>provided</scope> |
|
||||||
</dependency> |
|
||||||
</dependencies> |
|
||||||
|
|
||||||
<dependencyManagement> |
|
||||||
<dependencies> |
|
||||||
<dependency> |
|
||||||
<groupId>org.springframework.cloud</groupId> |
|
||||||
<artifactId>spring-cloud-dependencies</artifactId> |
|
||||||
<version>${spring-cloud.version}</version> |
|
||||||
<type>pom</type> |
|
||||||
<scope>import</scope> |
|
||||||
</dependency> |
|
||||||
</dependencies> |
|
||||||
</dependencyManagement> |
|
||||||
</project> |
|
@ -1,12 +0,0 @@ |
|||||||
package com.gitee.book.api.domain; |
|
||||||
|
|
||||||
import lombok.Data; |
|
||||||
|
|
||||||
/** |
|
||||||
* @author tanghc |
|
||||||
*/ |
|
||||||
@Data |
|
||||||
public class Book { |
|
||||||
private int id; |
|
||||||
private String name; |
|
||||||
} |
|
@ -1,14 +0,0 @@ |
|||||||
package com.gitee.book.api.service; |
|
||||||
|
|
||||||
import com.gitee.book.api.domain.Book; |
|
||||||
import org.springframework.web.bind.annotation.RequestMapping; |
|
||||||
import org.springframework.web.bind.annotation.RequestParam; |
|
||||||
|
|
||||||
/** |
|
||||||
* @author tanghc |
|
||||||
*/ |
|
||||||
@RequestMapping("/book") |
|
||||||
public interface BookService { |
|
||||||
@RequestMapping("/getBook") |
|
||||||
Book getBook(@RequestParam("id") int id); |
|
||||||
} |
|
@ -1,25 +0,0 @@ |
|||||||
/target/ |
|
||||||
!.mvn/wrapper/maven-wrapper.jar |
|
||||||
|
|
||||||
### 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/ |
|
@ -1,153 +0,0 @@ |
|||||||
<?xml version="1.0" encoding="UTF-8"?> |
|
||||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" |
|
||||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> |
|
||||||
<modelVersion>4.0.0</modelVersion> |
|
||||||
<parent> |
|
||||||
<groupId>org.springframework.boot</groupId> |
|
||||||
<artifactId>spring-boot-starter-parent</artifactId> |
|
||||||
<version>2.1.2.RELEASE</version> |
|
||||||
<relativePath/> <!-- lookup parent from repository --> |
|
||||||
</parent> |
|
||||||
<groupId>com.gitee.sop</groupId> |
|
||||||
<artifactId>sop-book-web</artifactId> |
|
||||||
<version>0.0.1-SNAPSHOT</version> |
|
||||||
<name>sop-book</name> |
|
||||||
<description>Demo project for Spring Boot</description> |
|
||||||
|
|
||||||
<properties> |
|
||||||
<java.version>1.8</java.version> |
|
||||||
<dubbo.version>2.6.5</dubbo.version> |
|
||||||
<spring-cloud.version>Greenwich.RELEASE</spring-cloud.version> |
|
||||||
<!-- nacos spring cloud版本号 --> |
|
||||||
<spring-cloud-alibaba-nacos.version>0.9.0.RELEASE</spring-cloud-alibaba-nacos.version> |
|
||||||
<!-- nacos客户端版本号 --> |
|
||||||
<nacos-client.version>1.1.3</nacos-client.version> |
|
||||||
</properties> |
|
||||||
|
|
||||||
<dependencies> |
|
||||||
<dependency> |
|
||||||
<groupId>com.gitee.sop</groupId> |
|
||||||
<artifactId>sop-service-common</artifactId> |
|
||||||
<version>3.1.5-SNAPSHOT</version> |
|
||||||
</dependency> |
|
||||||
<dependency> |
|
||||||
<groupId>com.gitee.sop</groupId> |
|
||||||
<artifactId>sop-book-api</artifactId> |
|
||||||
<version>1.0-SNAPSHOT</version> |
|
||||||
</dependency> |
|
||||||
<dependency> |
|
||||||
<groupId>com.gitee.sop</groupId> |
|
||||||
<artifactId>sop-story-api</artifactId> |
|
||||||
<version>1.0-SNAPSHOT</version> |
|
||||||
</dependency> |
|
||||||
|
|
||||||
|
|
||||||
<!-- 使用nacos注册中心 |
|
||||||
版本 0.2.x.RELEASE 对应的是 Spring Boot 2.x 版本,版本 0.1.x.RELEASE 对应的是 Spring Boot 1.x 版本。 |
|
||||||
https://mvnrepository.com/artifact/org.springframework.cloud/spring-cloud-starter-alibaba-nacos-discovery |
|
||||||
|
|
||||||
<dependency> |
|
||||||
<groupId>org.springframework.cloud</groupId> |
|
||||||
<artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId> |
|
||||||
<version>${spring-cloud-alibaba-nacos.version}</version> |
|
||||||
</dependency> |
|
||||||
<dependency> |
|
||||||
<groupId>com.alibaba.nacos</groupId> |
|
||||||
<artifactId>nacos-client</artifactId> |
|
||||||
<version>${nacos-client.version}</version> |
|
||||||
</dependency> |
|
||||||
--> |
|
||||||
<!-- 注册中心end --> |
|
||||||
|
|
||||||
<dependency> |
|
||||||
<groupId>org.springframework.cloud</groupId> |
|
||||||
<artifactId>spring-cloud-starter-netflix-eureka-client</artifactId> |
|
||||||
</dependency> |
|
||||||
|
|
||||||
<dependency> |
|
||||||
<groupId>org.springframework.cloud</groupId> |
|
||||||
<artifactId>spring-cloud-starter-openfeign</artifactId> |
|
||||||
</dependency> |
|
||||||
|
|
||||||
<!-- Dubbo Spring Boot Starter --> |
|
||||||
<dependency> |
|
||||||
<groupId>com.alibaba.boot</groupId> |
|
||||||
<artifactId>dubbo-spring-boot-starter</artifactId> |
|
||||||
<version>0.2.1.RELEASE</version> |
|
||||||
</dependency> |
|
||||||
<dependency> |
|
||||||
<groupId>com.alibaba</groupId> |
|
||||||
<artifactId>dubbo</artifactId> |
|
||||||
<version>${dubbo.version}</version> |
|
||||||
</dependency> |
|
||||||
<dependency> |
|
||||||
<groupId>io.netty</groupId> |
|
||||||
<artifactId>netty-all</artifactId> |
|
||||||
</dependency> |
|
||||||
|
|
||||||
<!-- swagger2 --> |
|
||||||
<dependency> |
|
||||||
<groupId>io.springfox</groupId> |
|
||||||
<artifactId>springfox-swagger2</artifactId> |
|
||||||
<version>2.9.2</version> |
|
||||||
<exclusions> |
|
||||||
<exclusion> |
|
||||||
<groupId>io.swagger</groupId> |
|
||||||
<artifactId>swagger-models</artifactId> |
|
||||||
</exclusion> |
|
||||||
</exclusions> |
|
||||||
</dependency> |
|
||||||
<dependency> |
|
||||||
<groupId>io.swagger</groupId> |
|
||||||
<artifactId>swagger-models</artifactId> |
|
||||||
<version>1.5.21</version> |
|
||||||
</dependency> |
|
||||||
<dependency> |
|
||||||
<groupId>io.springfox</groupId> |
|
||||||
<artifactId>springfox-swagger-ui</artifactId> |
|
||||||
<version>2.9.2</version> |
|
||||||
</dependency> |
|
||||||
|
|
||||||
<dependency> |
|
||||||
<groupId>org.springframework.boot</groupId> |
|
||||||
<artifactId>spring-boot-starter-test</artifactId> |
|
||||||
<scope>test</scope> |
|
||||||
</dependency> |
|
||||||
<dependency> |
|
||||||
<groupId>org.projectlombok</groupId> |
|
||||||
<artifactId>lombok</artifactId> |
|
||||||
<version>1.18.4</version> |
|
||||||
<scope>compile</scope> |
|
||||||
</dependency> |
|
||||||
</dependencies> |
|
||||||
|
|
||||||
<dependencyManagement> |
|
||||||
<dependencies> |
|
||||||
<dependency> |
|
||||||
<groupId>org.springframework.cloud</groupId> |
|
||||||
<artifactId>spring-cloud-dependencies</artifactId> |
|
||||||
<version>${spring-cloud.version}</version> |
|
||||||
<type>pom</type> |
|
||||||
<scope>import</scope> |
|
||||||
</dependency> |
|
||||||
</dependencies> |
|
||||||
</dependencyManagement> |
|
||||||
|
|
||||||
<build> |
|
||||||
<plugins> |
|
||||||
<plugin> |
|
||||||
<groupId>org.springframework.boot</groupId> |
|
||||||
<artifactId>spring-boot-maven-plugin</artifactId> |
|
||||||
</plugin> |
|
||||||
</plugins> |
|
||||||
</build> |
|
||||||
|
|
||||||
<repositories> |
|
||||||
<repository> |
|
||||||
<id>spring-milestones</id> |
|
||||||
<name>Spring Milestones</name> |
|
||||||
<url>https://repo.spring.io/milestone</url> |
|
||||||
</repository> |
|
||||||
</repositories> |
|
||||||
|
|
||||||
</project> |
|
@ -1,20 +0,0 @@ |
|||||||
package com.gitee.sop.bookweb; |
|
||||||
|
|
||||||
import org.springframework.boot.SpringApplication; |
|
||||||
import org.springframework.boot.autoconfigure.SpringBootApplication; |
|
||||||
import org.springframework.cloud.client.discovery.EnableDiscoveryClient; |
|
||||||
import org.springframework.cloud.openfeign.EnableFeignClients; |
|
||||||
|
|
||||||
// 允许调用其他服务
|
|
||||||
@EnableFeignClients |
|
||||||
// 服务注册
|
|
||||||
@EnableDiscoveryClient |
|
||||||
@SpringBootApplication |
|
||||||
public class SopBookApplication { |
|
||||||
|
|
||||||
public static void main(String[] args) { |
|
||||||
SpringApplication.run(SopBookApplication.class, args); |
|
||||||
} |
|
||||||
|
|
||||||
} |
|
||||||
|
|
@ -1,33 +0,0 @@ |
|||||||
package com.gitee.sop.bookweb.config; |
|
||||||
|
|
||||||
import com.gitee.sop.servercommon.configuration.AlipayServiceConfiguration; |
|
||||||
import com.gitee.sop.servercommon.swagger.SwaggerSupport; |
|
||||||
import org.springframework.context.annotation.Configuration; |
|
||||||
import springfox.documentation.swagger2.annotations.EnableSwagger2; |
|
||||||
|
|
||||||
/** |
|
||||||
* 使用支付宝开放平台功能 |
|
||||||
* @author tanghc |
|
||||||
*/ |
|
||||||
@Configuration |
|
||||||
public class OpenServiceConfig extends AlipayServiceConfiguration { |
|
||||||
|
|
||||||
// 开启文档
|
|
||||||
@Configuration |
|
||||||
@EnableSwagger2 |
|
||||||
public static class Swagger2 extends SwaggerSupport { |
|
||||||
@Override |
|
||||||
protected String getDocTitle() { |
|
||||||
return "图书API"; |
|
||||||
} |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
/** |
|
||||||
* 使用淘宝开放平台功能 |
|
||||||
* @author tanghc |
|
||||||
*/ |
|
||||||
//@Configuration
|
|
||||||
//public class OpenServiceConfig extends TaobaoServiceConfiguration {
|
|
||||||
//
|
|
||||||
//}
|
|
@ -1,14 +0,0 @@ |
|||||||
package com.gitee.sop.bookweb.consumer; |
|
||||||
|
|
||||||
import com.gitee.sop.story.api.service.StoryService; |
|
||||||
import org.springframework.cloud.openfeign.FeignClient; |
|
||||||
|
|
||||||
/** |
|
||||||
* 调用story服务 |
|
||||||
* |
|
||||||
* @author tanghc |
|
||||||
*/ |
|
||||||
// value对应的spring.application.name
|
|
||||||
@FeignClient("story-service") |
|
||||||
public interface StoryServiceConsumer extends StoryService { |
|
||||||
} |
|
@ -1,55 +0,0 @@ |
|||||||
package com.gitee.sop.bookweb.controller; |
|
||||||
|
|
||||||
import com.gitee.book.api.domain.Book; |
|
||||||
import com.gitee.sop.bookweb.consumer.StoryServiceConsumer; |
|
||||||
import com.gitee.sop.bookweb.param.BookParam; |
|
||||||
import com.gitee.sop.bookweb.vo.BookVO; |
|
||||||
import com.gitee.sop.servercommon.annotation.ApiMapping; |
|
||||||
import com.gitee.sop.story.api.domain.Story; |
|
||||||
import io.swagger.annotations.Api; |
|
||||||
import io.swagger.annotations.ApiOperation; |
|
||||||
import org.springframework.beans.factory.annotation.Autowired; |
|
||||||
import org.springframework.web.bind.annotation.RestController; |
|
||||||
|
|
||||||
import java.util.Arrays; |
|
||||||
|
|
||||||
/** |
|
||||||
* 这里演示如何接受业务参数。 |
|
||||||
* @author tanghc |
|
||||||
*/ |
|
||||||
@Api(tags = "图书接口") |
|
||||||
@RestController |
|
||||||
public class AlipayBookController { |
|
||||||
|
|
||||||
@Autowired |
|
||||||
StoryServiceConsumer storyServiceConsumer; |
|
||||||
|
|
||||||
@ApiOperation(value="查询书本信息", notes = "可以根据ISBN查询书本信息") |
|
||||||
@ApiMapping(value = "book.search") |
|
||||||
public BookVO searchBook(BookParam param) { |
|
||||||
BookVO bookVO = new BookVO(); |
|
||||||
bookVO.setId(1); |
|
||||||
bookVO.setName("白雪公主,ISBN:" + param.getIsbn()); |
|
||||||
bookVO.setIsbn("ABCSSSSDDD"); |
|
||||||
return bookVO; |
|
||||||
} |
|
||||||
|
|
||||||
@ApiMapping(value = "alipay.book.get") |
|
||||||
public Book getBook() { |
|
||||||
Book story = new Book(); |
|
||||||
story.setId(1); |
|
||||||
story.setName("白雪公主(alipay.book.get)"); |
|
||||||
return story; |
|
||||||
} |
|
||||||
|
|
||||||
// 通过Feign调用story服务
|
|
||||||
@ApiMapping(value = "alipay.book.story.get") |
|
||||||
public Object getBook2() { |
|
||||||
Story story = new Story(); |
|
||||||
story.setId(1); |
|
||||||
story.setName("白雪公主(alipay.book.story.get)"); |
|
||||||
Story story2 = storyServiceConsumer.getStory(1); |
|
||||||
return Arrays.asList(story, story2); |
|
||||||
} |
|
||||||
|
|
||||||
} |
|
@ -1,72 +0,0 @@ |
|||||||
package com.gitee.sop.bookweb.controller; |
|
||||||
|
|
||||||
import lombok.Data; |
|
||||||
|
|
||||||
/** |
|
||||||
* 默认的结果封装类. |
|
||||||
* <pre> |
|
||||||
* |
|
||||||
* xml返回结果: |
|
||||||
* <response> |
|
||||||
* <code>50</code> |
|
||||||
* <msg>Remote service error</msg> |
|
||||||
* <sub_code>isv.invalid-parameter</sub_code> |
|
||||||
* <sub_msg>非法参数</sub_msg> |
|
||||||
* </response> |
|
||||||
* 成功情况: |
|
||||||
* <response> |
|
||||||
* <code>0</code> |
|
||||||
* <msg>成功消息</msg> |
|
||||||
* <data> |
|
||||||
* ...返回内容 |
|
||||||
* </data> |
|
||||||
* </response> |
|
||||||
* |
|
||||||
* json返回格式: |
|
||||||
* { |
|
||||||
* "code":"50", |
|
||||||
* "msg":"Remote service error", |
|
||||||
* "sub_code":"isv.invalid-parameter", |
|
||||||
* "sub_msg":"非法参数" |
|
||||||
* } |
|
||||||
* 成功情况: |
|
||||||
* { |
|
||||||
* "code":"0", |
|
||||||
* "msg":"成功消息内容。。。", |
|
||||||
* "data":{ |
|
||||||
* ...返回内容 |
|
||||||
* } |
|
||||||
* } |
|
||||||
* </pre> |
|
||||||
* <p> |
|
||||||
* 字段说明: |
|
||||||
* code:网关异常码 <br> |
|
||||||
* msg:网关异常信息 <br> |
|
||||||
* sub_code:业务异常码 <br> |
|
||||||
* sub_msg:业务异常信息 <br> |
|
||||||
* |
|
||||||
* @author tanghc |
|
||||||
*/ |
|
||||||
@Data |
|
||||||
public class ApiResult { |
|
||||||
|
|
||||||
/** |
|
||||||
* 网关异常信息 |
|
||||||
*/ |
|
||||||
private String msg; |
|
||||||
|
|
||||||
/** |
|
||||||
* 业务异常码 |
|
||||||
*/ |
|
||||||
private String sub_msg; |
|
||||||
|
|
||||||
/** |
|
||||||
* 业务异常信息 |
|
||||||
*/ |
|
||||||
private String sub_code; |
|
||||||
|
|
||||||
/** |
|
||||||
* 返回结果 |
|
||||||
*/ |
|
||||||
private Object data; |
|
||||||
} |
|
@ -1,73 +0,0 @@ |
|||||||
package com.gitee.sop.bookweb.controller; |
|
||||||
|
|
||||||
import com.gitee.book.api.domain.Book; |
|
||||||
import com.gitee.sop.bookweb.consumer.StoryServiceConsumer; |
|
||||||
import com.gitee.sop.bookweb.param.BookParam; |
|
||||||
import com.gitee.sop.story.api.domain.Story; |
|
||||||
import com.gitee.book.api.service.BookService; |
|
||||||
import org.springframework.beans.factory.annotation.Autowired; |
|
||||||
import org.springframework.web.bind.annotation.RequestBody; |
|
||||||
import org.springframework.web.bind.annotation.RequestMapping; |
|
||||||
import org.springframework.web.bind.annotation.RestController; |
|
||||||
|
|
||||||
import java.util.Arrays; |
|
||||||
|
|
||||||
/** |
|
||||||
* book服务 |
|
||||||
* |
|
||||||
* @author tanghc |
|
||||||
*/ |
|
||||||
@RestController |
|
||||||
public class BookController implements BookService { |
|
||||||
|
|
||||||
@Autowired |
|
||||||
StoryServiceConsumer storyServiceConsumer; |
|
||||||
|
|
||||||
@Override |
|
||||||
public Book getBook(int id) { |
|
||||||
Book book = new Book(); |
|
||||||
book.setId(id); |
|
||||||
book.setName("汪汪队"); |
|
||||||
return book; |
|
||||||
} |
|
||||||
|
|
||||||
@RequestMapping("listBookAndStory") |
|
||||||
public Object listBookAndStory(int id) { |
|
||||||
Book book = new Book(); |
|
||||||
book.setId(id); |
|
||||||
book.setName("汪汪队"); |
|
||||||
|
|
||||||
// 调用story服务
|
|
||||||
Story story = storyServiceConsumer.getStory(id); |
|
||||||
|
|
||||||
return Arrays.asList(book, story); |
|
||||||
} |
|
||||||
|
|
||||||
@RequestMapping("getBook2") |
|
||||||
public Object getBookError(int id) { |
|
||||||
if (id == 0) { |
|
||||||
throw new RuntimeException("id不能为空"); |
|
||||||
} |
|
||||||
Book book = new Book(); |
|
||||||
book.setId(id); |
|
||||||
book.setName("汪汪队"); |
|
||||||
return Arrays.asList(book); |
|
||||||
} |
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@RequestMapping("getBook3") |
|
||||||
public Object getBook3(@RequestBody BookParam param) { |
|
||||||
if (param.getId() == 0) { |
|
||||||
throw new RuntimeException("id不能为空"); |
|
||||||
} |
|
||||||
Book book = new Book(); |
|
||||||
book.setId(param.getId()); |
|
||||||
book.setName("小马宝莉"); |
|
||||||
|
|
||||||
ApiResult apiResult = new ApiResult(); |
|
||||||
apiResult.setData(book); |
|
||||||
return apiResult; |
|
||||||
} |
|
||||||
|
|
||||||
} |
|
@ -1,40 +0,0 @@ |
|||||||
package com.gitee.sop.bookweb.controller; |
|
||||||
|
|
||||||
import com.alibaba.dubbo.config.annotation.Reference; |
|
||||||
import com.gitee.sop.servercommon.annotation.ApiMapping; |
|
||||||
import com.gitee.sop.story.api.domain.Story; |
|
||||||
import com.gitee.sop.story.api.param.DemoParam; |
|
||||||
import com.gitee.sop.story.api.result.DemoResult; |
|
||||||
import com.gitee.sop.story.api.service.DemoService; |
|
||||||
import lombok.extern.slf4j.Slf4j; |
|
||||||
import org.springframework.web.bind.annotation.RestController; |
|
||||||
|
|
||||||
/** |
|
||||||
* 调用dubbo服务,provider是story,见DefaultDemoService.java |
|
||||||
* dubbo配置方式参见:https://github.com/apache/dubbo-spring-boot-project/blob/0.2.x/README_CN.md
|
|
||||||
* <p> |
|
||||||
* 对比SpringCloud提供的Feign,dubbo会方便很多。 |
|
||||||
* <p> |
|
||||||
* Feign的使用方式参见:com.gitee.sop.bookweb.controller.AlipayBookController#getBook2() |
|
||||||
*/ |
|
||||||
@RestController |
|
||||||
@Slf4j |
|
||||||
public class DubboConsumerController { |
|
||||||
|
|
||||||
@Reference(version = "1.0.0", url = "dubbo://127.0.0.1:12345") |
|
||||||
private DemoService demoService; |
|
||||||
|
|
||||||
// 作为开放接口
|
|
||||||
@ApiMapping(value = "dubbo.story.get") |
|
||||||
public Story openApi(DemoParam demoParam) { |
|
||||||
log.info("dubbo consumer, param: {}", demoParam); |
|
||||||
// 通过dubbo调用story提供的服务
|
|
||||||
DemoResult dubboStory = demoService.getStory(demoParam); |
|
||||||
Story story = new Story(); |
|
||||||
story.setId(dubboStory.getId()); |
|
||||||
story.setName(dubboStory.getName()); |
|
||||||
return story; |
|
||||||
} |
|
||||||
|
|
||||||
|
|
||||||
} |
|
@ -1,16 +0,0 @@ |
|||||||
package com.gitee.sop.bookweb.param; |
|
||||||
|
|
||||||
import io.swagger.annotations.ApiModelProperty; |
|
||||||
import lombok.Data; |
|
||||||
|
|
||||||
/** |
|
||||||
* @author tanghc |
|
||||||
*/ |
|
||||||
@Data |
|
||||||
public class BookParam { |
|
||||||
@ApiModelProperty(value = "图书id", example = "1") |
|
||||||
private int id; |
|
||||||
|
|
||||||
@ApiModelProperty(value = "图书ISBN", example = "xxxx") |
|
||||||
private String isbn; |
|
||||||
} |
|
@ -1,16 +0,0 @@ |
|||||||
package com.gitee.sop.bookweb.vo; |
|
||||||
|
|
||||||
import io.swagger.annotations.ApiModelProperty; |
|
||||||
import lombok.Data; |
|
||||||
|
|
||||||
@Data |
|
||||||
public class BookVO { |
|
||||||
@ApiModelProperty(value = "图书id", example = "1") |
|
||||||
private int id; |
|
||||||
|
|
||||||
@ApiModelProperty(value = "图书名称", example = "白雪公主") |
|
||||||
private String name; |
|
||||||
|
|
||||||
@ApiModelProperty(value = "isbn", example = "xxxxxx") |
|
||||||
private String isbn; |
|
||||||
} |
|
@ -1,19 +0,0 @@ |
|||||||
server.port=3333 |
|
||||||
spring.application.name=book-service |
|
||||||
|
|
||||||
# nacos注册中心 |
|
||||||
#spring.cloud.nacos.discovery.server-addr=127.0.0.1:8848 |
|
||||||
|
|
||||||
# eureka注册中心 |
|
||||||
eureka.client.serviceUrl.defaultZone=http://localhost:1111/eureka/ |
|
||||||
|
|
||||||
# consumer不需要检查provider是否启动 |
|
||||||
dubbo.consumer.check=false |
|
||||||
|
|
||||||
# zipkin服务跟踪 |
|
||||||
#spring.zipkin.base-url=http://127.0.0.1:9411/ |
|
||||||
## 设置sleuth收集信息的比率,默认0.1,最大是1,数字越大越耗性能 |
|
||||||
#spring.sleuth.sampler.probability=1 |
|
||||||
## dubbo使用zipkin过滤器 |
|
||||||
#dubbo.provider.filter=tracing |
|
||||||
#dubbo.consumer.filter=tracing |
|
@ -1,17 +0,0 @@ |
|||||||
package com.gitee.sop.bookweb; |
|
||||||
|
|
||||||
import org.junit.Test; |
|
||||||
import org.junit.runner.RunWith; |
|
||||||
import org.springframework.boot.test.context.SpringBootTest; |
|
||||||
import org.springframework.test.context.junit4.SpringRunner; |
|
||||||
|
|
||||||
@RunWith(SpringRunner.class) |
|
||||||
@SpringBootTest |
|
||||||
public class SopBookApplicationTests { |
|
||||||
|
|
||||||
@Test |
|
||||||
public void contextLoads() { |
|
||||||
} |
|
||||||
|
|
||||||
} |
|
||||||
|
|
@ -1,25 +0,0 @@ |
|||||||
target/ |
|
||||||
!.mvn/wrapper/maven-wrapper.jar |
|
||||||
|
|
||||||
### STS ### |
|
||||||
.apt_generated |
|
||||||
.classpath |
|
||||||
.factorypath |
|
||||||
.project |
|
||||||
.settings |
|
||||||
.springBeans |
|
||||||
|
|
||||||
### IntelliJ IDEA ### |
|
||||||
.idea |
|
||||||
*.iws |
|
||||||
*.iml |
|
||||||
*.ipr |
|
||||||
|
|
||||||
### NetBeans ### |
|
||||||
nbproject/private/ |
|
||||||
build/ |
|
||||||
nbbuild/ |
|
||||||
dist/ |
|
||||||
nbdist/ |
|
||||||
.nb-gradle/ |
|
||||||
/local-config/ |
|
@ -1,132 +0,0 @@ |
|||||||
<?xml version="1.0" encoding="UTF-8"?> |
|
||||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" |
|
||||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> |
|
||||||
<modelVersion>4.0.0</modelVersion> |
|
||||||
<groupId>com.gitee.sop</groupId> |
|
||||||
<artifactId>sop-easyopen</artifactId> |
|
||||||
<version>1.0.0-SNAPSHOT</version> |
|
||||||
<packaging>jar</packaging> |
|
||||||
|
|
||||||
<name>easyopen-server</name> |
|
||||||
<description>easyopen Demo project for Spring Boot</description> |
|
||||||
|
|
||||||
<parent> |
|
||||||
<groupId>org.springframework.boot</groupId> |
|
||||||
<artifactId>spring-boot-starter-parent</artifactId> |
|
||||||
<version>2.1.2.RELEASE</version> |
|
||||||
<relativePath /> <!-- lookup parent from repository --> |
|
||||||
</parent> |
|
||||||
|
|
||||||
<properties> |
|
||||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> |
|
||||||
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding> |
|
||||||
<spring-cloud.version>Greenwich.RELEASE</spring-cloud.version> |
|
||||||
<java.version>1.8</java.version> |
|
||||||
</properties> |
|
||||||
|
|
||||||
<dependencies> |
|
||||||
<!-- sop接入依赖 --> |
|
||||||
<dependency> |
|
||||||
<groupId>com.gitee.sop</groupId> |
|
||||||
<artifactId>sop-service-common</artifactId> |
|
||||||
<version>3.1.5-SNAPSHOT</version> |
|
||||||
</dependency> |
|
||||||
|
|
||||||
<!-- 使用nacos注册中心 |
|
||||||
版本 0.2.x.RELEASE 对应的是 Spring Boot 2.x 版本,版本 0.1.x.RELEASE 对应的是 Spring Boot 1.x 版本。 |
|
||||||
https://mvnrepository.com/artifact/org.springframework.cloud/spring-cloud-starter-alibaba-nacos-discovery |
|
||||||
|
|
||||||
<dependency> |
|
||||||
<groupId>org.springframework.cloud</groupId> |
|
||||||
<artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId> |
|
||||||
<version>0.2.2.RELEASE</version> |
|
||||||
<exclusions> |
|
||||||
<exclusion> |
|
||||||
<groupId>com.alibaba.nacos</groupId> |
|
||||||
<artifactId>nacos-client</artifactId> |
|
||||||
</exclusion> |
|
||||||
</exclusions> |
|
||||||
</dependency> |
|
||||||
<dependency> |
|
||||||
<groupId>com.alibaba.nacos</groupId> |
|
||||||
<artifactId>nacos-client</artifactId> |
|
||||||
<version>1.1.0</version> |
|
||||||
</dependency> |
|
||||||
--> |
|
||||||
|
|
||||||
<dependency> |
|
||||||
<groupId>org.springframework.cloud</groupId> |
|
||||||
<artifactId>spring-cloud-starter-netflix-eureka-client</artifactId> |
|
||||||
</dependency> |
|
||||||
|
|
||||||
<dependency> |
|
||||||
<groupId>net.oschina.durcframework</groupId> |
|
||||||
<artifactId>easyopen</artifactId> |
|
||||||
<version>1.16.8</version> |
|
||||||
</dependency> |
|
||||||
<!-- sop接入依赖 end --> |
|
||||||
|
|
||||||
<dependency> |
|
||||||
<groupId>org.springframework.boot</groupId> |
|
||||||
<artifactId>spring-boot-starter-web</artifactId> |
|
||||||
</dependency> |
|
||||||
<dependency> |
|
||||||
<groupId>org.springframework.boot</groupId> |
|
||||||
<artifactId>spring-boot-starter-thymeleaf</artifactId> |
|
||||||
</dependency> |
|
||||||
|
|
||||||
<dependency> |
|
||||||
<groupId>org.springframework.boot</groupId> |
|
||||||
<artifactId>spring-boot-starter-data-redis</artifactId> |
|
||||||
</dependency> |
|
||||||
|
|
||||||
<dependency> |
|
||||||
<groupId>org.springframework.boot</groupId> |
|
||||||
<artifactId>spring-boot-configuration-processor</artifactId> |
|
||||||
<optional>true</optional> |
|
||||||
</dependency> |
|
||||||
<dependency> |
|
||||||
<groupId>org.springframework.boot</groupId> |
|
||||||
<artifactId>spring-boot-devtools</artifactId> |
|
||||||
<optional>true</optional> |
|
||||||
</dependency> |
|
||||||
|
|
||||||
<dependency> |
|
||||||
<groupId>org.springframework.boot</groupId> |
|
||||||
<artifactId>spring-boot-starter-test</artifactId> |
|
||||||
<scope>test</scope> |
|
||||||
</dependency> |
|
||||||
|
|
||||||
</dependencies> |
|
||||||
|
|
||||||
<dependencyManagement> |
|
||||||
<dependencies> |
|
||||||
<dependency> |
|
||||||
<groupId>org.springframework.cloud</groupId> |
|
||||||
<artifactId>spring-cloud-dependencies</artifactId> |
|
||||||
<version>${spring-cloud.version}</version> |
|
||||||
<type>pom</type> |
|
||||||
<scope>import</scope> |
|
||||||
</dependency> |
|
||||||
</dependencies> |
|
||||||
</dependencyManagement> |
|
||||||
|
|
||||||
<build> |
|
||||||
<plugins> |
|
||||||
<plugin> |
|
||||||
<groupId>org.springframework.boot</groupId> |
|
||||||
<artifactId>spring-boot-maven-plugin</artifactId> |
|
||||||
</plugin> |
|
||||||
<!-- 打包时跳过测试 --> |
|
||||||
<plugin> |
|
||||||
<groupId>org.apache.maven.plugins</groupId> |
|
||||||
<artifactId>maven-surefire-plugin</artifactId> |
|
||||||
<configuration> |
|
||||||
<skipTests>true</skipTests> |
|
||||||
</configuration> |
|
||||||
</plugin> |
|
||||||
</plugins> |
|
||||||
</build> |
|
||||||
|
|
||||||
|
|
||||||
</project> |
|
@ -1,31 +0,0 @@ |
|||||||
# easyopen-server |
|
||||||
|
|
||||||
接口服务器空项目,可在此基础上做开发。 |
|
||||||
|
|
||||||
入口类:IndexController |
|
||||||
|
|
||||||
业务类在api下,重点关注这里即可。 |
|
||||||
|
|
||||||
``` |
|
||||||
└─com.gitee.easyopen.server |
|
||||||
│ EmptySpringbootApplication.java // springboot启动类 |
|
||||||
│ IndexController.java // easyopen入口类 |
|
||||||
│ |
|
||||||
├─api // 存放接口 |
|
||||||
│ │ GoodsApi.java // 示例接口 |
|
||||||
│ │ |
|
||||||
│ ├─param // 存放接口参数类 |
|
||||||
│ │ GoodsParam.java |
|
||||||
│ │ |
|
||||||
│ └─result // 存放放回接口类 |
|
||||||
│ Goods.java |
|
||||||
│ |
|
||||||
├─config // spring配置 |
|
||||||
│ CorsConfig.java |
|
||||||
│ |
|
||||||
├─interceptor // easyopen拦截器 |
|
||||||
│ LogInterceptor.java |
|
||||||
│ |
|
||||||
└─message // 错误处理 |
|
||||||
CommonErrors.java |
|
||||||
``` |
|
@ -1,25 +0,0 @@ |
|||||||
package com.gitee.easyopen.server; |
|
||||||
|
|
||||||
import com.gitee.easyopen.ApiConfig; |
|
||||||
import com.gitee.easyopen.support.ApiController; |
|
||||||
import org.springframework.stereotype.Controller; |
|
||||||
import org.springframework.web.bind.annotation.RequestMapping; |
|
||||||
|
|
||||||
import java.util.HashMap; |
|
||||||
import java.util.Map; |
|
||||||
|
|
||||||
/** |
|
||||||
* 文档地址:http://localhost:8080/api/doc
|
|
||||||
*/ |
|
||||||
@Controller |
|
||||||
@RequestMapping("api") |
|
||||||
public class IndexController extends ApiController { |
|
||||||
@Override |
|
||||||
protected void initApiConfig(ApiConfig apiConfig) { |
|
||||||
apiConfig.setShowDoc(true); // 显示文档页面
|
|
||||||
// 配置国际化消息
|
|
||||||
Map<String, String> appSecretStore = new HashMap<String, String>(); |
|
||||||
appSecretStore.put("test", "123456"); |
|
||||||
apiConfig.addAppSecret(appSecretStore); |
|
||||||
} |
|
||||||
} |
|
@ -1,14 +0,0 @@ |
|||||||
package com.gitee.easyopen.server; |
|
||||||
|
|
||||||
import org.springframework.boot.SpringApplication; |
|
||||||
import org.springframework.boot.autoconfigure.SpringBootApplication; |
|
||||||
import org.springframework.cloud.client.discovery.EnableDiscoveryClient; |
|
||||||
|
|
||||||
@EnableDiscoveryClient |
|
||||||
@SpringBootApplication |
|
||||||
public class SopEasyopenApplication { |
|
||||||
|
|
||||||
public static void main(String[] args) { |
|
||||||
SpringApplication.run(SopEasyopenApplication.class, args); |
|
||||||
} |
|
||||||
} |
|
@ -1,31 +0,0 @@ |
|||||||
package com.gitee.easyopen.server.api; |
|
||||||
|
|
||||||
import com.gitee.easyopen.annotation.Api; |
|
||||||
import com.gitee.easyopen.annotation.ApiService; |
|
||||||
import com.gitee.easyopen.doc.annotation.ApiDoc; |
|
||||||
import com.gitee.easyopen.doc.annotation.ApiDocMethod; |
|
||||||
import com.gitee.easyopen.server.api.param.GoodsParam; |
|
||||||
import com.gitee.easyopen.server.api.result.Goods; |
|
||||||
|
|
||||||
import java.math.BigDecimal; |
|
||||||
|
|
||||||
/** |
|
||||||
* 业务类 |
|
||||||
* |
|
||||||
* @author tanghc |
|
||||||
*/ |
|
||||||
@ApiService |
|
||||||
@ApiDoc("库存接口") |
|
||||||
public class Goods2Api { |
|
||||||
|
|
||||||
@Api(name = "store.get") |
|
||||||
@ApiDocMethod(description = "获取库存") |
|
||||||
Goods getGoods(GoodsParam param) { |
|
||||||
Goods goods = new Goods(); |
|
||||||
goods.setId(1L); |
|
||||||
goods.setGoods_name("苹果iPhoneX"); |
|
||||||
goods.setPrice(new BigDecimal(8000)); |
|
||||||
return goods; |
|
||||||
} |
|
||||||
|
|
||||||
} |
|
@ -1,31 +0,0 @@ |
|||||||
package com.gitee.easyopen.server.api; |
|
||||||
|
|
||||||
import com.gitee.easyopen.annotation.Api; |
|
||||||
import com.gitee.easyopen.annotation.ApiService; |
|
||||||
import com.gitee.easyopen.doc.annotation.ApiDoc; |
|
||||||
import com.gitee.easyopen.doc.annotation.ApiDocMethod; |
|
||||||
import com.gitee.easyopen.server.api.param.GoodsParam; |
|
||||||
import com.gitee.easyopen.server.api.result.Goods; |
|
||||||
|
|
||||||
import java.math.BigDecimal; |
|
||||||
|
|
||||||
/** |
|
||||||
* 业务类 |
|
||||||
* |
|
||||||
* @author tanghc |
|
||||||
*/ |
|
||||||
@ApiService |
|
||||||
@ApiDoc("商品接口") |
|
||||||
public class GoodsApi { |
|
||||||
|
|
||||||
@Api(name = "easyopen.goods.get") |
|
||||||
@ApiDocMethod(description = "获取商品") |
|
||||||
Goods getGoods(GoodsParam param) { |
|
||||||
Goods goods = new Goods(); |
|
||||||
goods.setId(1L); |
|
||||||
goods.setGoods_name("苹果iPhoneX"); |
|
||||||
goods.setPrice(new BigDecimal(8000)); |
|
||||||
return goods; |
|
||||||
} |
|
||||||
|
|
||||||
} |
|
@ -1,23 +0,0 @@ |
|||||||
package com.gitee.easyopen.server.api.param; |
|
||||||
|
|
||||||
import com.gitee.easyopen.doc.annotation.ApiDocField; |
|
||||||
import org.hibernate.validator.constraints.Length; |
|
||||||
|
|
||||||
import javax.validation.constraints.NotEmpty; |
|
||||||
|
|
||||||
public class GoodsParam { |
|
||||||
|
|
||||||
@ApiDocField(description = "商品名称", required = true, example = "iphoneX") |
|
||||||
@NotEmpty(message = "商品名称不能为空") |
|
||||||
@Length(min = 3, max = 20, message = "{goods.name.length}=3,20") |
|
||||||
private String goods_name; |
|
||||||
|
|
||||||
public String getGoods_name() { |
|
||||||
return goods_name; |
|
||||||
} |
|
||||||
|
|
||||||
public void setGoods_name(String goods_name) { |
|
||||||
this.goods_name = goods_name; |
|
||||||
} |
|
||||||
|
|
||||||
} |
|
@ -1,46 +0,0 @@ |
|||||||
package com.gitee.easyopen.server.api.result; |
|
||||||
|
|
||||||
import com.gitee.easyopen.doc.DataType; |
|
||||||
import com.gitee.easyopen.doc.annotation.ApiDocField; |
|
||||||
|
|
||||||
import java.math.BigDecimal; |
|
||||||
|
|
||||||
public class Goods { |
|
||||||
|
|
||||||
@ApiDocField(description = "id") |
|
||||||
private Long id; |
|
||||||
@ApiDocField(description = "商品名称") |
|
||||||
private String goods_name; |
|
||||||
@ApiDocField(description = "价格", dataType = DataType.FLOAT) |
|
||||||
private BigDecimal price; |
|
||||||
|
|
||||||
public Long getId() { |
|
||||||
return id; |
|
||||||
} |
|
||||||
|
|
||||||
public void setId(Long id) { |
|
||||||
this.id = id; |
|
||||||
} |
|
||||||
|
|
||||||
public String getGoods_name() { |
|
||||||
return goods_name; |
|
||||||
} |
|
||||||
|
|
||||||
public void setGoods_name(String goods_name) { |
|
||||||
this.goods_name = goods_name; |
|
||||||
} |
|
||||||
|
|
||||||
public BigDecimal getPrice() { |
|
||||||
return price; |
|
||||||
} |
|
||||||
|
|
||||||
public void setPrice(BigDecimal price) { |
|
||||||
this.price = price; |
|
||||||
} |
|
||||||
|
|
||||||
@Override |
|
||||||
public String toString() { |
|
||||||
return "Goods [id=" + id + ", goods_name=" + goods_name + ", price=" + price + "]"; |
|
||||||
} |
|
||||||
|
|
||||||
} |
|
@ -1,37 +0,0 @@ |
|||||||
package com.gitee.easyopen.server.config; |
|
||||||
|
|
||||||
import org.springframework.context.annotation.Bean; |
|
||||||
import org.springframework.context.annotation.Configuration; |
|
||||||
import org.springframework.web.cors.CorsConfiguration; |
|
||||||
import org.springframework.web.cors.UrlBasedCorsConfigurationSource; |
|
||||||
import org.springframework.web.filter.CorsFilter; |
|
||||||
|
|
||||||
/** |
|
||||||
* 解决js跨域 |
|
||||||
* @author tanghc |
|
||||||
*/ |
|
||||||
@Configuration |
|
||||||
public class CorsConfig { |
|
||||||
|
|
||||||
/** |
|
||||||
* 跨域过滤器 |
|
||||||
* |
|
||||||
* @return |
|
||||||
*/ |
|
||||||
@Bean |
|
||||||
public CorsFilter corsFilter() { |
|
||||||
UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource(); |
|
||||||
source.registerCorsConfiguration("/**", buildConfig()); // 4
|
|
||||||
return new CorsFilter(source); |
|
||||||
} |
|
||||||
|
|
||||||
private CorsConfiguration buildConfig() { |
|
||||||
CorsConfiguration corsConfiguration = new CorsConfiguration(); |
|
||||||
corsConfiguration.addAllowedOrigin("*"); |
|
||||||
corsConfiguration.addAllowedHeader("*"); |
|
||||||
corsConfiguration.addAllowedMethod("*"); |
|
||||||
return corsConfiguration; |
|
||||||
} |
|
||||||
|
|
||||||
|
|
||||||
} |
|
@ -1,28 +0,0 @@ |
|||||||
package com.gitee.easyopen.server.config; |
|
||||||
|
|
||||||
import com.gitee.sop.servercommon.configuration.EasyopenDocSupportController; |
|
||||||
import com.gitee.sop.servercommon.easyopen.EasyopenServiceConfiguration; |
|
||||||
import org.springframework.context.annotation.Configuration; |
|
||||||
import org.springframework.stereotype.Controller; |
|
||||||
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry; |
|
||||||
|
|
||||||
/** |
|
||||||
* @author tanghc |
|
||||||
*/ |
|
||||||
@Configuration |
|
||||||
public class SopConfig extends EasyopenServiceConfiguration { |
|
||||||
|
|
||||||
@Controller |
|
||||||
public static class SopDocController extends EasyopenDocSupportController { |
|
||||||
@Override |
|
||||||
public String getDocTitle() { |
|
||||||
return "商品API"; |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
@Override |
|
||||||
public void addResourceHandlers(ResourceHandlerRegistry registry) { |
|
||||||
//配置映射关系
|
|
||||||
registry.addResourceHandler("/opendoc/**").addResourceLocations("classpath:/META-INF/resources/opendoc/"); |
|
||||||
} |
|
||||||
} |
|
@ -1,23 +0,0 @@ |
|||||||
package com.gitee.easyopen.server.interceptor; |
|
||||||
|
|
||||||
import com.gitee.easyopen.ApiContext; |
|
||||||
import com.gitee.easyopen.interceptor.ApiInterceptorAdapter; |
|
||||||
import com.gitee.easyopen.util.RequestUtil; |
|
||||||
import org.slf4j.Logger; |
|
||||||
import org.slf4j.LoggerFactory; |
|
||||||
|
|
||||||
import javax.servlet.http.HttpServletRequest; |
|
||||||
import javax.servlet.http.HttpServletResponse; |
|
||||||
import java.net.URLDecoder; |
|
||||||
|
|
||||||
public class LogInterceptor extends ApiInterceptorAdapter { |
|
||||||
|
|
||||||
Logger logger = LoggerFactory.getLogger(getClass()); |
|
||||||
|
|
||||||
@Override |
|
||||||
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object serviceObj, Object argu) |
|
||||||
throws Exception { |
|
||||||
logger.info("收到客户端请求,ip={},参数={}", RequestUtil.getClientIP(request), URLDecoder.decode(ApiContext.getApiParam().toJSONString(), "UTF-8")); |
|
||||||
return true; |
|
||||||
} |
|
||||||
} |
|
@ -1,16 +0,0 @@ |
|||||||
package com.gitee.easyopen.server.message; |
|
||||||
|
|
||||||
import com.gitee.easyopen.message.ErrorMeta; |
|
||||||
|
|
||||||
/** |
|
||||||
* 错误码放在这里 |
|
||||||
* |
|
||||||
* 使用方式:throw CommonErrors.NUll_ERROR.getException(); |
|
||||||
*/ |
|
||||||
public interface CommonErrors { |
|
||||||
String isvModule = "isv.error_"; // error_zh_CN2.properties内容前缀
|
|
||||||
|
|
||||||
ErrorMeta NUll_ERROR = new ErrorMeta(isvModule, "200", "不能为空"); |
|
||||||
|
|
||||||
|
|
||||||
} |
|
@ -1,7 +0,0 @@ |
|||||||
server.port=2121 |
|
||||||
spring.application.name=easyopen-service |
|
||||||
|
|
||||||
# eureka注册中心 |
|
||||||
eureka.client.serviceUrl.defaultZone=http://localhost:1111/eureka/ |
|
||||||
|
|
||||||
easyopen.prefix-path=/api |
|
@ -1 +0,0 @@ |
|||||||
spring.profiles.active=dev |
|
@ -1,2 +0,0 @@ |
|||||||
# common errors here |
|
||||||
isv.error_200=\u4E0D\u80FD\u4E3A\u7A7A |
|
@ -1,16 +0,0 @@ |
|||||||
package com.gitee.sop.adminserver; |
|
||||||
|
|
||||||
import org.junit.Test; |
|
||||||
import org.junit.runner.RunWith; |
|
||||||
import org.springframework.boot.test.context.SpringBootTest; |
|
||||||
import org.springframework.test.context.junit4.SpringRunner; |
|
||||||
|
|
||||||
@RunWith(SpringRunner.class) |
|
||||||
@SpringBootTest |
|
||||||
public class SopEasyopenApplicationApplicationTests { |
|
||||||
|
|
||||||
@Test |
|
||||||
public void contextLoads() { |
|
||||||
} |
|
||||||
|
|
||||||
} |
|
@ -1,15 +1,93 @@ |
|||||||
<?xml version="1.0" encoding="UTF-8"?> |
<?xml version="1.0" encoding="UTF-8"?> |
||||||
<project xmlns="http://maven.apache.org/POM/4.0.0" |
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" |
||||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" |
|
||||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> |
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> |
||||||
<modelVersion>4.0.0</modelVersion> |
<parent> |
||||||
<groupId>com.gitee.sop-story</groupId> |
<groupId>com.gitee.sop</groupId> |
||||||
<artifactId>sop-story-parent</artifactId> |
<artifactId>sop-parent</artifactId> |
||||||
<version>1.0.0-SNAPSHOT</version> |
<version>1.0.0-SNAPSHOT</version> |
||||||
<packaging>pom</packaging> |
<relativePath>../../pom.xml</relativePath> <!-- lookup parent from repository --> |
||||||
|
</parent> |
||||||
|
|
||||||
|
<modelVersion>4.0.0</modelVersion> |
||||||
|
<artifactId>sop-story</artifactId> |
||||||
|
|
||||||
|
<properties> |
||||||
|
<java.version>1.8</java.version> |
||||||
|
</properties> |
||||||
|
|
||||||
|
<dependencies> |
||||||
|
<dependency> |
||||||
|
<groupId>com.gitee.sop</groupId> |
||||||
|
<artifactId>sop-service-common</artifactId> |
||||||
|
<version>3.2.0-SNAPSHOT</version> |
||||||
|
</dependency> |
||||||
|
|
||||||
|
<dependency> |
||||||
|
<groupId>org.springframework.boot</groupId> |
||||||
|
<artifactId>spring-boot-starter-web</artifactId> |
||||||
|
</dependency> |
||||||
|
|
||||||
|
<!-- 使用nacos注册中心 --> |
||||||
|
<dependency> |
||||||
|
<groupId>com.alibaba.cloud</groupId> |
||||||
|
<artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId> |
||||||
|
</dependency> |
||||||
|
<!-- 注册中心end --> |
||||||
|
|
||||||
|
<dependency> |
||||||
|
<groupId>org.springframework.cloud</groupId> |
||||||
|
<artifactId>spring-cloud-starter-openfeign</artifactId> |
||||||
|
</dependency> |
||||||
|
|
||||||
|
<!-- swagger2 --> |
||||||
|
<dependency> |
||||||
|
<groupId>io.springfox</groupId> |
||||||
|
<artifactId>springfox-swagger2</artifactId> |
||||||
|
<version>2.9.2</version> |
||||||
|
</dependency> |
||||||
|
<dependency> |
||||||
|
<groupId>com.github.xiaoymin</groupId> |
||||||
|
<artifactId>swagger-bootstrap-ui</artifactId> |
||||||
|
<version>1.9.5</version> |
||||||
|
</dependency> |
||||||
|
|
||||||
|
<dependency> |
||||||
|
<groupId>org.springframework.boot</groupId> |
||||||
|
<artifactId>spring-boot-starter-test</artifactId> |
||||||
|
<scope>test</scope> |
||||||
|
</dependency> |
||||||
|
<dependency> |
||||||
|
<groupId>org.projectlombok</groupId> |
||||||
|
<artifactId>lombok</artifactId> |
||||||
|
<version>1.18.4</version> |
||||||
|
<scope>provided</scope> |
||||||
|
</dependency> |
||||||
|
</dependencies> |
||||||
|
|
||||||
|
<build> |
||||||
|
<plugins> |
||||||
|
<!-- 打包时跳过测试 --> |
||||||
|
<plugin> |
||||||
|
<groupId>org.apache.maven.plugins</groupId> |
||||||
|
<artifactId>maven-surefire-plugin</artifactId> |
||||||
|
<version>2.12.4</version> |
||||||
|
<configuration> |
||||||
|
<skipTests>true</skipTests> |
||||||
|
</configuration> |
||||||
|
</plugin> |
||||||
|
<plugin> |
||||||
|
<groupId>org.springframework.boot</groupId> |
||||||
|
<artifactId>spring-boot-maven-plugin</artifactId> |
||||||
|
</plugin> |
||||||
|
</plugins> |
||||||
|
</build> |
||||||
|
|
||||||
|
<repositories> |
||||||
|
<repository> |
||||||
|
<id>spring-milestones</id> |
||||||
|
<name>Spring Milestones</name> |
||||||
|
<url>https://repo.spring.io/milestone</url> |
||||||
|
</repository> |
||||||
|
</repositories> |
||||||
|
|
||||||
<modules> |
|
||||||
<module>sop-story-api</module> |
|
||||||
<module>sop-story-web</module> |
|
||||||
</modules> |
|
||||||
</project> |
</project> |
@ -1,25 +0,0 @@ |
|||||||
/target/ |
|
||||||
!.mvn/wrapper/maven-wrapper.jar |
|
||||||
|
|
||||||
### 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/ |
|
@ -1,46 +0,0 @@ |
|||||||
<?xml version="1.0" encoding="UTF-8"?> |
|
||||||
<project xmlns="http://maven.apache.org/POM/4.0.0" |
|
||||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" |
|
||||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> |
|
||||||
<modelVersion>4.0.0</modelVersion> |
|
||||||
<parent> |
|
||||||
<groupId>org.springframework.boot</groupId> |
|
||||||
<artifactId>spring-boot-starter-parent</artifactId> |
|
||||||
<version>2.1.2.RELEASE</version> |
|
||||||
<relativePath/> <!-- lookup parent from repository --> |
|
||||||
</parent> |
|
||||||
<groupId>com.gitee.sop</groupId> |
|
||||||
<artifactId>sop-story-api</artifactId> |
|
||||||
<version>1.0-SNAPSHOT</version> |
|
||||||
|
|
||||||
<properties> |
|
||||||
<java.version>1.8</java.version> |
|
||||||
<spring-cloud.version>Greenwich.RELEASE</spring-cloud.version> |
|
||||||
</properties> |
|
||||||
|
|
||||||
<dependencies> |
|
||||||
<dependency> |
|
||||||
<groupId>org.springframework.boot</groupId> |
|
||||||
<artifactId>spring-boot-starter-web</artifactId> |
|
||||||
</dependency> |
|
||||||
|
|
||||||
<dependency> |
|
||||||
<groupId>org.projectlombok</groupId> |
|
||||||
<artifactId>lombok</artifactId> |
|
||||||
<version>1.18.4</version> |
|
||||||
<scope>provided</scope> |
|
||||||
</dependency> |
|
||||||
</dependencies> |
|
||||||
|
|
||||||
<dependencyManagement> |
|
||||||
<dependencies> |
|
||||||
<dependency> |
|
||||||
<groupId>org.springframework.cloud</groupId> |
|
||||||
<artifactId>spring-cloud-dependencies</artifactId> |
|
||||||
<version>${spring-cloud.version}</version> |
|
||||||
<type>pom</type> |
|
||||||
<scope>import</scope> |
|
||||||
</dependency> |
|
||||||
</dependencies> |
|
||||||
</dependencyManagement> |
|
||||||
</project> |
|
@ -1,18 +0,0 @@ |
|||||||
package com.gitee.sop.story.api.domain; |
|
||||||
|
|
||||||
import lombok.Data; |
|
||||||
import org.hibernate.validator.constraints.Length; |
|
||||||
|
|
||||||
import javax.validation.constraints.NotBlank; |
|
||||||
|
|
||||||
/** |
|
||||||
* @author tanghc |
|
||||||
*/ |
|
||||||
@Data |
|
||||||
public class Story { |
|
||||||
private int id; |
|
||||||
|
|
||||||
@NotBlank(message = "name不能为空") |
|
||||||
@Length(max = 20, message = "name长度不能超过20") |
|
||||||
private String name; |
|
||||||
} |
|
@ -1,14 +0,0 @@ |
|||||||
package com.gitee.sop.story.api.param; |
|
||||||
|
|
||||||
import lombok.Data; |
|
||||||
|
|
||||||
import java.io.Serializable; |
|
||||||
|
|
||||||
/** |
|
||||||
* dubbo 参数 |
|
||||||
* @author tanghc |
|
||||||
*/ |
|
||||||
@Data |
|
||||||
public class DemoParam implements Serializable { |
|
||||||
private int id; |
|
||||||
} |
|
@ -1,15 +0,0 @@ |
|||||||
package com.gitee.sop.story.api.result; |
|
||||||
|
|
||||||
import lombok.Data; |
|
||||||
|
|
||||||
import java.io.Serializable; |
|
||||||
|
|
||||||
/** |
|
||||||
* dubbo返回结果 |
|
||||||
* @author tanghc |
|
||||||
*/ |
|
||||||
@Data |
|
||||||
public class DemoResult implements Serializable { |
|
||||||
private int id; |
|
||||||
private String name; |
|
||||||
} |
|
@ -1,17 +0,0 @@ |
|||||||
package com.gitee.sop.story.api.service; |
|
||||||
|
|
||||||
import com.gitee.sop.story.api.param.DemoParam; |
|
||||||
import com.gitee.sop.story.api.result.DemoResult; |
|
||||||
|
|
||||||
public interface DemoService { |
|
||||||
|
|
||||||
String sayHello(String name); |
|
||||||
|
|
||||||
/** |
|
||||||
* 获取故事名称 |
|
||||||
* @param param |
|
||||||
* @return |
|
||||||
*/ |
|
||||||
DemoResult getStory(DemoParam param); |
|
||||||
|
|
||||||
} |
|
@ -1,15 +0,0 @@ |
|||||||
package com.gitee.sop.story.api.service; |
|
||||||
|
|
||||||
import com.gitee.sop.story.api.domain.Story; |
|
||||||
import org.springframework.web.bind.annotation.RequestMapping; |
|
||||||
import org.springframework.web.bind.annotation.RequestParam; |
|
||||||
|
|
||||||
/** |
|
||||||
* @author tanghc |
|
||||||
*/ |
|
||||||
@RequestMapping("/story") |
|
||||||
public interface StoryService { |
|
||||||
@RequestMapping("/getStory") |
|
||||||
Story getStory(@RequestParam("id")/* 必须指定@RequestParam,且value不能少 */ |
|
||||||
int id); |
|
||||||
} |
|
@ -1,25 +0,0 @@ |
|||||||
/target/ |
|
||||||
!.mvn/wrapper/maven-wrapper.jar |
|
||||||
|
|
||||||
### 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/ |
|
@ -1,146 +0,0 @@ |
|||||||
<?xml version="1.0" encoding="UTF-8"?> |
|
||||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" |
|
||||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> |
|
||||||
<modelVersion>4.0.0</modelVersion> |
|
||||||
<parent> |
|
||||||
<groupId>org.springframework.boot</groupId> |
|
||||||
<artifactId>spring-boot-starter-parent</artifactId> |
|
||||||
<version>2.1.2.RELEASE</version> |
|
||||||
<relativePath/> <!-- lookup parent from repository --> |
|
||||||
</parent> |
|
||||||
<groupId>com.gitee.sop</groupId> |
|
||||||
<artifactId>sop-story-web</artifactId> |
|
||||||
<version>0.0.1-SNAPSHOT</version> |
|
||||||
<name>sop-story</name> |
|
||||||
<description>Demo project for Spring Boot</description> |
|
||||||
|
|
||||||
<properties> |
|
||||||
<java.version>1.8</java.version> |
|
||||||
<dubbo.version>2.6.5</dubbo.version> |
|
||||||
<spring-cloud.version>Greenwich.RELEASE</spring-cloud.version> |
|
||||||
<!-- nacos spring cloud版本号 --> |
|
||||||
<spring-cloud-alibaba-nacos.version>0.9.0.RELEASE</spring-cloud-alibaba-nacos.version> |
|
||||||
<!-- nacos客户端版本号 --> |
|
||||||
<nacos-client.version>1.1.3</nacos-client.version> |
|
||||||
</properties> |
|
||||||
|
|
||||||
<dependencies> |
|
||||||
<dependency> |
|
||||||
<groupId>com.gitee.sop</groupId> |
|
||||||
<artifactId>sop-service-common</artifactId> |
|
||||||
<version>3.1.5-SNAPSHOT</version> |
|
||||||
</dependency> |
|
||||||
<dependency> |
|
||||||
<groupId>com.gitee.sop</groupId> |
|
||||||
<artifactId>sop-story-api</artifactId> |
|
||||||
<version>1.0-SNAPSHOT</version> |
|
||||||
</dependency> |
|
||||||
|
|
||||||
<!-- 使用nacos注册中心 |
|
||||||
版本 0.2.x.RELEASE 对应的是 Spring Boot 2.x 版本,版本 0.1.x.RELEASE 对应的是 Spring Boot 1.x 版本。 |
|
||||||
https://mvnrepository.com/artifact/org.springframework.cloud/spring-cloud-starter-alibaba-nacos-discovery |
|
||||||
|
|
||||||
<dependency> |
|
||||||
<groupId>org.springframework.cloud</groupId> |
|
||||||
<artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId> |
|
||||||
<version>${spring-cloud-alibaba-nacos.version}</version> |
|
||||||
</dependency> |
|
||||||
<dependency> |
|
||||||
<groupId>com.alibaba.nacos</groupId> |
|
||||||
<artifactId>nacos-client</artifactId> |
|
||||||
<version>${nacos-client.version}</version> |
|
||||||
</dependency> |
|
||||||
--> |
|
||||||
<!-- 注册中心end --> |
|
||||||
|
|
||||||
<dependency> |
|
||||||
<groupId>org.springframework.cloud</groupId> |
|
||||||
<artifactId>spring-cloud-starter-netflix-eureka-client</artifactId> |
|
||||||
</dependency> |
|
||||||
|
|
||||||
<dependency> |
|
||||||
<groupId>org.springframework.cloud</groupId> |
|
||||||
<artifactId>spring-cloud-starter-openfeign</artifactId> |
|
||||||
</dependency> |
|
||||||
|
|
||||||
<!-- Dubbo Spring Boot Starter --> |
|
||||||
<dependency> |
|
||||||
<groupId>com.alibaba.boot</groupId> |
|
||||||
<artifactId>dubbo-spring-boot-starter</artifactId> |
|
||||||
<version>0.2.1.RELEASE</version> |
|
||||||
</dependency> |
|
||||||
<dependency> |
|
||||||
<groupId>com.alibaba</groupId> |
|
||||||
<artifactId>dubbo</artifactId> |
|
||||||
<version>${dubbo.version}</version> |
|
||||||
</dependency> |
|
||||||
<dependency> |
|
||||||
<groupId>io.netty</groupId> |
|
||||||
<artifactId>netty-all</artifactId> |
|
||||||
</dependency> |
|
||||||
|
|
||||||
<!-- swagger2 --> |
|
||||||
<dependency> |
|
||||||
<groupId>io.springfox</groupId> |
|
||||||
<artifactId>springfox-swagger2</artifactId> |
|
||||||
<version>2.9.2</version> |
|
||||||
</dependency> |
|
||||||
<dependency> |
|
||||||
<groupId>com.github.xiaoymin</groupId> |
|
||||||
<artifactId>swagger-bootstrap-ui</artifactId> |
|
||||||
<version>1.9.5</version> |
|
||||||
</dependency> |
|
||||||
|
|
||||||
<dependency> |
|
||||||
<groupId>org.springframework.boot</groupId> |
|
||||||
<artifactId>spring-boot-starter-test</artifactId> |
|
||||||
<scope>test</scope> |
|
||||||
</dependency> |
|
||||||
<dependency> |
|
||||||
<groupId>org.projectlombok</groupId> |
|
||||||
<artifactId>lombok</artifactId> |
|
||||||
<version>1.18.4</version> |
|
||||||
<scope>provided</scope> |
|
||||||
</dependency> |
|
||||||
</dependencies> |
|
||||||
|
|
||||||
<dependencyManagement> |
|
||||||
<dependencies> |
|
||||||
<dependency> |
|
||||||
<groupId>org.springframework.cloud</groupId> |
|
||||||
<artifactId>spring-cloud-dependencies</artifactId> |
|
||||||
<version>${spring-cloud.version}</version> |
|
||||||
<type>pom</type> |
|
||||||
<scope>import</scope> |
|
||||||
</dependency> |
|
||||||
|
|
||||||
</dependencies> |
|
||||||
</dependencyManagement> |
|
||||||
|
|
||||||
<build> |
|
||||||
<plugins> |
|
||||||
<!-- 打包时跳过测试 --> |
|
||||||
<plugin> |
|
||||||
<groupId>org.apache.maven.plugins</groupId> |
|
||||||
<artifactId>maven-surefire-plugin</artifactId> |
|
||||||
<version>2.12.4</version> |
|
||||||
<configuration> |
|
||||||
<skipTests>true</skipTests> |
|
||||||
</configuration> |
|
||||||
</plugin> |
|
||||||
<plugin> |
|
||||||
<groupId>org.springframework.boot</groupId> |
|
||||||
<artifactId>spring-boot-maven-plugin</artifactId> |
|
||||||
</plugin> |
|
||||||
</plugins> |
|
||||||
</build> |
|
||||||
|
|
||||||
<repositories> |
|
||||||
<repository> |
|
||||||
<id>spring-milestones</id> |
|
||||||
<name>Spring Milestones</name> |
|
||||||
<url>https://repo.spring.io/milestone</url> |
|
||||||
</repository> |
|
||||||
</repositories> |
|
||||||
|
|
||||||
</project> |
|
@ -1,23 +0,0 @@ |
|||||||
package com.gitee.sop.storyweb.controller; |
|
||||||
|
|
||||||
import com.gitee.sop.story.api.domain.Story; |
|
||||||
import com.gitee.sop.story.api.service.StoryService; |
|
||||||
import org.springframework.web.bind.annotation.RestController; |
|
||||||
|
|
||||||
/** |
|
||||||
* @author tanghc |
|
||||||
*/ |
|
||||||
@RestController |
|
||||||
public class StoryController implements StoryService { |
|
||||||
|
|
||||||
// 提供给Feign的服务
|
|
||||||
@Override |
|
||||||
public Story getStory(int id) { |
|
||||||
Story story = new Story(); |
|
||||||
story.setId(id); |
|
||||||
story.setName("海底小纵队(Feign)"); |
|
||||||
return story; |
|
||||||
} |
|
||||||
|
|
||||||
|
|
||||||
} |
|
@ -1,21 +0,0 @@ |
|||||||
package com.gitee.sop.storyweb.controller; |
|
||||||
|
|
||||||
import com.gitee.sop.servercommon.annotation.ApiMapping; |
|
||||||
import com.gitee.sop.story.api.domain.Story; |
|
||||||
import org.springframework.web.bind.annotation.RestController; |
|
||||||
|
|
||||||
/** |
|
||||||
* @author tanghc |
|
||||||
*/ |
|
||||||
@RestController |
|
||||||
public class StoryDemoController { |
|
||||||
|
|
||||||
@ApiMapping(value = "story.demo.get") |
|
||||||
public Story getStory() { |
|
||||||
Story story = new Story(); |
|
||||||
story.setId(1); |
|
||||||
story.setName("白雪公主"); |
|
||||||
return story; |
|
||||||
} |
|
||||||
|
|
||||||
} |
|
@ -1,32 +0,0 @@ |
|||||||
package com.gitee.sop.storyweb.service; |
|
||||||
|
|
||||||
import com.alibaba.dubbo.config.annotation.Service; |
|
||||||
import com.gitee.sop.story.api.param.DemoParam; |
|
||||||
import com.gitee.sop.story.api.result.DemoResult; |
|
||||||
import com.gitee.sop.story.api.service.DemoService; |
|
||||||
import lombok.extern.slf4j.Slf4j; |
|
||||||
import org.springframework.beans.factory.annotation.Value; |
|
||||||
|
|
||||||
@Service(version = "1.0.0") |
|
||||||
@Slf4j |
|
||||||
public class DefaultDemoService implements DemoService { |
|
||||||
|
|
||||||
/** |
|
||||||
* The default value of ${dubbo.application.name} is ${spring.application.name} |
|
||||||
*/ |
|
||||||
@Value("${dubbo.application.name}") |
|
||||||
private String serviceName; |
|
||||||
|
|
||||||
public String sayHello(String name) { |
|
||||||
return String.format("[%s] : Hello, %s", serviceName, name); |
|
||||||
} |
|
||||||
|
|
||||||
@Override |
|
||||||
public DemoResult getStory(DemoParam param) { |
|
||||||
log.info("dubbo provider, param: {}", param); |
|
||||||
DemoResult demoResult = new DemoResult(); |
|
||||||
demoResult.setId(param.getId()); |
|
||||||
demoResult.setName("dubbo 白雪公主, param=" + param); |
|
||||||
return demoResult; |
|
||||||
} |
|
||||||
} |
|
@ -1 +0,0 @@ |
|||||||
spring.profiles.active=dev |
|
@ -1,7 +1,6 @@ |
|||||||
package com.gitee.sop.storyweb.controller; |
package com.gitee.sop.storyweb.controller; |
||||||
|
|
||||||
import com.gitee.sop.servercommon.annotation.ApiMapping; |
import com.gitee.sop.servercommon.annotation.ApiMapping; |
||||||
import com.gitee.sop.story.api.domain.Story; |
|
||||||
import com.gitee.sop.storyweb.controller.result.StoryResult; |
import com.gitee.sop.storyweb.controller.result.StoryResult; |
||||||
import org.springframework.web.bind.annotation.RestController; |
import org.springframework.web.bind.annotation.RestController; |
||||||
|
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in new issue