﻿<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/"><channel><title>BlogJava-paulwong-随笔分类-MICROSERVICE</title><link>http://www.blogjava.net/paulwong/category/55108.html</link><description /><language>zh-cn</language><lastBuildDate>Sun, 17 Dec 2023 12:04:15 GMT</lastBuildDate><pubDate>Sun, 17 Dec 2023 12:04:15 GMT</pubDate><ttl>60</ttl><item><title>Micro Front</title><link>http://www.blogjava.net/paulwong/archive/2023/12/14/451321.html</link><dc:creator>paulwong</dc:creator><author>paulwong</author><pubDate>Thu, 14 Dec 2023 01:58:00 GMT</pubDate><guid>http://www.blogjava.net/paulwong/archive/2023/12/14/451321.html</guid><wfw:comment>http://www.blogjava.net/paulwong/comments/451321.html</wfw:comment><comments>http://www.blogjava.net/paulwong/archive/2023/12/14/451321.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/paulwong/comments/commentRss/451321.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/paulwong/services/trackbacks/451321.html</trackback:ping><description><![CDATA[微服務很夯，那你有聽過微前端嗎？初探 Micro Frontends 程式架構<br /><a href="https://medium.com/starbugs/%E5%BE%AE%E6%9C%8D%E5%8B%99%E5%BE%88%E5%A4%AF-%E9%82%A3%E4%BD%A0%E6%9C%89%E8%81%BD%E9%81%8E%E5%BE%AE%E5%89%8D%E7%AB%AF%E5%97%8E-%E5%88%9D%E6%8E%A2-micro-frontends-%E6%9E%B6%E6%A7%8B-e0a8469be601" target="_blank">https://medium.com/starbugs/%E5%BE%AE%E6%9C%8D%E5%8B%99%E5%BE%88%E5%A4%AF-%E9%82%A3%E4%BD%A0%E6%9C%89%E8%81%BD%E9%81%8E%E5%BE%AE%E5%89%8D%E7%AB%AF%E5%97%8E-%E5%88%9D%E6%8E%A2-micro-frontends-%E6%9E%B6%E6%A7%8B-e0a8469be601</a><br /><br />一起探討 Micro Frontends 的世界<br /><a href="https://blog.techbridge.cc/2019/01/12/micro-frontends-concept/" target="_blank">https://blog.techbridge.cc/2019/01/12/micro-frontends-concept/</a><br /><br /><br />Micro&#8198;Frontends<br />extending the microservice idea to frontend development<br /><a href="https://micro-frontends.org/" target="_blank">https://micro-frontends.org/</a><br /><img src ="http://www.blogjava.net/paulwong/aggbug/451321.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/paulwong/" target="_blank">paulwong</a> 2023-12-14 09:58 <a href="http://www.blogjava.net/paulwong/archive/2023/12/14/451321.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>SPRING CLOUD CONFIG有界面的配置管理中心</title><link>http://www.blogjava.net/paulwong/archive/2021/10/07/436000.html</link><dc:creator>paulwong</dc:creator><author>paulwong</author><pubDate>Thu, 07 Oct 2021 08:55:00 GMT</pubDate><guid>http://www.blogjava.net/paulwong/archive/2021/10/07/436000.html</guid><wfw:comment>http://www.blogjava.net/paulwong/comments/436000.html</wfw:comment><comments>http://www.blogjava.net/paulwong/archive/2021/10/07/436000.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/paulwong/comments/commentRss/436000.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/paulwong/services/trackbacks/436000.html</trackback:ping><description><![CDATA[<br /><img src="https://github.com/dyc87112/spring-cloud-config-admin/raw/master/statics/images/scca-arch.png" width="600" height="597" alt="" /><br /><br /><a href="https://dyc87112.github.io/spring-cloud-config-admin/" target="_blank">https://dyc87112.github.io/spring-cloud-config-admin/</a><img src ="http://www.blogjava.net/paulwong/aggbug/436000.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/paulwong/" target="_blank">paulwong</a> 2021-10-07 16:55 <a href="http://www.blogjava.net/paulwong/archive/2021/10/07/436000.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>微服务架构设计模式</title><link>http://www.blogjava.net/paulwong/archive/2021/01/06/435766.html</link><dc:creator>paulwong</dc:creator><author>paulwong</author><pubDate>Wed, 06 Jan 2021 06:44:00 GMT</pubDate><guid>http://www.blogjava.net/paulwong/archive/2021/01/06/435766.html</guid><wfw:comment>http://www.blogjava.net/paulwong/comments/435766.html</wfw:comment><comments>http://www.blogjava.net/paulwong/archive/2021/01/06/435766.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/paulwong/comments/commentRss/435766.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/paulwong/services/trackbacks/435766.html</trackback:ping><description><![CDATA[微服务架构及设计模式<br /><a href="http://dockone.io/article/9680" target="_blank">http://dockone.io/article/9680</a><br /><br />微服务架构10个最重要的设计模式<br /><a href="https://developer.51cto.com/art/202012/635852.htm" target="_blank">https://developer.51cto.com/art/202012/635852.htm</a><br /><br />GitHub标星127K！字节内部必刷&#8220;微服务架构设计模式&#8221;<br /><a href="https://blog.csdn.net/a159357445566/article/details/110006542" target="_blank">https://blog.csdn.net/a159357445566/article/details/110006542</a><br /><br />微服务架构及其最重要的10个设计模式<br /><a href="https://www.infoq.cn/article/Kdw69bdimlX6FSGz1bg3" target="_blank">https://www.infoq.cn/article/Kdw69bdimlX6FSGz1bg3</a><br /><br />Effective Microservices: 10 Best Practices<br /><a href="https://towardsdatascience.com/effective-microservices-10-best-practices-c6e4ba0c6ee2" target="_blank">https://towardsdatascience.com/effective-microservices-10-best-practices-c6e4ba0c6ee2</a><br /><br />Microservice Architecture and its 10 Most Important Design Patterns<br /><a href="https://towardsdatascience.com/microservice-architecture-and-its-10-most-important-design-patterns-824952d7fa41" target="_blank">https://towardsdatascience.com/microservice-architecture-and-its-10-most-important-design-patterns-824952d7fa41</a><br /><br /><br /><br /><br /><img src ="http://www.blogjava.net/paulwong/aggbug/435766.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/paulwong/" target="_blank">paulwong</a> 2021-01-06 14:44 <a href="http://www.blogjava.net/paulwong/archive/2021/01/06/435766.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>基于Spring Cloud的快速开发脚手架&amp;最佳实践总结</title><link>http://www.blogjava.net/paulwong/archive/2020/10/09/435685.html</link><dc:creator>paulwong</dc:creator><author>paulwong</author><pubDate>Fri, 09 Oct 2020 02:48:00 GMT</pubDate><guid>http://www.blogjava.net/paulwong/archive/2020/10/09/435685.html</guid><wfw:comment>http://www.blogjava.net/paulwong/comments/435685.html</wfw:comment><comments>http://www.blogjava.net/paulwong/archive/2020/10/09/435685.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/paulwong/comments/commentRss/435685.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/paulwong/services/trackbacks/435685.html</trackback:ping><description><![CDATA[<table style="border-collapse: collapse; border-spacing: 0px; margin-top: 0px; margin-bottom: 16px; display: block; width: 942px; overflow: auto; word-break: initial; color: #40485b; font-family: -apple-system, BlinkMacSystemFont, &quot;Segoe UI&quot;, Helvetica, Arial, &quot;Apple Color Emoji&quot;, &quot;Segoe UI Emoji&quot;, &quot;Segoe UI Symbol&quot;, &quot;Liberation Sans&quot;, &quot;PingFang SC&quot;, &quot;Microsoft YaHei&quot;, &quot;Hiragino Sans GB&quot;, &quot;Wenquanyi Micro Hei&quot;, &quot;WenQuanYi Zen Hei&quot;, &quot;ST Heiti&quot;, SimHei, SimSun, &quot;WenQuanYi Zen Hei Sharp&quot;, sans-serif; font-size: 16px; background-color: #ffffff;">
     <tbody style="box-sizing: border-box;">
         <tr style="box-sizing: border-box; border-top: 1px solid #c6cbd1;">
             <td style="box-sizing: border-box; padding: 6px 13px; border-style: solid; border-color: #dfe2e5;">Spring Cloud</td>
             <td style="box-sizing: border-box; padding: 6px 13px; border-style: solid; border-color: #dfe2e5;">你懂的</td>
         </tr>
         <tr style="box-sizing: border-box; background-color: #f6f8fa; border-top: 1px solid #c6cbd1;">
             <td style="box-sizing: border-box; padding: 6px 13px; border-style: solid; border-color: #dfe2e5;">Keycloak</td>
             <td style="box-sizing: border-box; padding: 6px 13px; border-style: solid; border-color: #dfe2e5;">微服务认证授权</td>
         </tr>
         <tr style="box-sizing: border-box; border-top: 1px solid #c6cbd1;">
             <td style="box-sizing: border-box; padding: 6px 13px; border-style: solid; border-color: #dfe2e5;">Jenkins</td>
             <td style="box-sizing: border-box; padding: 6px 13px; border-style: solid; border-color: #dfe2e5;">持续集成</td>
         </tr>
         <tr style="box-sizing: border-box; background-color: #f6f8fa; border-top: 1px solid #c6cbd1;">
             <td style="box-sizing: border-box; padding: 6px 13px; border-style: solid; border-color: #dfe2e5;">SonarQube</td>
             <td style="box-sizing: border-box; padding: 6px 13px; border-style: solid; border-color: #dfe2e5;">代码质量控制</td>
         </tr>
     </tbody>
</table><br /><br /><a href="https://gitee.com/itmuch/spring-cloud-yes" target="_blank">https://gitee.com/itmuch/spring-cloud-yes</a><img src ="http://www.blogjava.net/paulwong/aggbug/435685.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/paulwong/" target="_blank">paulwong</a> 2020-10-09 10:48 <a href="http://www.blogjava.net/paulwong/archive/2020/10/09/435685.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Spring Cloud异步场景分布式事务怎样做？试试RocketMQ</title><link>http://www.blogjava.net/paulwong/archive/2020/07/15/435596.html</link><dc:creator>paulwong</dc:creator><author>paulwong</author><pubDate>Wed, 15 Jul 2020 02:33:00 GMT</pubDate><guid>http://www.blogjava.net/paulwong/archive/2020/07/15/435596.html</guid><wfw:comment>http://www.blogjava.net/paulwong/comments/435596.html</wfw:comment><comments>http://www.blogjava.net/paulwong/archive/2020/07/15/435596.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/paulwong/comments/commentRss/435596.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/paulwong/services/trackbacks/435596.html</trackback:ping><description><![CDATA[例如有如下场景，新增一订单，同时为此订单的用户增加积分。场景对应场景表，积分对应积分表，如果要防止订单增加成功而积分增加不成功，则要将此两种操作放在一个事务下。<br />
<br />
分布式的场景下，订单服务在一个JVM下，积分服务在另一个JVM下，两者要如何才能达到数据一致（原子）性？<br />
<br />
<a href="https://zlt2000.gitee.io/2019-09-23-rocketmq-transaction/" target="_blank"><img src="http://qiniu.zlt2000.cn/blog/20190917/F0kVQXulbJAm.png?imageslim" width="600" alt="" /><br />
https://zlt2000.gitee.io/2019-09-23-rocketmq-transaction/</a><img src ="http://www.blogjava.net/paulwong/aggbug/435596.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/paulwong/" target="_blank">paulwong</a> 2020-07-15 10:33 <a href="http://www.blogjava.net/paulwong/archive/2020/07/15/435596.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>!!zlt-microservices-platform</title><link>http://www.blogjava.net/paulwong/archive/2020/07/15/435595.html</link><dc:creator>paulwong</dc:creator><author>paulwong</author><pubDate>Wed, 15 Jul 2020 02:15:00 GMT</pubDate><guid>http://www.blogjava.net/paulwong/archive/2020/07/15/435595.html</guid><wfw:comment>http://www.blogjava.net/paulwong/comments/435595.html</wfw:comment><comments>http://www.blogjava.net/paulwong/archive/2020/07/15/435595.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/paulwong/comments/commentRss/435595.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/paulwong/services/trackbacks/435595.html</trackback:ping><description><![CDATA[<h2>1. 总体架构图</h2>
<p style="box-sizing: border-box; margin-top: 0px; margin-bottom: 16px; color: #24292e; font-family: -apple-system, BlinkMacSystemFont, &quot;Segoe UI&quot;, Helvetica, Arial, sans-serif, &quot;Apple Color Emoji&quot;, &quot;Segoe UI Emoji&quot;; font-size: 16px; background-color: #ffffff;"><a target="_blank" rel="noopener noreferrer" href="https://camo.githubusercontent.com/c0ab697230e8324302cf3967d0d0ba6756e6fc8b/68747470733a2f2f67697465652e636f6d2f7a6c74323030302f696d616765732f7261772f6d61737465722f737072696e67636c6f75642545352542452541452545362539432538442545352538412541312545362539452542362545362539452538342545352539422542452e6a7067" style="box-sizing: border-box; background-color: initial; color: #0366d6; text-decoration-line: none;"><img src="https://camo.githubusercontent.com/c0ab697230e8324302cf3967d0d0ba6756e6fc8b/68747470733a2f2f67697465652e636f6d2f7a6c74323030302f696d616765732f7261772f6d61737465722f737072696e67636c6f75642545352542452541452545362539432538442545352538412541312545362539452542362545362539452538342545352539422542452e6a7067" alt="mark" data-canonical-src="https://gitee.com/zlt2000/images/raw/master/springcloud%E5%BE%AE%E6%9C%8D%E5%8A%A1%E6%9E%B6%E6%9E%84%E5%9B%BE.jpg" style="box-sizing: initial; border-style: none; max-width: 100%;" /></a></p>
<p style="box-sizing: border-box; margin-top: 0px; margin-bottom: 16px; color: #24292e; font-family: -apple-system, BlinkMacSystemFont, &quot;Segoe UI&quot;, Helvetica, Arial, sans-serif, &quot;Apple Color Emoji&quot;, &quot;Segoe UI Emoji&quot;; font-size: 16px; background-color: #ffffff;"><br />
</p>
<h2><a id="user-content-2-功能介绍" aria-hidden="true" href="https://github.com/zlt2000/microservices-platform#2-%E5%8A%9F%E8%83%BD%E4%BB%8B%E7%BB%8D" style="box-sizing: border-box; color: #0366d6; text-decoration-line: none; float: left; padding-right: 4px; margin-left: -20px; line-height: 1;"><svg octicon-link"="" viewbox="0 0 16 16" version="1.1" width="16" height="16" aria-hidden="true"></svg></a>2. 功能介绍</h2>
<p style="box-sizing: border-box; margin-top: 0px; margin-bottom: 16px; color: #24292e; font-family: -apple-system, BlinkMacSystemFont, &quot;Segoe UI&quot;, Helvetica, Arial, sans-serif, &quot;Apple Color Emoji&quot;, &quot;Segoe UI Emoji&quot;; font-size: 16px; background-color: #ffffff;"><a target="_blank" rel="noopener noreferrer" href="https://camo.githubusercontent.com/d1eee72307400c3147abda61e069e626e5a57405/68747470733a2f2f67697465652e636f6d2f7a6c74323030302f696d616765732f7261772f6d61737465722f5a4c542d4d502545352542452541452545362539432538442545352538412541312545352542392542332545352538462542302545352538412539462545382538332542442545352539422542452e6a7067" style="box-sizing: border-box; background-color: initial; color: #0366d6; text-decoration-line: none;"><img src="https://camo.githubusercontent.com/d1eee72307400c3147abda61e069e626e5a57405/68747470733a2f2f67697465652e636f6d2f7a6c74323030302f696d616765732f7261772f6d61737465722f5a4c542d4d502545352542452541452545362539432538442545352538412541312545352542392542332545352538462542302545352538412539462545382538332542442545352539422542452e6a7067" alt="mark" data-canonical-src="https://gitee.com/zlt2000/images/raw/master/ZLT-MP%E5%BE%AE%E6%9C%8D%E5%8A%A1%E5%B9%B3%E5%8F%B0%E5%8A%9F%E8%83%BD%E5%9B%BE.jpg" style="box-sizing: initial; border-style: none; max-width: 100%;" /><br />
<br />
<br />
</a></p>
<br />
<br />
<a href="https://github.com/zlt2000/microservices-platform" target="_blank">https://github.com/zlt2000/microservices-platform</a>&nbsp;<br />
<br />
<a href="https://zlt2000.gitee.io/" target="_blank">https://zlt2000.gitee.io/</a>
<br /><br />产品文档（付费，微信登录）：<br /><a href="https://www.kancloud.cn/zlt2000/microservices-platform" target="_blank">https://www.kancloud.cn/zlt2000/microservices-platform</a><br /><br /><br /><img src ="http://www.blogjava.net/paulwong/aggbug/435595.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/paulwong/" target="_blank">paulwong</a> 2020-07-15 10:15 <a href="http://www.blogjava.net/paulwong/archive/2020/07/15/435595.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>APM资源</title><link>http://www.blogjava.net/paulwong/archive/2019/12/30/435006.html</link><dc:creator>paulwong</dc:creator><author>paulwong</author><pubDate>Mon, 30 Dec 2019 08:50:00 GMT</pubDate><guid>http://www.blogjava.net/paulwong/archive/2019/12/30/435006.html</guid><wfw:comment>http://www.blogjava.net/paulwong/comments/435006.html</wfw:comment><comments>http://www.blogjava.net/paulwong/archive/2019/12/30/435006.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/paulwong/comments/commentRss/435006.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/paulwong/services/trackbacks/435006.html</trackback:ping><description><![CDATA[Spring Boot 2 实战：使用 Spring Boot Admin 监控你的应用<br /><a href="https://my.oschina.net/10000000000/blog/3119697" target="_blank">https://my.oschina.net/10000000000/blog/3119697</a><br /><br />监控管理之Spring Boot Admin使用<br /><a href="https://my.oschina.net/xiedeshou/blog/2051625" target="_blank">https://my.oschina.net/xiedeshou/blog/2051625</a><br /><br /><br /><a href="https://my.oschina.net/janlle/blog/3040749" target="_blank">https://my.oschina.net/janlle/blog/3040749</a><img src ="http://www.blogjava.net/paulwong/aggbug/435006.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/paulwong/" target="_blank">paulwong</a> 2019-12-30 16:50 <a href="http://www.blogjava.net/paulwong/archive/2019/12/30/435006.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>微服务-网关</title><link>http://www.blogjava.net/paulwong/archive/2019/12/30/435005.html</link><dc:creator>paulwong</dc:creator><author>paulwong</author><pubDate>Mon, 30 Dec 2019 08:44:00 GMT</pubDate><guid>http://www.blogjava.net/paulwong/archive/2019/12/30/435005.html</guid><wfw:comment>http://www.blogjava.net/paulwong/comments/435005.html</wfw:comment><comments>http://www.blogjava.net/paulwong/archive/2019/12/30/435005.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/paulwong/comments/commentRss/435005.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/paulwong/services/trackbacks/435005.html</trackback:ping><description><![CDATA[微服务开源最强网关Kong<br /><a href="https://felord.cn/kong-api-gateway.html" target="_blank">https://felord.cn/kong-api-gateway.html</a><br /><br />云原生网关 Kong 和Kong 管理UI Konga的完全安装攻略<br /><a href="https://felord.cn/kong-and-konga-install.html" target="_blank">https://felord.cn/kong-and-konga-install.html</a><br /><br /><br /><br /><br /><img src ="http://www.blogjava.net/paulwong/aggbug/435005.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/paulwong/" target="_blank">paulwong</a> 2019-12-30 16:44 <a href="http://www.blogjava.net/paulwong/archive/2019/12/30/435005.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>使用Spring Cloud Security OAuth2搭建授权服务</title><link>http://www.blogjava.net/paulwong/archive/2016/09/16/431797.html</link><dc:creator>paulwong</dc:creator><author>paulwong</author><pubDate>Fri, 16 Sep 2016 10:22:00 GMT</pubDate><guid>http://www.blogjava.net/paulwong/archive/2016/09/16/431797.html</guid><wfw:comment>http://www.blogjava.net/paulwong/comments/431797.html</wfw:comment><comments>http://www.blogjava.net/paulwong/archive/2016/09/16/431797.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/paulwong/comments/commentRss/431797.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/paulwong/services/trackbacks/431797.html</trackback:ping><description><![CDATA[<p style="box-sizing: border-box; margin: 0px 0px 1.1em; padding: 0px; font-family: &quot;Microsoft YaHei&quot;; border: 0px; outline: 0px; font-size: 15px; vertical-align: baseline; color: #666666; line-height: 26px; background-image: initial; background-attachment: initial; background-size: initial; background-origin: initial; background-clip: initial; background-position: initial; background-repeat: initial;">Spring Cloud Security OAuth2 是 Spring 对 OAuth2 的开源实现，优点是能与Spring Cloud技术线无缝集成，如果全部使用默认配置，开发者只需要添加注解就能完成 OAuth2 授权服务的搭建。</p><h1>1. 添加依赖</h1><p style="box-sizing: border-box; margin: 0px 0px 1.1em; padding: 0px; font-family: &quot;Microsoft YaHei&quot;; border: 0px; outline: 0px; font-size: 15px; vertical-align: baseline; color: #666666; line-height: 26px; background-image: initial; background-attachment: initial; background-size: initial; background-origin: initial; background-clip: initial; background-position: initial; background-repeat: initial;">授权服务是基于Spring Security的，因此需要在项目中引入两个依赖：<br /></p><div style="background-color:#eeeeee;font-size:13px;border:1px solid #CCCCCC;padding-right: 5px;padding-bottom: 4px;padding-left: 4px;padding-top: 4px;width: 98%;word-break:break-all"><!--<br /><br />Code highlighting produced by Actipro CodeHighlighter (freeware)<br />http://www.CodeHighlighter.com/<br /><br />--><span style="color: #0000FF; ">&lt;</span><span style="color: #800000; ">dependency</span><span style="color: #0000FF; ">&gt;</span><br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #0000FF; ">&lt;</span><span style="color: #800000; ">groupId</span><span style="color: #0000FF; ">&gt;</span>org.springframework.cloud<span style="color: #0000FF; ">&lt;/</span><span style="color: #800000; ">groupId</span><span style="color: #0000FF; ">&gt;</span><br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #0000FF; ">&lt;</span><span style="color: #800000; ">artifactId</span><span style="color: #0000FF; ">&gt;</span>spring-cloud-starter-security<span style="color: #0000FF; ">&lt;/</span><span style="color: #800000; ">artifactId</span><span style="color: #0000FF; ">&gt;</span><br /><span style="color: #0000FF; ">&lt;/</span><span style="color: #800000; ">dependency</span><span style="color: #0000FF; ">&gt;</span><br /><br /><span style="color: #0000FF; ">&lt;</span><span style="color: #800000; ">dependency</span><span style="color: #0000FF; ">&gt;</span><br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #0000FF; ">&lt;</span><span style="color: #800000; ">groupId</span><span style="color: #0000FF; ">&gt;</span>org.springframework.cloud<span style="color: #0000FF; ">&lt;/</span><span style="color: #800000; ">groupId</span><span style="color: #0000FF; ">&gt;</span><br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #0000FF; ">&lt;</span><span style="color: #800000; ">artifactId</span><span style="color: #0000FF; ">&gt;</span>spring-cloud-starter-oauth2<span style="color: #0000FF; ">&lt;/</span><span style="color: #800000; ">artifactId</span><span style="color: #0000FF; ">&gt;</span><br />&nbsp;<span style="color: #0000FF; ">&lt;/</span><span style="color: #800000; ">dependency</span><span style="color: #0000FF; ">&gt;</span></div><p style="box-sizing: border-box; margin: 0px 0px 1.1em; padding: 0px; font-family: &quot;Microsoft YaHei&quot;; border: 0px; outline: 0px; font-size: 15px; vertical-align: baseline; color: #666666; line-height: 26px; background-image: initial; background-attachment: initial; background-size: initial; background-origin: initial; background-clip: initial; background-position: initial; background-repeat: initial;"><br /></p><p style="box-sizing: border-box; margin: 0px 0px 1.1em; padding: 0px; font-family: &quot;Microsoft YaHei&quot;; border: 0px; outline: 0px; font-size: 15px; vertical-align: baseline; color: #666666; line-height: 26px; background-image: initial; background-attachment: initial; background-size: initial; background-origin: initial; background-clip: initial; background-position: initial; background-repeat: initial;">前者为 Security，后者为Security的OAuth2扩展。</p><h1>2. 添加注解和配置</h1><p style="box-sizing: border-box; margin: 0px 0px 1.1em; padding: 0px; font-family: &quot;Microsoft YaHei&quot;; border: 0px; outline: 0px; font-size: 15px; vertical-align: baseline; color: #666666; line-height: 26px; background-image: initial; background-attachment: initial; background-size: initial; background-origin: initial; background-clip: initial; background-position: initial; background-repeat: initial;">在启动类中添加<code style="box-sizing: border-box; font-family: &quot;Source Code Pro&quot;, monospace; font-size: 13.5px; padding: 2px 4px; color: #3f3f3f; white-space: nowrap; border-radius: 0px; margin: 0px; border: 0px; outline: 0px; vertical-align: baseline; word-break: break-word; background: rgba(128, 128, 128, 0.0745098);">@EnableAuthorizationServer</code>注解：<br /></p><div style="background-color:#eeeeee;font-size:13px;border:1px solid #CCCCCC;padding-right: 5px;padding-bottom: 4px;padding-left: 4px;padding-top: 4px;width: 98%;word-break:break-all"><!--<br /><br />Code highlighting produced by Actipro CodeHighlighter (freeware)<br />http://www.CodeHighlighter.com/<br /><br />-->@SpringBootApplication<br />@EnableAuthorizationServer<br /><span style="color: #0000FF; ">public</span>&nbsp;<span style="color: #0000FF; ">class</span>&nbsp;AlanOAuthApplication&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #0000FF; ">public</span>&nbsp;<span style="color: #0000FF; ">static</span>&nbsp;<span style="color: #0000FF; ">void</span>&nbsp;main(String[]&nbsp;args)&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;SpringApplication.run(AlanOAuthApplication.<span style="color: #0000FF; ">class</span>,&nbsp;args);<br />&nbsp;&nbsp;&nbsp;&nbsp;}<br />}</div><p style="box-sizing: border-box; margin: 0px 0px 1.1em; padding: 0px; font-family: &quot;Microsoft YaHei&quot;; border: 0px; outline: 0px; font-size: 15px; vertical-align: baseline; color: #666666; line-height: 26px; background-image: initial; background-attachment: initial; background-size: initial; background-origin: initial; background-clip: initial; background-position: initial; background-repeat: initial;"><br />完成这些我们的授权服务最基本的骨架就已经搭建完成了。但是要想跑通整个流程，我们必须分配&nbsp;<code style="box-sizing: border-box; font-family: &quot;Source Code Pro&quot;, monospace; font-size: 13.5px; padding: 2px 4px; color: #3f3f3f; white-space: nowrap; border-radius: 0px; margin: 0px; border: 0px; outline: 0px; vertical-align: baseline; word-break: break-word; background: rgba(128, 128, 128, 0.0745098);">client_id</code>,&nbsp;<code style="box-sizing: border-box; font-family: &quot;Source Code Pro&quot;, monospace; font-size: 13.5px; padding: 2px 4px; color: #3f3f3f; white-space: nowrap; border-radius: 0px; margin: 0px; border: 0px; outline: 0px; vertical-align: baseline; word-break: break-word; background: rgba(128, 128, 128, 0.0745098);">client_secret</code>才行。Spring Security OAuth2的配置方法是编写<code style="box-sizing: border-box; font-family: &quot;Source Code Pro&quot;, monospace; font-size: 13.5px; padding: 2px 4px; color: #3f3f3f; white-space: nowrap; border-radius: 0px; margin: 0px; border: 0px; outline: 0px; vertical-align: baseline; word-break: break-word; background: rgba(128, 128, 128, 0.0745098);">@Configuration</code>类继承<code style="box-sizing: border-box; font-family: &quot;Source Code Pro&quot;, monospace; font-size: 13.5px; padding: 2px 4px; color: #3f3f3f; white-space: nowrap; border-radius: 0px; margin: 0px; border: 0px; outline: 0px; vertical-align: baseline; word-break: break-word; background: rgba(128, 128, 128, 0.0745098);">AuthorizationServerConfigurerAdapter</code>，然后重写<code style="box-sizing: border-box; font-family: &quot;Source Code Pro&quot;, monospace; font-size: 13.5px; padding: 2px 4px; color: #3f3f3f; white-space: nowrap; border-radius: 0px; margin: 0px; border: 0px; outline: 0px; vertical-align: baseline; word-break: break-word; background: rgba(128, 128, 128, 0.0745098);">void configure(ClientDetailsServiceConfigurer clients)</code>方法，如：<br /></p><div style="background-color:#eeeeee;font-size:13px;border:1px solid #CCCCCC;padding-right: 5px;padding-bottom: 4px;padding-left: 4px;padding-top: 4px;width: 98%;word-break:break-all"><!--<br /><br />Code highlighting produced by Actipro CodeHighlighter (freeware)<br />http://www.CodeHighlighter.com/<br /><br />-->@Override<br />&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #0000FF; ">public</span>&nbsp;<span style="color: #0000FF; ">void</span>&nbsp;configure(ClientDetailsServiceConfigurer&nbsp;clients)&nbsp;<span style="color: #0000FF; ">throws</span>&nbsp;Exception&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;clients.inMemory()&nbsp;<span style="color: #008000; ">//</span><span style="color: #008000; ">&nbsp;使用in-memory存储</span><span style="color: #008000; "><br /></span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;.withClient("client")&nbsp;<span style="color: #008000; ">//</span><span style="color: #008000; ">&nbsp;client_id</span><span style="color: #008000; "><br /></span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;.secret("secret")&nbsp;<span style="color: #008000; ">//</span><span style="color: #008000; ">&nbsp;client_secret</span><span style="color: #008000; "><br /></span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;.authorizedGrantTypes("authorization_code")&nbsp;<span style="color: #008000; ">//</span><span style="color: #008000; ">&nbsp;该client允许的授权类型</span><span style="color: #008000; "><br /></span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;.scopes("app");&nbsp;<span style="color: #008000; ">//</span><span style="color: #008000; ">&nbsp;允许的授权范围</span><span style="color: #008000; "><br /></span>&nbsp;&nbsp;&nbsp;&nbsp;}</div><p style="box-sizing: border-box; margin: 0px 0px 1.1em; padding: 0px; font-family: &quot;Microsoft YaHei&quot;; border: 0px; outline: 0px; font-size: 15px; vertical-align: baseline; color: #666666; line-height: 26px; background-image: initial; background-attachment: initial; background-size: initial; background-origin: initial; background-clip: initial; background-position: initial; background-repeat: initial;"><br /></p><h1 id="3-授权流程" style="box-sizing: border-box; margin: 0.8em 0px; font-size: 28px; font-family: &quot;Microsoft YaHei&quot;; font-weight: 100; line-height: 30px; color: #666666; padding: 0px; border: 0px; outline: 0px; vertical-align: baseline; background-image: initial; background-attachment: initial; background-size: initial; background-origin: initial; background-clip: initial; background-position: initial; background-repeat: initial;">3. 授权流程</h1><p style="box-sizing: border-box; margin: 0px 0px 1.1em; padding: 0px; font-family: &quot;Microsoft YaHei&quot;; border: 0px; outline: 0px; font-size: 15px; vertical-align: baseline; color: #666666; line-height: 26px; background-image: initial; background-attachment: initial; background-size: initial; background-origin: initial; background-clip: initial; background-position: initial; background-repeat: initial;">访问授权页面：<br /></p><div style="background-color:#eeeeee;font-size:13px;border:1px solid #CCCCCC;padding-right: 5px;padding-bottom: 4px;padding-left: 4px;padding-top: 4px;width: 98%;word-break:break-all"><!--<br /><br />Code highlighting produced by Actipro CodeHighlighter (freeware)<br />http://www.CodeHighlighter.com/<br /><br />-->localhost:8080/oauth/authorize?client_id=client&amp;response_type=code&amp;redirect_uri=http:<span style="color: #008000; ">//</span><span style="color: #008000; ">www.baidu.com</span></div><p style="box-sizing: border-box; margin: 0px 0px 1.1em; padding: 0px; font-family: &quot;Microsoft YaHei&quot;; border: 0px; outline: 0px; font-size: 15px; vertical-align: baseline; color: #666666; line-height: 26px; background-image: initial; background-attachment: initial; background-size: initial; background-origin: initial; background-clip: initial; background-position: initial; background-repeat: initial;"><br /></p><p style="box-sizing: border-box; margin: 0px 0px 1.1em; padding: 0px; font-family: &quot;Microsoft YaHei&quot;; border: 0px; outline: 0px; font-size: 15px; vertical-align: baseline; color: #666666; line-height: 26px; background-image: initial; background-attachment: initial; background-size: initial; background-origin: initial; background-clip: initial; background-position: initial; background-repeat: initial;">此时浏览器会让你输入用户名密码，这是因为 Spring Security 在默认情况下会对所有URL添加Basic Auth认证。默认的用户名为<code style="box-sizing: border-box; font-family: &quot;Source Code Pro&quot;, monospace; font-size: 13.5px; padding: 2px 4px; color: #3f3f3f; white-space: nowrap; border-radius: 0px; margin: 0px; border: 0px; outline: 0px; vertical-align: baseline; word-break: break-word; background: rgba(128, 128, 128, 0.0745098);">user</code>, 密码是随机生成的，在控制台日志中可以看到。</p><p style="box-sizing: border-box; margin: 0px 0px 1.1em; padding: 0px; font-family: &quot;Microsoft YaHei&quot;; border: 0px; outline: 0px; font-size: 15px; vertical-align: baseline; color: #666666; line-height: 26px; background-image: initial; background-attachment: initial; background-size: initial; background-origin: initial; background-clip: initial; background-position: initial; background-repeat: initial;"><img src="http://img.blog.csdn.net/20160914172241289" alt="oauth2" title="" style="box-sizing: border-box; border: 0px; vertical-align: middle; outline: 0px; margin: 0px; padding: 0px; max-width: 100%; background-image: initial; background-attachment: initial; background-size: initial; background-origin: initial; background-clip: initial; background-position: initial; background-repeat: initial;" /></p><p style="box-sizing: border-box; margin: 0px 0px 1.1em; padding: 0px; font-family: &quot;Microsoft YaHei&quot;; border: 0px; outline: 0px; font-size: 15px; vertical-align: baseline; color: #666666; line-height: 26px; background-image: initial; background-attachment: initial; background-size: initial; background-origin: initial; background-clip: initial; background-position: initial; background-repeat: initial;">画风虽然很简陋，但是基本功能都具备了。点击<code style="box-sizing: border-box; font-family: &quot;Source Code Pro&quot;, monospace; font-size: 13.5px; padding: 2px 4px; color: #3f3f3f; white-space: nowrap; border-radius: 0px; margin: 0px; border: 0px; outline: 0px; vertical-align: baseline; word-break: break-word; background: rgba(128, 128, 128, 0.0745098);">Authorize</code>后，浏览器就会重定向到百度，并带上<code style="box-sizing: border-box; font-family: &quot;Source Code Pro&quot;, monospace; font-size: 13.5px; padding: 2px 4px; color: #3f3f3f; white-space: nowrap; border-radius: 0px; margin: 0px; border: 0px; outline: 0px; vertical-align: baseline; word-break: break-word; background: rgba(128, 128, 128, 0.0745098);">code</code>参数：</p><p style="box-sizing: border-box; margin: 0px 0px 1.1em; padding: 0px; font-family: &quot;Microsoft YaHei&quot;; border: 0px; outline: 0px; font-size: 15px; vertical-align: baseline; color: #666666; line-height: 26px; background-image: initial; background-attachment: initial; background-size: initial; background-origin: initial; background-clip: initial; background-position: initial; background-repeat: initial;"><img src="http://img.blog.csdn.net/20160914172412190" alt="这里写图片描述" title="" style="box-sizing: border-box; border: 0px; vertical-align: middle; outline: 0px; margin: 0px; padding: 0px; max-width: 100%; background-image: initial; background-attachment: initial; background-size: initial; background-origin: initial; background-clip: initial; background-position: initial; background-repeat: initial;" /></p><p style="box-sizing: border-box; margin: 0px 0px 1.1em; padding: 0px; font-family: &quot;Microsoft YaHei&quot;; border: 0px; outline: 0px; font-size: 15px; vertical-align: baseline; color: #666666; line-height: 26px; background-image: initial; background-attachment: initial; background-size: initial; background-origin: initial; background-clip: initial; background-position: initial; background-repeat: initial;">拿到<code style="box-sizing: border-box; font-family: &quot;Source Code Pro&quot;, monospace; font-size: 13.5px; padding: 2px 4px; color: #3f3f3f; white-space: nowrap; border-radius: 0px; margin: 0px; border: 0px; outline: 0px; vertical-align: baseline; word-break: break-word; background: rgba(128, 128, 128, 0.0745098);">code</code>以后，就可以调用</p><pre style="box-sizing: border-box; font-family: &quot;Source Code Pro&quot;, monospace; white-space: nowrap; padding: 5px 5px 5px 60px; margin-top: 0px; margin-bottom: 1.1em; line-height: 1.45; color: #333333; word-break: break-all; word-wrap: break-word; border: 1px solid rgba(128, 128, 128, 0.0745098); border-radius: 0px; outline: 0px; vertical-align: baseline; position: relative; overflow-y: hidden; overflow-x: auto; background: rgba(128, 128, 128, 0.0470588);"><code livecodeserver=""  has-numbering"="" style="box-sizing: border-box; font-family: &quot;Source Code Pro&quot;, monospace; font-size: inherit; padding: 0px; color: inherit; white-space: pre; border-radius: 0px; margin: 0px; border: 0px; outline: 0px; vertical-align: baseline; display: block; word-break: break-word; word-wrap: normal; background: transparent;">POST/GET <span style="box-sizing: border-box; margin: 0px; padding: 0px; font-family: &quot;Microsoft YaHei&quot;; border: 0px; outline: 0px; vertical-align: baseline; color: #000088; background: transparent;">http</span>://client:secret@localhost:<span style="box-sizing: border-box; margin: 0px; padding: 0px; font-family: &quot;Microsoft YaHei&quot;; border: 0px; outline: 0px; vertical-align: baseline; color: #006666; background: transparent;">8080</span>/oauth/<span style="box-sizing: border-box; margin: 0px; padding: 0px; font-family: &quot;Microsoft YaHei&quot;; border: 0px; outline: 0px; vertical-align: baseline; color: #000088; background: transparent;">token</span></code><ul style="box-sizing: border-box; margin: 0px; padding: 6px 0px 40px; font-family: &quot;Microsoft YaHei&quot;; list-style: none; border-width: 0px 1px 0px 0px; border-right-style: solid; border-right-color: #dddddd; outline: 0px; vertical-align: baseline; position: absolute; width: 50px; top: 0px; left: 0px; text-align: right; background: #eeeeee;"><li style="box-sizing: border-box; margin: 0px; padding: 0px 5px; list-style: none; border: 0px; outline: 0px; vertical-align: baseline; background: transparent;">1</li></ul></pre><p style="box-sizing: border-box; margin: 0px 0px 1.1em; padding: 0px; font-family: &quot;Microsoft YaHei&quot;; border: 0px; outline: 0px; font-size: 15px; vertical-align: baseline; color: #666666; line-height: 26px; background-image: initial; background-attachment: initial; background-size: initial; background-origin: initial; background-clip: initial; background-position: initial; background-repeat: initial;">来换取<code style="box-sizing: border-box; font-family: &quot;Source Code Pro&quot;, monospace; font-size: 13.5px; padding: 2px 4px; color: #3f3f3f; white-space: nowrap; border-radius: 0px; margin: 0px; border: 0px; outline: 0px; vertical-align: baseline; word-break: break-word; background: rgba(128, 128, 128, 0.0745098);">access_token</code>了：<br /></p><div style="background-color:#eeeeee;font-size:13px;border:1px solid #CCCCCC;padding-right: 5px;padding-bottom: 4px;padding-left: 4px;padding-top: 4px;width: 98%;word-break:break-all"><!--<br /><br />Code highlighting produced by Actipro CodeHighlighter (freeware)<br />http://www.CodeHighlighter.com/<br /><br />-->curl&nbsp;-X&nbsp;POST&nbsp;-H&nbsp;"Cache-Control:&nbsp;no-cache"&nbsp;-H&nbsp;"Content-Type:&nbsp;application/x-www-form-urlencoded"&nbsp;-d&nbsp;'grant_type=authorization_code&amp;code=Li4NZo&amp;redirect_uri=http://www.baidu.com'&nbsp;"http://client:secret@localhost:8080/oauth/token"</div><p style="box-sizing: border-box; margin: 0px 0px 1.1em; padding: 0px; font-family: &quot;Microsoft YaHei&quot;; border: 0px; outline: 0px; font-size: 15px; vertical-align: baseline; color: #666666; line-height: 26px; background-image: initial; background-attachment: initial; background-size: initial; background-origin: initial; background-clip: initial; background-position: initial; background-repeat: initial;">返回如下：<br /></p><div style="background-color:#eeeeee;font-size:13px;border:1px solid #CCCCCC;padding-right: 5px;padding-bottom: 4px;padding-left: 4px;padding-top: 4px;width: 98%;word-break:break-all"><!--<br /><br />Code highlighting produced by Actipro CodeHighlighter (freeware)<br />http://www.CodeHighlighter.com/<br /><br />-->{<br />&nbsp;&nbsp;"access_token":&nbsp;"32a1ca28-bc7a-4147-88a1-c95abcc30556",<br />&nbsp;&nbsp;"token_type":&nbsp;"bearer",<br />&nbsp;&nbsp;"expires_in":&nbsp;2591999,<br />&nbsp;&nbsp;"scope":&nbsp;"app"<br />}</div><p style="box-sizing: border-box; margin: 0px 0px 1.1em; padding: 0px; font-family: &quot;Microsoft YaHei&quot;; border: 0px; outline: 0px; font-size: 15px; vertical-align: baseline; color: #666666; line-height: 26px; background-image: initial; background-attachment: initial; background-size: initial; background-origin: initial; background-clip: initial; background-position: initial; background-repeat: initial;">到此我们最最基本的授权服务就搭建完成了。然而，这仅仅是个demo，如果要在生产环境中使用，还需要做更多的工作。</p><h1>4. 使用MySQL存储access_token和client信息</h1><p style="box-sizing: border-box; margin: 0px 0px 1.1em; padding: 0px; font-family: &quot;Microsoft YaHei&quot;; border: 0px; outline: 0px; font-size: 15px; vertical-align: baseline; color: #666666; line-height: 26px; background-image: initial; background-attachment: initial; background-size: initial; background-origin: initial; background-clip: initial; background-position: initial; background-repeat: initial;">把授权服务器中的数据存储到数据库中并不难，因为 Spring Cloud Security OAuth 已经为我们设计好了一套Schema和对应的DAO对象。但在使用之前，我们需要先对相关的类有一定的了解。</p><h2>4.1 相关接口</h2><p style="box-sizing: border-box; margin: 0px 0px 1.1em; padding: 0px; font-family: &quot;Microsoft YaHei&quot;; border: 0px; outline: 0px; font-size: 15px; vertical-align: baseline; color: #666666; line-height: 26px; background-image: initial; background-attachment: initial; background-size: initial; background-origin: initial; background-clip: initial; background-position: initial; background-repeat: initial;">Spring Cloud Security OAuth2通过<code style="box-sizing: border-box; font-family: &quot;Source Code Pro&quot;, monospace; font-size: 13.5px; padding: 2px 4px; color: #3f3f3f; white-space: nowrap; border-radius: 0px; margin: 0px; border: 0px; outline: 0px; vertical-align: baseline; word-break: break-word; background: rgba(128, 128, 128, 0.0745098);">DefaultTokenServices</code>类来完成token生成、过期等 OAuth2 标准规定的业务逻辑，而<code style="box-sizing: border-box; font-family: &quot;Source Code Pro&quot;, monospace; font-size: 13.5px; padding: 2px 4px; color: #3f3f3f; white-space: nowrap; border-radius: 0px; margin: 0px; border: 0px; outline: 0px; vertical-align: baseline; word-break: break-word; background: rgba(128, 128, 128, 0.0745098);">DefaultTokenServices</code>又是通过<code style="box-sizing: border-box; font-family: &quot;Source Code Pro&quot;, monospace; font-size: 13.5px; padding: 2px 4px; color: #3f3f3f; white-space: nowrap; border-radius: 0px; margin: 0px; border: 0px; outline: 0px; vertical-align: baseline; word-break: break-word; background: rgba(128, 128, 128, 0.0745098);">TokenStore</code>接口完成对生成数据的持久化。在上面的demo中，<code style="box-sizing: border-box; font-family: &quot;Source Code Pro&quot;, monospace; font-size: 13.5px; padding: 2px 4px; color: #3f3f3f; white-space: nowrap; border-radius: 0px; margin: 0px; border: 0px; outline: 0px; vertical-align: baseline; word-break: break-word; background: rgba(128, 128, 128, 0.0745098);">TokenStore</code>的默认实现为<code style="box-sizing: border-box; font-family: &quot;Source Code Pro&quot;, monospace; font-size: 13.5px; padding: 2px 4px; color: #3f3f3f; white-space: nowrap; border-radius: 0px; margin: 0px; border: 0px; outline: 0px; vertical-align: baseline; word-break: break-word; background: rgba(128, 128, 128, 0.0745098);">InMemoryTokenStore</code>，即内存存储。 对于Client信息，<code style="box-sizing: border-box; font-family: &quot;Source Code Pro&quot;, monospace; font-size: 13.5px; padding: 2px 4px; color: #3f3f3f; white-space: nowrap; border-radius: 0px; margin: 0px; border: 0px; outline: 0px; vertical-align: baseline; word-break: break-word; background: rgba(128, 128, 128, 0.0745098);">ClientDetailsService</code>接口负责从存储仓库中读取数据，在上面的demo中默认使用的也是<code style="box-sizing: border-box; font-family: &quot;Source Code Pro&quot;, monospace; font-size: 13.5px; padding: 2px 4px; color: #3f3f3f; white-space: nowrap; border-radius: 0px; margin: 0px; border: 0px; outline: 0px; vertical-align: baseline; word-break: break-word; background: rgba(128, 128, 128, 0.0745098);">InMemoryClientDetialsService</code>实现类。说到这里就能看出，要想使用数据库存储，只需要提供这些接口的实现类即可。庆幸的是，框架已经为我们写好JDBC实现了，即<code style="box-sizing: border-box; font-family: &quot;Source Code Pro&quot;, monospace; font-size: 13.5px; padding: 2px 4px; color: #3f3f3f; white-space: nowrap; border-radius: 0px; margin: 0px; border: 0px; outline: 0px; vertical-align: baseline; word-break: break-word; background: rgba(128, 128, 128, 0.0745098);">JdbcTokenStore</code>和<code style="box-sizing: border-box; font-family: &quot;Source Code Pro&quot;, monospace; font-size: 13.5px; padding: 2px 4px; color: #3f3f3f; white-space: nowrap; border-radius: 0px; margin: 0px; border: 0px; outline: 0px; vertical-align: baseline; word-break: break-word; background: rgba(128, 128, 128, 0.0745098);">JdbcClientDetailsService</code>。</p><h2>4.2 建表</h2><p style="box-sizing: border-box; margin: 0px 0px 1.1em; padding: 0px; font-family: &quot;Microsoft YaHei&quot;; border: 0px; outline: 0px; font-size: 15px; vertical-align: baseline; color: #666666; line-height: 26px; background-image: initial; background-attachment: initial; background-size: initial; background-origin: initial; background-clip: initial; background-position: initial; background-repeat: initial;">要想使用这些JDBC实现，首先要建表。框架为我们提前设计好了schema, 在github上：<a href="https://github.com/spring-projects/spring-security-oauth/blob/master/spring-security-oauth2/src/test/resources/schema.sql" style="box-sizing: border-box; color: #428bca; text-decoration: none; margin: 0px; padding: 0px; outline: none; background-image: initial; background-attachment: initial; background-size: initial; background-origin: initial; background-clip: initial; background-position: initial; background-repeat: initial;">https://github.com/spring-projects/spring-security-oauth/blob/master/spring-security-oauth2/src/test/resources/schema.sql</a></p><p style="box-sizing: border-box; margin: 0px 0px 1.1em; padding: 0px; font-family: &quot;Microsoft YaHei&quot;; border: 0px; outline: 0px; font-size: 15px; vertical-align: baseline; color: #666666; line-height: 26px; background-image: initial; background-attachment: initial; background-size: initial; background-origin: initial; background-clip: initial; background-position: initial; background-repeat: initial;">在使用这套表结构之前要注意的是，对于MySQL来说，默认建表语句中主键是varchar(255)类型，在mysql中执行会报错，原因是mysql对varchar主键长度有限制。所以这里改成128即可。其次，语句中会有某些字段为<code style="box-sizing: border-box; font-family: &quot;Source Code Pro&quot;, monospace; font-size: 13.5px; padding: 2px 4px; color: #3f3f3f; white-space: nowrap; border-radius: 0px; margin: 0px; border: 0px; outline: 0px; vertical-align: baseline; word-break: break-word; background: rgba(128, 128, 128, 0.0745098);">LONGVARBINARY</code>类型，它对应mysql的<code style="box-sizing: border-box; font-family: &quot;Source Code Pro&quot;, monospace; font-size: 13.5px; padding: 2px 4px; color: #3f3f3f; white-space: nowrap; border-radius: 0px; margin: 0px; border: 0px; outline: 0px; vertical-align: baseline; word-break: break-word; background: rgba(128, 128, 128, 0.0745098);">blob</code>类型，也需要修改一下。</p><h2>4.3 配置</h2><p style="box-sizing: border-box; margin: 0px 0px 1.1em; padding: 0px; font-family: &quot;Microsoft YaHei&quot;; border: 0px; outline: 0px; font-size: 15px; vertical-align: baseline; color: #666666; line-height: 26px; background-image: initial; background-attachment: initial; background-size: initial; background-origin: initial; background-clip: initial; background-position: initial; background-repeat: initial;">数据库建好后，下一步就是配置框架使用JDBC实现。方法还是编写<code style="box-sizing: border-box; font-family: &quot;Source Code Pro&quot;, monospace; font-size: 13.5px; padding: 2px 4px; color: #3f3f3f; white-space: nowrap; border-radius: 0px; margin: 0px; border: 0px; outline: 0px; vertical-align: baseline; word-break: break-word; background: rgba(128, 128, 128, 0.0745098);">@Configuration</code>类继承<code style="box-sizing: border-box; font-family: &quot;Source Code Pro&quot;, monospace; font-size: 13.5px; padding: 2px 4px; color: #3f3f3f; white-space: nowrap; border-radius: 0px; margin: 0px; border: 0px; outline: 0px; vertical-align: baseline; word-break: break-word; background: rgba(128, 128, 128, 0.0745098);">AuthorizationServerConfigurerAdapter</code>：<br /></p><div style="background-color:#eeeeee;font-size:13px;border:1px solid #CCCCCC;padding-right: 5px;padding-bottom: 4px;padding-left: 4px;padding-top: 4px;width: 98%;word-break:break-all"><!--<br /><br />Code highlighting produced by Actipro CodeHighlighter (freeware)<br />http://www.CodeHighlighter.com/<br /><br />-->@Autowired<br />&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #0000FF; ">private</span>&nbsp;AuthenticationManager&nbsp;authenticationManager;<br /><br />&nbsp;&nbsp;&nbsp;&nbsp;@Autowired<br />&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #0000FF; ">private</span>&nbsp;DataSource&nbsp;dataSource;<br />&nbsp;&nbsp;&nbsp;&nbsp;@Bean&nbsp;<span style="color: #008000; ">//</span><span style="color: #008000; ">&nbsp;声明TokenStore实现</span><span style="color: #008000; "><br /></span>&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #0000FF; ">public</span>&nbsp;TokenStore&nbsp;tokenStore()&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #0000FF; ">return</span>&nbsp;<span style="color: #0000FF; ">new</span>&nbsp;JdbcTokenStore(dataSource);<br />&nbsp;&nbsp;&nbsp;&nbsp;}<br />&nbsp;&nbsp;&nbsp;&nbsp;@Bean&nbsp;<span style="color: #008000; ">//</span><span style="color: #008000; ">&nbsp;声明&nbsp;ClientDetails实现</span><span style="color: #008000; "><br /></span>&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #0000FF; ">public</span>&nbsp;ClientDetailsService&nbsp;clientDetails()&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #0000FF; ">return</span>&nbsp;<span style="color: #0000FF; ">new</span>&nbsp;JdbcClientDetailsService(dataSource);<br />&nbsp;&nbsp;&nbsp;&nbsp;}<br />&nbsp;&nbsp;&nbsp;&nbsp;@Override&nbsp;<span style="color: #008000; ">//</span><span style="color: #008000; ">&nbsp;配置框架应用上述实现</span><span style="color: #008000; "><br /></span>&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #0000FF; ">public</span>&nbsp;<span style="color: #0000FF; ">void</span>&nbsp;configure(AuthorizationServerEndpointsConfigurer&nbsp;endpoints)&nbsp;<span style="color: #0000FF; ">throws</span>&nbsp;Exception&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;endpoints.authenticationManager(authenticationManager);<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;endpoints.tokenStore(tokenStore());<br /><br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #008000; ">//</span><span style="color: #008000; ">&nbsp;配置TokenServices参数</span><span style="color: #008000; "><br /></span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;DefaultTokenServices&nbsp;tokenServices&nbsp;=&nbsp;<span style="color: #0000FF; ">new</span>&nbsp;DefaultTokenServices();<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;tokenServices.setTokenStore(endpoints.getTokenStore());<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;tokenServices.setSupportRefreshToken(<span style="color: #0000FF; ">false</span>);<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;tokenServices.setClientDetailsService(endpoints.getClientDetailsService());<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;tokenServices.setTokenEnhancer(endpoints.getTokenEnhancer());<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;tokenServices.setAccessTokenValiditySeconds(&nbsp;(<span style="color: #0000FF; ">int</span>)&nbsp;TimeUnit.DAYS.toSeconds(30));&nbsp;<span style="color: #008000; ">//</span><span style="color: #008000; ">&nbsp;30天</span><span style="color: #008000; "><br /></span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;endpoints.tokenServices(tokenServices);<br />&nbsp;&nbsp;&nbsp;&nbsp;}</div><p style="box-sizing: border-box; margin: 0px 0px 1.1em; padding: 0px; font-family: &quot;Microsoft YaHei&quot;; border: 0px; outline: 0px; font-size: 15px; vertical-align: baseline; color: #666666; line-height: 26px; background-image: initial; background-attachment: initial; background-size: initial; background-origin: initial; background-clip: initial; background-position: initial; background-repeat: initial;">完成这些后，框架就会将中间产生的数据写到mysql中了。<code style="box-sizing: border-box; font-family: &quot;Source Code Pro&quot;, monospace; font-size: 13.5px; padding: 2px 4px; color: #3f3f3f; white-space: nowrap; border-radius: 0px; margin: 0px; border: 0px; outline: 0px; vertical-align: baseline; word-break: break-word; background: rgba(128, 128, 128, 0.0745098);">oauth_client_details</code>是client表，可以直接在该表中添加记录来添加client:&nbsp;<br style="box-sizing: border-box;" /><img src="http://img.blog.csdn.net/20160914174747955" alt="这里写图片描述" title="" style="box-sizing: border-box; border: 0px; vertical-align: middle; outline: 0px; margin: 0px; padding: 0px; max-width: 100%; background-image: initial; background-attachment: initial; background-size: initial; background-origin: initial; background-clip: initial; background-position: initial; background-repeat: initial;" /></p><h2>4.4 需要注意的地方</h2><p style="box-sizing: border-box; margin: 0px 0px 1.1em; padding: 0px; font-family: &quot;Microsoft YaHei&quot;; border: 0px; outline: 0px; font-size: 15px; vertical-align: baseline; color: #666666; line-height: 26px; background-image: initial; background-attachment: initial; background-size: initial; background-origin: initial; background-clip: initial; background-position: initial; background-repeat: initial;">这里不得不说 Spring 设计有一个奇葩地的方。注意看<code style="box-sizing: border-box; font-family: &quot;Source Code Pro&quot;, monospace; font-size: 13.5px; padding: 2px 4px; color: #3f3f3f; white-space: nowrap; border-radius: 0px; margin: 0px; border: 0px; outline: 0px; vertical-align: baseline; word-break: break-word; background: rgba(128, 128, 128, 0.0745098);">oauth_access_token</code>表是存放访问令牌的，但是并没有直接在字段中存放token。Spring 使用<code style="box-sizing: border-box; font-family: &quot;Source Code Pro&quot;, monospace; font-size: 13.5px; padding: 2px 4px; color: #3f3f3f; white-space: nowrap; border-radius: 0px; margin: 0px; border: 0px; outline: 0px; vertical-align: baseline; word-break: break-word; background: rgba(128, 128, 128, 0.0745098);">OAuth2AccessToken</code>来抽象与令牌有关的所有属性，在写入到数据库时，<strong style="box-sizing: border-box; margin: 0px; padding: 0px; border: 0px; outline: 0px; font-size: 16px; vertical-align: baseline; background-image: initial; background-attachment: initial; background-size: initial; background-origin: initial; background-clip: initial; background-position: initial; background-repeat: initial;">Spring将该对象通过JDK自带的序列化机制序列成字节</strong>直接保存到了该表的<code style="box-sizing: border-box; font-family: &quot;Source Code Pro&quot;, monospace; font-size: 13.5px; padding: 2px 4px; color: #3f3f3f; white-space: nowrap; border-radius: 0px; margin: 0px; border: 0px; outline: 0px; vertical-align: baseline; word-break: break-word; background: rgba(128, 128, 128, 0.0745098);">token</code>字段中。也就是说，如果只看数据表你是看不出<code style="box-sizing: border-box; font-family: &quot;Source Code Pro&quot;, monospace; font-size: 13.5px; padding: 2px 4px; color: #3f3f3f; white-space: nowrap; border-radius: 0px; margin: 0px; border: 0px; outline: 0px; vertical-align: baseline; word-break: break-word; background: rgba(128, 128, 128, 0.0745098);">access_token</code>的值是多少，过期时间等信息的。这就给资源服务器的实现带来了麻烦。我们的资源提供方并没有使用Spring Security，也不想引入 Spring Security 的任何依赖，这时候就只能将&nbsp;<code style="box-sizing: border-box; font-family: &quot;Source Code Pro&quot;, monospace; font-size: 13.5px; padding: 2px 4px; color: #3f3f3f; white-space: nowrap; border-radius: 0px; margin: 0px; border: 0px; outline: 0px; vertical-align: baseline; word-break: break-word; background: rgba(128, 128, 128, 0.0745098);">DefaultOAuth2AccessToken</code>的源码copy到资源提供方的项目中，然后读取<code style="box-sizing: border-box; font-family: &quot;Source Code Pro&quot;, monospace; font-size: 13.5px; padding: 2px 4px; color: #3f3f3f; white-space: nowrap; border-radius: 0px; margin: 0px; border: 0px; outline: 0px; vertical-align: baseline; word-break: break-word; background: rgba(128, 128, 128, 0.0745098);">token</code>字段并反序列化还原对象来获取token信息。但是如果这样做还会遇到反序列化兼容性的问题，具体解决方法参考我另一篇博文:<a href="http://blog.csdn.net/neosmith/article/details/52539614" style="box-sizing: border-box; color: #428bca; text-decoration: none; margin: 0px; padding: 0px; outline: none; background-image: initial; background-attachment: initial; background-size: initial; background-origin: initial; background-clip: initial; background-position: initial; background-repeat: initial;">http://blog.csdn.net/neosmith/article/details/52539614<br /><br /></a></p><h1>5. 总结</h1><p style="box-sizing: border-box; margin: 0px 0px 1.1em; padding: 0px; font-family: &quot;Microsoft YaHei&quot;; border: 0px; outline: 0px; font-size: 15px; vertical-align: baseline; color: #666666; line-height: 26px; background-image: initial; background-attachment: initial; background-size: initial; background-origin: initial; background-clip: initial; background-position: initial; background-repeat: initial;">至此一个能在生产环境下使用的授权服务就搭建好了。其实我们在实际使用时应该适当定制<code style="box-sizing: border-box; font-family: &quot;Source Code Pro&quot;, monospace; font-size: 13.5px; padding: 2px 4px; color: #3f3f3f; white-space: nowrap; border-radius: 0px; margin: 0px; border: 0px; outline: 0px; vertical-align: baseline; word-break: break-word; background: rgba(128, 128, 128, 0.0745098);">JdbcTokenStore</code>或<code style="box-sizing: border-box; font-family: &quot;Source Code Pro&quot;, monospace; font-size: 13.5px; padding: 2px 4px; color: #3f3f3f; white-space: nowrap; border-radius: 0px; margin: 0px; border: 0px; outline: 0px; vertical-align: baseline; word-break: break-word; background: rgba(128, 128, 128, 0.0745098);">ClientDetailsService</code>来实适应业务需要，甚至可以直接从0开始实现接口，完全不用框架提供的实现。另外，Spring 直接将<code style="box-sizing: border-box; font-family: &quot;Source Code Pro&quot;, monospace; font-size: 13.5px; padding: 2px 4px; color: #3f3f3f; white-space: nowrap; border-radius: 0px; margin: 0px; border: 0px; outline: 0px; vertical-align: baseline; word-break: break-word; background: rgba(128, 128, 128, 0.0745098);">DefaultOAuth2AccessToken</code>序列化成字节保存到数据库中的设计，我认为是非常不合理的。或许设计者的初衷是保密<code style="box-sizing: border-box; font-family: &quot;Source Code Pro&quot;, monospace; font-size: 13.5px; padding: 2px 4px; color: #3f3f3f; white-space: nowrap; border-radius: 0px; margin: 0px; border: 0px; outline: 0px; vertical-align: baseline; word-break: break-word; background: rgba(128, 128, 128, 0.0745098);">access_token</code>，但是通过加密的方法也可以实现，完全不应该直接扔字节。不过通过定制<code style="box-sizing: border-box; font-family: &quot;Source Code Pro&quot;, monospace; font-size: 13.5px; padding: 2px 4px; color: #3f3f3f; white-space: nowrap; border-radius: 0px; margin: 0px; border: 0px; outline: 0px; vertical-align: baseline; word-break: break-word; background: rgba(128, 128, 128, 0.0745098);">TokenStore</code>接口，我们可以使用自己的表结构而不拘泥于默认实现。<br /><br /><a href="http://blog.csdn.net/tracker_w/article/category/6360121" target="_blank">http://blog.csdn.net/tracker_w/article/category/6360121</a></p><p style="box-sizing: border-box; margin: 0px 0px 1.1em; padding: 0px; font-family: &quot;Microsoft YaHei&quot;; border: 0px; outline: 0px; font-size: 15px; vertical-align: baseline; color: #666666; line-height: 26px; background-image: initial; background-attachment: initial; background-size: initial; background-origin: initial; background-clip: initial; background-position: initial; background-repeat: initial;"><a href="http://blog.csdn.net/neosmith/article/details/52539927" target="_blank">http://blog.csdn.net/neosmith/article/details/52539927</a><br /><br /></p><img src ="http://www.blogjava.net/paulwong/aggbug/431797.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/paulwong/" target="_blank">paulwong</a> 2016-09-16 18:22 <a href="http://www.blogjava.net/paulwong/archive/2016/09/16/431797.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>使用Spring Cloud Feign作为HTTP客户端调用远程HTTP服务</title><link>http://www.blogjava.net/paulwong/archive/2016/09/16/431796.html</link><dc:creator>paulwong</dc:creator><author>paulwong</author><pubDate>Fri, 16 Sep 2016 10:13:00 GMT</pubDate><guid>http://www.blogjava.net/paulwong/archive/2016/09/16/431796.html</guid><wfw:comment>http://www.blogjava.net/paulwong/comments/431796.html</wfw:comment><comments>http://www.blogjava.net/paulwong/archive/2016/09/16/431796.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/paulwong/comments/commentRss/431796.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/paulwong/services/trackbacks/431796.html</trackback:ping><description><![CDATA[<p style="box-sizing: border-box; margin: 0px 0px 1.1em; padding: 0px; font-family: &quot;Microsoft YaHei&quot;; border: 0px; outline: 0px; font-size: 15px; vertical-align: baseline; color: #666666; line-height: 26px; background-image: initial; background-attachment: initial; background-size: initial; background-origin: initial; background-clip: initial; background-position: initial; background-repeat: initial;">在Spring Cloud Netflix栈中，各个微服务都是以HTTP接口的形式暴露自身服务的，因此在调用远程服务时就必须使用HTTP客户端。我们可以使用JDK原生的<code style="box-sizing: border-box; font-family: &quot;Source Code Pro&quot;, monospace; font-size: 13.5px; padding: 2px 4px; color: #3f3f3f; white-space: nowrap; border-radius: 0px; margin: 0px; border: 0px; outline: 0px; vertical-align: baseline; word-break: break-word; background: rgba(128, 128, 128, 0.0745098);">URLConnection</code>、Apache的<code style="box-sizing: border-box; font-family: &quot;Source Code Pro&quot;, monospace; font-size: 13.5px; padding: 2px 4px; color: #3f3f3f; white-space: nowrap; border-radius: 0px; margin: 0px; border: 0px; outline: 0px; vertical-align: baseline; word-break: break-word; background: rgba(128, 128, 128, 0.0745098);">Http Client</code>、Netty的异步HTTP Client, Spring的<code style="box-sizing: border-box; font-family: &quot;Source Code Pro&quot;, monospace; font-size: 13.5px; padding: 2px 4px; color: #3f3f3f; white-space: nowrap; border-radius: 0px; margin: 0px; border: 0px; outline: 0px; vertical-align: baseline; word-break: break-word; background: rgba(128, 128, 128, 0.0745098);">RestTemplate</code>。但是，用起来最方便、最优雅的还是要属Feign了。</p><h1>Feign简介</h1><p style="box-sizing: border-box; margin: 0px 0px 1.1em; padding: 0px; font-family: &quot;Microsoft YaHei&quot;; border: 0px; outline: 0px; font-size: 15px; vertical-align: baseline; color: #666666; line-height: 26px; background-image: initial; background-attachment: initial; background-size: initial; background-origin: initial; background-clip: initial; background-position: initial; background-repeat: initial;">Feign是一种声明式、模板化的HTTP客户端。在Spring Cloud中使用Feign, 我们可以做到使用HTTP请求远程服务时能与调用本地方法一样的编码体验，开发者完全感知不到这是远程方法，更感知不到这是个HTTP请求。比如：<br /></p><div style="background-color:#eeeeee;font-size:13px;border:1px solid #CCCCCC;padding-right: 5px;padding-bottom: 4px;padding-left: 4px;padding-top: 4px;width: 98%;word-break:break-all"><!--<br /><br />Code highlighting produced by Actipro CodeHighlighter (freeware)<br />http://www.CodeHighlighter.com/<br /><br />-->@Autowired<br /><span style="color: #0000FF; ">private</span>&nbsp;AdvertGropRemoteService&nbsp;service;&nbsp;<span style="color: #008000; ">//</span><span style="color: #008000; ">&nbsp;远程服务</span><span style="color: #008000; "><br /></span><br /><span style="color: #0000FF; ">public</span>&nbsp;AdvertGroupVO&nbsp;foo(Integer&nbsp;groupId)&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #0000FF; ">return</span>&nbsp;service.findByGroupId(groupId);&nbsp;<span style="color: #008000; ">//</span><span style="color: #008000; ">&nbsp;通过HTTP调用远程服务</span><span style="color: #008000; "><br /></span>}</div><p style="box-sizing: border-box; margin: 0px 0px 1.1em; padding: 0px; font-family: &quot;Microsoft YaHei&quot;; border: 0px; outline: 0px; font-size: 15px; vertical-align: baseline; color: #666666; line-height: 26px; background-image: initial; background-attachment: initial; background-size: initial; background-origin: initial; background-clip: initial; background-position: initial; background-repeat: initial;">开发者通过<code style="box-sizing: border-box; font-family: &quot;Source Code Pro&quot;, monospace; font-size: 13.5px; padding: 2px 4px; color: #3f3f3f; white-space: nowrap; border-radius: 0px; margin: 0px; border: 0px; outline: 0px; vertical-align: baseline; word-break: break-word; background: rgba(128, 128, 128, 0.0745098);">service.findByGroupId()</code>就能完成发送HTTP请求和解码HTTP返回结果并封装成对象的过程。</p><h1>Feign的定义</h1><p style="box-sizing: border-box; margin: 0px 0px 1.1em; padding: 0px; font-family: &quot;Microsoft YaHei&quot;; border: 0px; outline: 0px; font-size: 15px; vertical-align: baseline; color: #666666; line-height: 26px; background-image: initial; background-attachment: initial; background-size: initial; background-origin: initial; background-clip: initial; background-position: initial; background-repeat: initial;">为了让Feign知道在调用方法时应该向哪个地址发请求以及请求需要带哪些参数，我们需要定义一个接口：<br /></p><div style="background-color:#eeeeee;font-size:13px;border:1px solid #CCCCCC;padding-right: 5px;padding-bottom: 4px;padding-left: 4px;padding-top: 4px;width: 98%;word-break:break-all"><!--<br /><br />Code highlighting produced by Actipro CodeHighlighter (freeware)<br />http://www.CodeHighlighter.com/<br /><br />-->@FeignClient(name&nbsp;=&nbsp;"ea")&nbsp;&nbsp;<span style="color: #008000; ">//</span><span style="color: #008000; ">&nbsp;&nbsp;[A]</span><span style="color: #008000; "><br /></span><span style="color: #0000FF; ">public</span>&nbsp;<span style="color: #0000FF; ">interface</span>&nbsp;AdvertGroupRemoteService&nbsp;{<br /><br />&nbsp;&nbsp;&nbsp;&nbsp;@RequestMapping(value&nbsp;=&nbsp;"/group/{groupId}",&nbsp;method&nbsp;=&nbsp;RequestMethod.GET)&nbsp;<span style="color: #008000; ">//</span><span style="color: #008000; ">&nbsp;[B]</span><span style="color: #008000; "><br /></span>&nbsp;&nbsp;&nbsp;&nbsp;AdvertGroupVO&nbsp;findByGroupId(@PathVariable("groupId")&nbsp;Integer&nbsp;adGroupId)&nbsp;<span style="color: #008000; ">//</span><span style="color: #008000; ">&nbsp;[C]</span><span style="color: #008000; "><br /></span><br />&nbsp;&nbsp;&nbsp;&nbsp;@RequestMapping(value&nbsp;=&nbsp;"/group/{groupId}",&nbsp;method&nbsp;=&nbsp;RequestMethod.PUT)<br />&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #0000FF; ">void</span>&nbsp;update(@PathVariable("groupId")&nbsp;Integer&nbsp;groupId,&nbsp;@RequestParam("groupName")&nbsp;String&nbsp;groupName)</div><p style="box-sizing: border-box; margin: 0px 0px 1.1em; padding: 0px; font-family: &quot;Microsoft YaHei&quot;; border: 0px; outline: 0px; font-size: 15px; vertical-align: baseline; color: #666666; line-height: 26px; background-image: initial; background-attachment: initial; background-size: initial; background-origin: initial; background-clip: initial; background-position: initial; background-repeat: initial;">A:&nbsp;<code style="box-sizing: border-box; font-family: &quot;Source Code Pro&quot;, monospace; font-size: 13.5px; padding: 2px 4px; color: #3f3f3f; white-space: nowrap; border-radius: 0px; margin: 0px; border: 0px; outline: 0px; vertical-align: baseline; word-break: break-word; background: rgba(128, 128, 128, 0.0745098);">@FeignClient</code>用于通知Feign组件对该接口进行代理(不需要编写接口实现)，使用者可直接通过<code style="box-sizing: border-box; font-family: &quot;Source Code Pro&quot;, monospace; font-size: 13.5px; padding: 2px 4px; color: #3f3f3f; white-space: nowrap; border-radius: 0px; margin: 0px; border: 0px; outline: 0px; vertical-align: baseline; word-break: break-word; background: rgba(128, 128, 128, 0.0745098);">@Autowired</code>注入。</p><p style="box-sizing: border-box; margin: 0px 0px 1.1em; padding: 0px; font-family: &quot;Microsoft YaHei&quot;; border: 0px; outline: 0px; font-size: 15px; vertical-align: baseline; color: #666666; line-height: 26px; background-image: initial; background-attachment: initial; background-size: initial; background-origin: initial; background-clip: initial; background-position: initial; background-repeat: initial;">B:&nbsp;<code style="box-sizing: border-box; font-family: &quot;Source Code Pro&quot;, monospace; font-size: 13.5px; padding: 2px 4px; color: #3f3f3f; white-space: nowrap; border-radius: 0px; margin: 0px; border: 0px; outline: 0px; vertical-align: baseline; word-break: break-word; background: rgba(128, 128, 128, 0.0745098);">@RequestMapping</code>表示在调用该方法时需要向<code style="box-sizing: border-box; font-family: &quot;Source Code Pro&quot;, monospace; font-size: 13.5px; padding: 2px 4px; color: #3f3f3f; white-space: nowrap; border-radius: 0px; margin: 0px; border: 0px; outline: 0px; vertical-align: baseline; word-break: break-word; background: rgba(128, 128, 128, 0.0745098);">/group/{groupId}</code>发送<code style="box-sizing: border-box; font-family: &quot;Source Code Pro&quot;, monospace; font-size: 13.5px; padding: 2px 4px; color: #3f3f3f; white-space: nowrap; border-radius: 0px; margin: 0px; border: 0px; outline: 0px; vertical-align: baseline; word-break: break-word; background: rgba(128, 128, 128, 0.0745098);">GET</code>请求。</p><p style="box-sizing: border-box; margin: 0px 0px 1.1em; padding: 0px; font-family: &quot;Microsoft YaHei&quot;; border: 0px; outline: 0px; font-size: 15px; vertical-align: baseline; color: #666666; line-height: 26px; background-image: initial; background-attachment: initial; background-size: initial; background-origin: initial; background-clip: initial; background-position: initial; background-repeat: initial;">C:&nbsp;<code style="box-sizing: border-box; font-family: &quot;Source Code Pro&quot;, monospace; font-size: 13.5px; padding: 2px 4px; color: #3f3f3f; white-space: nowrap; border-radius: 0px; margin: 0px; border: 0px; outline: 0px; vertical-align: baseline; word-break: break-word; background: rgba(128, 128, 128, 0.0745098);">@PathVariable</code>与<code style="box-sizing: border-box; font-family: &quot;Source Code Pro&quot;, monospace; font-size: 13.5px; padding: 2px 4px; color: #3f3f3f; white-space: nowrap; border-radius: 0px; margin: 0px; border: 0px; outline: 0px; vertical-align: baseline; word-break: break-word; background: rgba(128, 128, 128, 0.0745098);">SpringMVC</code>中对应注解含义相同。</p><p style="box-sizing: border-box; margin: 0px 0px 1.1em; padding: 0px; font-family: &quot;Microsoft YaHei&quot;; border: 0px; outline: 0px; font-size: 15px; vertical-align: baseline; color: #666666; line-height: 26px; background-image: initial; background-attachment: initial; background-size: initial; background-origin: initial; background-clip: initial; background-position: initial; background-repeat: initial;">Spring Cloud应用在启动时，Feign会扫描标有<code style="box-sizing: border-box; font-family: &quot;Source Code Pro&quot;, monospace; font-size: 13.5px; padding: 2px 4px; color: #3f3f3f; white-space: nowrap; border-radius: 0px; margin: 0px; border: 0px; outline: 0px; vertical-align: baseline; word-break: break-word; background: rgba(128, 128, 128, 0.0745098);">@FeignClient</code>注解的接口，生成代理，并注册到Spring容器中。生成代理时Feign会为每个接口方法创建一个<code style="box-sizing: border-box; font-family: &quot;Source Code Pro&quot;, monospace; font-size: 13.5px; padding: 2px 4px; color: #3f3f3f; white-space: nowrap; border-radius: 0px; margin: 0px; border: 0px; outline: 0px; vertical-align: baseline; word-break: break-word; background: rgba(128, 128, 128, 0.0745098);">RequetTemplate</code>对象，该对象封装了HTTP请求需要的全部信息，请求参数名、请求方法等信息都是在这个过程中确定的，Feign的模板化就体现在这里。</p><p style="box-sizing: border-box; margin: 0px 0px 1.1em; padding: 0px; font-family: &quot;Microsoft YaHei&quot;; border: 0px; outline: 0px; font-size: 15px; vertical-align: baseline; color: #666666; line-height: 26px; background-image: initial; background-attachment: initial; background-size: initial; background-origin: initial; background-clip: initial; background-position: initial; background-repeat: initial;">在本例中，我们将Feign与Eureka和Ribbon组合使用，<code style="box-sizing: border-box; font-family: &quot;Source Code Pro&quot;, monospace; font-size: 13.5px; padding: 2px 4px; color: #3f3f3f; white-space: nowrap; border-radius: 0px; margin: 0px; border: 0px; outline: 0px; vertical-align: baseline; word-break: break-word; background: rgba(128, 128, 128, 0.0745098);">@FeignClient(name = "ea")</code>意为通知Feign在调用该接口方法时要向Eureka中查询名为<code style="box-sizing: border-box; font-family: &quot;Source Code Pro&quot;, monospace; font-size: 13.5px; padding: 2px 4px; color: #3f3f3f; white-space: nowrap; border-radius: 0px; margin: 0px; border: 0px; outline: 0px; vertical-align: baseline; word-break: break-word; background: rgba(128, 128, 128, 0.0745098);">ea</code>的服务，从而得到服务URL。</p><h1>Feign的Encoder、Decoder和ErrorDecoder</h1><p style="box-sizing: border-box; margin: 0px 0px 1.1em; padding: 0px; font-family: &quot;Microsoft YaHei&quot;; border: 0px; outline: 0px; font-size: 15px; vertical-align: baseline; color: #666666; line-height: 26px; background-image: initial; background-attachment: initial; background-size: initial; background-origin: initial; background-clip: initial; background-position: initial; background-repeat: initial;">Feign将方法签名中方法参数对象序列化为请求参数放到HTTP请求中的过程，是由编码器(Encoder)完成的。同理，将HTTP响应数据反序列化为java对象是由解码器(Decoder)完成的。</p><p style="box-sizing: border-box; margin: 0px 0px 1.1em; padding: 0px; font-family: &quot;Microsoft YaHei&quot;; border: 0px; outline: 0px; font-size: 15px; vertical-align: baseline; color: #666666; line-height: 26px; background-image: initial; background-attachment: initial; background-size: initial; background-origin: initial; background-clip: initial; background-position: initial; background-repeat: initial;">默认情况下，Feign会将标有<code style="box-sizing: border-box; font-family: &quot;Source Code Pro&quot;, monospace; font-size: 13.5px; padding: 2px 4px; color: #3f3f3f; white-space: nowrap; border-radius: 0px; margin: 0px; border: 0px; outline: 0px; vertical-align: baseline; word-break: break-word; background: rgba(128, 128, 128, 0.0745098);">@RequestParam</code>注解的参数转换成字符串添加到URL中，将没有注解的参数通过Jackson转换成json放到请求体中。注意，如果在<code style="box-sizing: border-box; font-family: &quot;Source Code Pro&quot;, monospace; font-size: 13.5px; padding: 2px 4px; color: #3f3f3f; white-space: nowrap; border-radius: 0px; margin: 0px; border: 0px; outline: 0px; vertical-align: baseline; word-break: break-word; background: rgba(128, 128, 128, 0.0745098);">@RequetMapping</code>中的<code style="box-sizing: border-box; font-family: &quot;Source Code Pro&quot;, monospace; font-size: 13.5px; padding: 2px 4px; color: #3f3f3f; white-space: nowrap; border-radius: 0px; margin: 0px; border: 0px; outline: 0px; vertical-align: baseline; word-break: break-word; background: rgba(128, 128, 128, 0.0745098);">method</code>将请求方式指定为<code style="box-sizing: border-box; font-family: &quot;Source Code Pro&quot;, monospace; font-size: 13.5px; padding: 2px 4px; color: #3f3f3f; white-space: nowrap; border-radius: 0px; margin: 0px; border: 0px; outline: 0px; vertical-align: baseline; word-break: break-word; background: rgba(128, 128, 128, 0.0745098);">POST</code>，那么所有未标注解的参数将会被忽略，例如：<br /></p><div style="font-size: 13px; border: 1px solid #cccccc; padding: 4px 5px 4px 4px; width: 98%; word-break: break-all; background-color: #eeeeee;"><!--<br /><br />Code highlighting produced by Actipro CodeHighlighter (freeware)<br />http://www.CodeHighlighter.com/<br /><br />-->@FeignClient(name&nbsp;=&nbsp;"ea")&nbsp;&nbsp;<span style="color: #008000; ">//</span><span style="color: #008000; ">&nbsp;&nbsp;[A]</span><span style="color: #008000; "><br /></span><span style="color: #0000FF; ">public</span>&nbsp;<span style="color: #0000FF; ">interface</span>&nbsp;AdvertGroupRemoteService&nbsp;{<br /><br />&nbsp;&nbsp;&nbsp;&nbsp;@RequestMapping(value&nbsp;=&nbsp;"/group/{groupId}",&nbsp;method&nbsp;=&nbsp;RequestMethod.GET)&nbsp;<span style="color: #008000; ">//</span><span style="color: #008000; ">&nbsp;[B]</span><span style="color: #008000; "><br /></span>&nbsp;&nbsp;&nbsp;&nbsp;AdvertGroupVO&nbsp;findByGroupId(@PathVariable("groupId")&nbsp;Integer&nbsp;adGroupId)&nbsp;<span style="color: #008000; ">//</span><span style="color: #008000; ">&nbsp;[C]</span><span style="color: #008000; "><br /></span><br />&nbsp;&nbsp;&nbsp;&nbsp;@RequestMapping(value&nbsp;=&nbsp;"/group/{groupId}",&nbsp;method&nbsp;=&nbsp;RequestMethod.PUT)<br />&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #0000FF; ">void</span>&nbsp;update(@PathVariable("groupId")&nbsp;Integer&nbsp;groupId,&nbsp;@RequestParam("groupName")&nbsp;String&nbsp;groupName)</div><p style="box-sizing: border-box; margin: 0px 0px 1.1em; padding: 0px; font-family: &quot;Microsoft YaHei&quot;; border: 0px; outline: 0px; font-size: 15px; vertical-align: baseline; color: #666666; line-height: 26px; background-image: initial; background-attachment: initial; background-size: initial; background-origin: initial; background-clip: initial; background-position: initial; background-repeat: initial;">此时因为声明的是GET请求没有请求体，所以<code style="box-sizing: border-box; font-family: &quot;Source Code Pro&quot;, monospace; font-size: 13.5px; padding: 2px 4px; color: #3f3f3f; white-space: nowrap; border-radius: 0px; margin: 0px; border: 0px; outline: 0px; vertical-align: baseline; word-break: break-word; background: rgba(128, 128, 128, 0.0745098);">obj</code>参数就会被忽略。</p><p style="box-sizing: border-box; margin: 0px 0px 1.1em; padding: 0px; font-family: &quot;Microsoft YaHei&quot;; border: 0px; outline: 0px; font-size: 15px; vertical-align: baseline; color: #666666; line-height: 26px; background-image: initial; background-attachment: initial; background-size: initial; background-origin: initial; background-clip: initial; background-position: initial; background-repeat: initial;">在Spring Cloud环境下，Feign的Encoder*只会用来编码没有添加注解的参数*。如果你自定义了Encoder, 那么只有在编码<code style="box-sizing: border-box; font-family: &quot;Source Code Pro&quot;, monospace; font-size: 13.5px; padding: 2px 4px; color: #3f3f3f; white-space: nowrap; border-radius: 0px; margin: 0px; border: 0px; outline: 0px; vertical-align: baseline; word-break: break-word; background: rgba(128, 128, 128, 0.0745098);">obj</code>参数时才会调用你的Encoder。对于Decoder, 默认会委托给SpringMVC中的<code style="box-sizing: border-box; font-family: &quot;Source Code Pro&quot;, monospace; font-size: 13.5px; padding: 2px 4px; color: #3f3f3f; white-space: nowrap; border-radius: 0px; margin: 0px; border: 0px; outline: 0px; vertical-align: baseline; word-break: break-word; background: rgba(128, 128, 128, 0.0745098);">MappingJackson2HttpMessageConverter</code>类进行解码。只有当状态码不在200 ~ 300之间时ErrorDecoder才会被调用。ErrorDecoder的作用是可以根据HTTP响应信息返回一个异常，该异常可以在调用Feign接口的地方被捕获到。我们目前就通过ErrorDecoder来使Feign接口抛出业务异常以供调用者处理。</p><h1>Feign的HTTP Client</h1><p style="box-sizing: border-box; margin: 0px 0px 1.1em; padding: 0px; font-family: &quot;Microsoft YaHei&quot;; border: 0px; outline: 0px; font-size: 15px; vertical-align: baseline; color: #666666; line-height: 26px; background-image: initial; background-attachment: initial; background-size: initial; background-origin: initial; background-clip: initial; background-position: initial; background-repeat: initial;">Feign在默认情况下使用的是JDK原生的<code style="box-sizing: border-box; font-family: &quot;Source Code Pro&quot;, monospace; font-size: 13.5px; padding: 2px 4px; color: #3f3f3f; white-space: nowrap; border-radius: 0px; margin: 0px; border: 0px; outline: 0px; vertical-align: baseline; word-break: break-word; background: rgba(128, 128, 128, 0.0745098);">URLConnection</code>发送HTTP请求，没有连接池，但是对每个地址会保持一个长连接，即利用HTTP的<code style="box-sizing: border-box; font-family: &quot;Source Code Pro&quot;, monospace; font-size: 13.5px; padding: 2px 4px; color: #3f3f3f; white-space: nowrap; border-radius: 0px; margin: 0px; border: 0px; outline: 0px; vertical-align: baseline; word-break: break-word; background: rgba(128, 128, 128, 0.0745098);">persistence connection</code>&nbsp;。我们可以用Apache的HTTP Client替换Feign原始的http client, 从而获取连接池、超时时间等与性能息息相关的控制能力。Spring Cloud从<code style="box-sizing: border-box; font-family: &quot;Source Code Pro&quot;, monospace; font-size: 13.5px; padding: 2px 4px; color: #3f3f3f; white-space: nowrap; border-radius: 0px; margin: 0px; border: 0px; outline: 0px; vertical-align: baseline; word-break: break-word; background: rgba(128, 128, 128, 0.0745098);">Brixtion.SR5</code>版本开始支持这种替换，首先在项目中声明Apache HTTP Client和<code style="box-sizing: border-box; font-family: &quot;Source Code Pro&quot;, monospace; font-size: 13.5px; padding: 2px 4px; color: #3f3f3f; white-space: nowrap; border-radius: 0px; margin: 0px; border: 0px; outline: 0px; vertical-align: baseline; word-break: break-word; background: rgba(128, 128, 128, 0.0745098);">feign-httpclient</code>依赖：<br /></p><div style="background-color:#eeeeee;font-size:13px;border:1px solid #CCCCCC;padding-right: 5px;padding-bottom: 4px;padding-left: 4px;padding-top: 4px;width: 98%;word-break:break-all"><!--<br /><br />Code highlighting produced by Actipro CodeHighlighter (freeware)<br />http://www.CodeHighlighter.com/<br /><br />-->@RequestMapping(value&nbsp;=&nbsp;"/group/{groupId}",&nbsp;method&nbsp;=&nbsp;RequestMethod.GET)<br /><span style="color: #0000FF; ">void</span>&nbsp;update(@PathVariable("groupId")&nbsp;Integer&nbsp;groupId,&nbsp;@RequestParam("groupName")&nbsp;String&nbsp;groupName,&nbsp;DataObject&nbsp;obj);</div><p style="box-sizing: border-box; margin: 0px 0px 1.1em; padding: 0px; font-family: &quot;Microsoft YaHei&quot;; border: 0px; outline: 0px; font-size: 15px; vertical-align: baseline; color: #666666; line-height: 26px; background-image: initial; background-attachment: initial; background-size: initial; background-origin: initial; background-clip: initial; background-position: initial; background-repeat: initial;">然后在<code style="box-sizing: border-box; font-family: &quot;Source Code Pro&quot;, monospace; font-size: 13.5px; padding: 2px 4px; color: #3f3f3f; white-space: nowrap; border-radius: 0px; margin: 0px; border: 0px; outline: 0px; vertical-align: baseline; word-break: break-word; background: rgba(128, 128, 128, 0.0745098);">application.properties</code>中添加：<br /></p><div style="background-color:#eeeeee;font-size:13px;border:1px solid #CCCCCC;padding-right: 5px;padding-bottom: 4px;padding-left: 4px;padding-top: 4px;width: 98%;word-break:break-all"><!--<br /><br />Code highlighting produced by Actipro CodeHighlighter (freeware)<br />http://www.CodeHighlighter.com/<br /><br />-->feign.httpclient.enabled=true</div><h1>总结</h1><p style="box-sizing: border-box; margin: 0px 0px 1.1em; padding: 0px; font-family: &quot;Microsoft YaHei&quot;; border: 0px; outline: 0px; font-size: 15px; vertical-align: baseline; color: #666666; line-height: 26px; background-image: initial; background-attachment: initial; background-size: initial; background-origin: initial; background-clip: initial; background-position: initial; background-repeat: initial;">通过Feign， 我们能把HTTP远程调用对开发者完全透明，得到与调用本地方法一致的编码体验。这一点与阿里Dubbo中暴露远程服务的方式类似，区别在于Dubbo是基于私有二进制协议，而Feign本质上还是个HTTP客户端。如果是在用Spring Cloud Netflix搭建微服务，那么Feign无疑是最佳选择。<br /><br /><a href="http://blog.csdn.net/tracker_w/article/category/6360121" target="_blank">http://blog.csdn.net/tracker_w/article/category/6360121</a><br /><a href="http://blog.csdn.net/neosmith/article/details/52449921" target="_blank">http://blog.csdn.net/neosmith/article/details/52449921</a><br /></p><img src ="http://www.blogjava.net/paulwong/aggbug/431796.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/paulwong/" target="_blank">paulwong</a> 2016-09-16 18:13 <a href="http://www.blogjava.net/paulwong/archive/2016/09/16/431796.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>微服务框架Spring Cloud</title><link>http://www.blogjava.net/paulwong/archive/2016/09/11/431788.html</link><dc:creator>paulwong</dc:creator><author>paulwong</author><pubDate>Sun, 11 Sep 2016 12:49:00 GMT</pubDate><guid>http://www.blogjava.net/paulwong/archive/2016/09/11/431788.html</guid><wfw:comment>http://www.blogjava.net/paulwong/comments/431788.html</wfw:comment><comments>http://www.blogjava.net/paulwong/archive/2016/09/11/431788.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/paulwong/comments/commentRss/431788.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/paulwong/services/trackbacks/431788.html</trackback:ping><description><![CDATA[<h2>2016</h2><article style="margin: 0px 0px 0px 5em; padding: 1em 0px 0.7em 4.5em; border: 0px; font-variant-numeric: inherit; font-stretch: inherit; line-height: 27.6px; font-family: &quot;PT Serif&quot;, Georgia, Times, &quot;Times New Roman&quot;, serif; font-size: 18.4px; vertical-align: baseline; position: relative; color: #aaaaaa; background: url(&quot;data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACgAAAABCAYAAACsXeyTAAAAFUlEQVR4AWNIS0sr/v//PwMUDzo+ADqMahmdZfljAAAAAElFTkSuQmCC&quot;) left bottom repeat-x #f8f8f8;"><h1><a href="http://skaka.me/blog/2016/09/04/springcloud5/" style="margin: 0px; padding: 0px; border: 0px; font-style: inherit; font-variant: inherit; font-weight: normal; font-stretch: inherit; line-height: inherit; font-family: inherit; font-size: 27.6px; vertical-align: baseline; transition: color 0.3s; white-space: pre-wrap; word-wrap: break-word; text-decoration: none; display: inline-block;" target="_blank">微服务框架Spring Cloud介绍 Part5: 在微服务系统中使用Hystrix, Hystrix Dashboard与Turbine</a></h1><time datetime="2016-09-04T21:03:22+08:00" pubdate="" style="margin: 0px; padding: 0px; border: 0px; font-style: inherit; font-variant: inherit; font-weight: inherit; font-stretch: inherit; line-height: 1.2em; font-family: &quot;PT Sans&quot;, &quot;Helvetica Neue&quot;, Arial, sans-serif; font-size: 0.9em; vertical-align: baseline; position: absolute; text-align: right; left: 0em; top: 1.8em;"><span style="margin: 0px; padding: 0px; border: 0px; font-style: inherit; font-variant: inherit; font-weight: inherit; font-stretch: inherit; line-height: inherit; font-family: inherit; font-size: 16.56px; vertical-align: baseline; display: inline-block; text-transform: uppercase;">SEP</span>&nbsp;<span style="margin: 0px; padding: 0px; border: 0px; font-style: inherit; font-variant: inherit; font-weight: inherit; font-stretch: inherit; line-height: inherit; font-family: inherit; font-size: 16.56px; vertical-align: baseline; display: inline-block;">04</span></time><footer style="margin: 0px; padding: 0px; border: 0px; font-style: inherit; font-variant: inherit; font-weight: inherit; font-stretch: inherit; line-height: inherit; font-family: &quot;PT Sans&quot;, &quot;Helvetica Neue&quot;, Arial, sans-serif; font-size: 18.4px; vertical-align: baseline;"><span style="margin: 0px; padding: 0px; border: 0px; font-style: inherit; font-variant: inherit; font-weight: inherit; font-stretch: inherit; line-height: inherit; font-family: inherit; font-size: 18.4px; vertical-align: baseline;">posted in&nbsp;<a href="http://skaka.me/blog/categories/spring-cloud/" style="margin: 0px; padding: 0px; border: 0px; font-style: inherit; font-variant: inherit; font-weight: inherit; font-stretch: inherit; line-height: 1.1em; font-size: 18.4px; vertical-align: baseline; color: #aaaaaa; transition: color 0.3s; white-space: pre-wrap; word-wrap: break-word;">spring cloud</a>,&nbsp;<a href="http://skaka.me/blog/categories/wei-fu-wu/" style="margin: 0px; padding: 0px; border: 0px; font-style: inherit; font-variant: inherit; font-weight: inherit; font-stretch: inherit; line-height: 1.1em; font-size: 18.4px; vertical-align: baseline; color: #aaaaaa; transition: color 0.3s; white-space: pre-wrap; word-wrap: break-word;">微服务</a></span></footer></article><article style="margin: 0px 0px 0px 5em; padding: 1em 0px 0.7em 4.5em; border: 0px; font-variant-numeric: inherit; font-stretch: inherit; line-height: 27.6px; font-family: &quot;PT Serif&quot;, Georgia, Times, &quot;Times New Roman&quot;, serif; font-size: 18.4px; vertical-align: baseline; position: relative; color: #aaaaaa; background: url(&quot;data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACgAAAABCAYAAACsXeyTAAAAFUlEQVR4AWNIS0sr/v//PwMUDzo+ADqMahmdZfljAAAAAElFTkSuQmCC&quot;) left bottom repeat-x #f8f8f8;"><h1><a href="http://skaka.me/blog/2016/08/25/springcloud4/" style="margin: 0px; padding: 0px; border: 0px; font-style: inherit; font-variant: inherit; font-weight: normal; font-stretch: inherit; line-height: inherit; font-family: inherit; font-size: 27.6px; vertical-align: baseline; transition: color 0.3s; white-space: pre-wrap; word-wrap: break-word; text-decoration: none; display: inline-block;" target="_blank">微服务框架Spring Cloud介绍 Part4: 使用Eureka, Ribbon, Feign实现REST服务客户端</a></h1><time datetime="2016-08-25T19:52:31+08:00" pubdate="" style="margin: 0px; padding: 0px; border: 0px; font-style: inherit; font-variant: inherit; font-weight: inherit; font-stretch: inherit; line-height: 1.2em; font-family: &quot;PT Sans&quot;, &quot;Helvetica Neue&quot;, Arial, sans-serif; font-size: 0.9em; vertical-align: baseline; position: absolute; text-align: right; left: 0em; top: 1.8em;"><span style="margin: 0px; padding: 0px; border: 0px; font-style: inherit; font-variant: inherit; font-weight: inherit; font-stretch: inherit; line-height: inherit; font-family: inherit; font-size: 16.56px; vertical-align: baseline; display: inline-block; text-transform: uppercase;">AUG</span>&nbsp;<span style="margin: 0px; padding: 0px; border: 0px; font-style: inherit; font-variant: inherit; font-weight: inherit; font-stretch: inherit; line-height: inherit; font-family: inherit; font-size: 16.56px; vertical-align: baseline; display: inline-block;">25</span></time><footer style="margin: 0px; padding: 0px; border: 0px; font-style: inherit; font-variant: inherit; font-weight: inherit; font-stretch: inherit; line-height: inherit; font-family: &quot;PT Sans&quot;, &quot;Helvetica Neue&quot;, Arial, sans-serif; font-size: 18.4px; vertical-align: baseline;"><span style="margin: 0px; padding: 0px; border: 0px; font-style: inherit; font-variant: inherit; font-weight: inherit; font-stretch: inherit; line-height: inherit; font-family: inherit; font-size: 18.4px; vertical-align: baseline;">posted in&nbsp;<a href="http://skaka.me/blog/categories/spring-cloud/" style="margin: 0px; padding: 0px; border: 0px; font-style: inherit; font-variant: inherit; font-weight: inherit; font-stretch: inherit; line-height: 1.1em; font-size: 18.4px; vertical-align: baseline; color: #aaaaaa; transition: color 0.3s; white-space: pre-wrap; word-wrap: break-word;">spring cloud</a>,&nbsp;<a href="http://skaka.me/blog/categories/wei-fu-wu/" style="margin: 0px; padding: 0px; border: 0px; font-style: inherit; font-variant: inherit; font-weight: inherit; font-stretch: inherit; line-height: 1.1em; font-size: 18.4px; vertical-align: baseline; color: #aaaaaa; transition: color 0.3s; white-space: pre-wrap; word-wrap: break-word;">微服务</a></span></footer></article><article style="margin: 0px 0px 0px 5em; padding: 1em 0px 0.7em 4.5em; border: 0px; font-variant-numeric: inherit; font-stretch: inherit; line-height: 27.6px; font-family: &quot;PT Serif&quot;, Georgia, Times, &quot;Times New Roman&quot;, serif; font-size: 18.4px; vertical-align: baseline; position: relative; color: #aaaaaa; background: url(&quot;data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACgAAAABCAYAAACsXeyTAAAAFUlEQVR4AWNIS0sr/v//PwMUDzo+ADqMahmdZfljAAAAAElFTkSuQmCC&quot;) left bottom repeat-x #f8f8f8;"><h1><a href="http://skaka.me/blog/2016/08/10/springcloud3/" style="margin: 0px; padding: 0px; border: 0px; font-style: inherit; font-variant: inherit; font-weight: normal; font-stretch: inherit; line-height: inherit; font-family: inherit; font-size: 27.6px; vertical-align: baseline; transition: color 0.3s; white-space: pre-wrap; word-wrap: break-word; text-decoration: none; display: inline-block;" target="_blank">微服务框架Spring Cloud介绍 Part3: Mysteam项目结构与开发用户注册服务</a></h1><time datetime="2016-08-10T10:06:10+08:00" pubdate="" style="margin: 0px; padding: 0px; border: 0px; font-style: inherit; font-variant: inherit; font-weight: inherit; font-stretch: inherit; line-height: 1.2em; font-family: &quot;PT Sans&quot;, &quot;Helvetica Neue&quot;, Arial, sans-serif; font-size: 0.9em; vertical-align: baseline; position: absolute; text-align: right; left: 0em; top: 1.8em;"><span style="margin: 0px; padding: 0px; border: 0px; font-style: inherit; font-variant: inherit; font-weight: inherit; font-stretch: inherit; line-height: inherit; font-family: inherit; font-size: 16.56px; vertical-align: baseline; display: inline-block; text-transform: uppercase;">AUG</span>&nbsp;<span style="margin: 0px; padding: 0px; border: 0px; font-style: inherit; font-variant: inherit; font-weight: inherit; font-stretch: inherit; line-height: inherit; font-family: inherit; font-size: 16.56px; vertical-align: baseline; display: inline-block;">10</span></time><footer style="margin: 0px; padding: 0px; border: 0px; font-style: inherit; font-variant: inherit; font-weight: inherit; font-stretch: inherit; line-height: inherit; font-family: &quot;PT Sans&quot;, &quot;Helvetica Neue&quot;, Arial, sans-serif; font-size: 18.4px; vertical-align: baseline;"><span style="margin: 0px; padding: 0px; border: 0px; font-style: inherit; font-variant: inherit; font-weight: inherit; font-stretch: inherit; line-height: inherit; font-family: inherit; font-size: 18.4px; vertical-align: baseline;">posted in&nbsp;<a href="http://skaka.me/blog/categories/spring-cloud/" style="margin: 0px; padding: 0px; border: 0px; font-style: inherit; font-variant: inherit; font-weight: inherit; font-stretch: inherit; line-height: 1.1em; font-size: 18.4px; vertical-align: baseline; color: #aaaaaa; transition: color 0.3s; white-space: pre-wrap; word-wrap: break-word;">spring cloud</a>,&nbsp;<a href="http://skaka.me/blog/categories/wei-fu-wu/" style="margin: 0px; padding: 0px; border: 0px; font-style: inherit; font-variant: inherit; font-weight: inherit; font-stretch: inherit; line-height: 1.1em; font-size: 18.4px; vertical-align: baseline; color: #aaaaaa; transition: color 0.3s; white-space: pre-wrap; word-wrap: break-word;">微服务</a></span></footer></article><article style="margin: 0px 0px 0px 5em; padding: 1em 0px 0.7em 4.5em; border: 0px; font-variant-numeric: inherit; font-stretch: inherit; line-height: 27.6px; font-family: &quot;PT Serif&quot;, Georgia, Times, &quot;Times New Roman&quot;, serif; font-size: 18.4px; vertical-align: baseline; position: relative; color: #aaaaaa; background: url(&quot;data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACgAAAABCAYAAACsXeyTAAAAFUlEQVR4AWNIS0sr/v//PwMUDzo+ADqMahmdZfljAAAAAElFTkSuQmCC&quot;) left bottom repeat-x #f8f8f8;"><h1><a href="http://skaka.me/blog/2016/08/03/springcloud2/" style="margin: 0px; padding: 0px; border: 0px; font-style: inherit; font-variant: inherit; font-weight: normal; font-stretch: inherit; line-height: inherit; font-family: inherit; font-size: 27.6px; vertical-align: baseline; transition: color 0.3s; white-space: pre-wrap; word-wrap: break-word; text-decoration: none; display: inline-block;">微服务框架Spring Cloud介绍 Part2: Spring Cloud与微服务</a></h1><time datetime="2016-08-03T22:09:25+08:00" pubdate="" style="margin: 0px; padding: 0px; border: 0px; font-style: inherit; font-variant: inherit; font-weight: inherit; font-stretch: inherit; line-height: 1.2em; font-family: &quot;PT Sans&quot;, &quot;Helvetica Neue&quot;, Arial, sans-serif; font-size: 0.9em; vertical-align: baseline; position: absolute; text-align: right; left: 0em; top: 1.8em;"><span style="margin: 0px; padding: 0px; border: 0px; font-style: inherit; font-variant: inherit; font-weight: inherit; font-stretch: inherit; line-height: inherit; font-family: inherit; font-size: 16.56px; vertical-align: baseline; display: inline-block; text-transform: uppercase;">AUG</span>&nbsp;<span style="margin: 0px; padding: 0px; border: 0px; font-style: inherit; font-variant: inherit; font-weight: inherit; font-stretch: inherit; line-height: inherit; font-family: inherit; font-size: 16.56px; vertical-align: baseline; display: inline-block;">03</span></time><footer style="margin: 0px; padding: 0px; border: 0px; font-style: inherit; font-variant: inherit; font-weight: inherit; font-stretch: inherit; line-height: inherit; font-family: &quot;PT Sans&quot;, &quot;Helvetica Neue&quot;, Arial, sans-serif; font-size: 18.4px; vertical-align: baseline;"><span style="margin: 0px; padding: 0px; border: 0px; font-style: inherit; font-variant: inherit; font-weight: inherit; font-stretch: inherit; line-height: inherit; font-family: inherit; font-size: 18.4px; vertical-align: baseline;">posted in&nbsp;<a href="http://skaka.me/blog/categories/spring-cloud/" style="margin: 0px; padding: 0px; border: 0px; font-style: inherit; font-variant: inherit; font-weight: inherit; font-stretch: inherit; line-height: 1.1em; font-size: 18.4px; vertical-align: baseline; color: #aaaaaa; transition: color 0.3s; white-space: pre-wrap; word-wrap: break-word;">spring cloud</a>,&nbsp;<a href="http://skaka.me/blog/categories/wei-fu-wu/" style="margin: 0px; padding: 0px; border: 0px; font-style: inherit; font-variant: inherit; font-weight: inherit; font-stretch: inherit; line-height: 1.1em; font-size: 18.4px; vertical-align: baseline; color: #aaaaaa; transition: color 0.3s; white-space: pre-wrap; word-wrap: break-word;">微服务</a></span></footer></article><article style="margin: 0px 0px 0px 5em; padding: 1em 0px 0.7em 4.5em; border: 0px; font-variant-numeric: inherit; font-stretch: inherit; line-height: 27.6px; font-family: &quot;PT Serif&quot;, Georgia, Times, &quot;Times New Roman&quot;, serif; font-size: 18.4px; vertical-align: baseline; position: relative; color: #aaaaaa; background: url(&quot;data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACgAAAABCAYAAACsXeyTAAAAFUlEQVR4AWNIS0sr/v//PwMUDzo+ADqMahmdZfljAAAAAElFTkSuQmCC&quot;) left bottom repeat-x #f8f8f8;"><h1><a href="http://skaka.me/blog/2016/05/02/finagle3/" style="margin: 0px; padding: 0px; border: 0px; font-style: inherit; font-variant: inherit; font-weight: normal; font-stretch: inherit; line-height: inherit; font-family: inherit; font-size: 27.6px; vertical-align: baseline; transition: color 0.3s; white-space: pre-wrap; word-wrap: break-word; text-decoration: none; display: inline-block;">微服务框架Finagle介绍 Part3: 在Finagle中开发基于Thrift协议的应用</a></h1><time datetime="2016-05-02T21:32:55+08:00" pubdate="" style="margin: 0px; padding: 0px; border: 0px; font-style: inherit; font-variant: inherit; font-weight: inherit; font-stretch: inherit; line-height: 1.2em; font-family: &quot;PT Sans&quot;, &quot;Helvetica Neue&quot;, Arial, sans-serif; font-size: 0.9em; vertical-align: baseline; position: absolute; text-align: right; left: 0em; top: 1.8em;"><span style="margin: 0px; padding: 0px; border: 0px; font-style: inherit; font-variant: inherit; font-weight: inherit; font-stretch: inherit; line-height: inherit; font-family: inherit; font-size: 16.56px; vertical-align: baseline; display: inline-block; text-transform: uppercase;">MAY</span>&nbsp;<span style="margin: 0px; padding: 0px; border: 0px; font-style: inherit; font-variant: inherit; font-weight: inherit; font-stretch: inherit; line-height: inherit; font-family: inherit; font-size: 16.56px; vertical-align: baseline; display: inline-block;">02</span></time><footer style="margin: 0px; padding: 0px; border: 0px; font-style: inherit; font-variant: inherit; font-weight: inherit; font-stretch: inherit; line-height: inherit; font-family: &quot;PT Sans&quot;, &quot;Helvetica Neue&quot;, Arial, sans-serif; font-size: 18.4px; vertical-align: baseline;"><span style="margin: 0px; padding: 0px; border: 0px; font-style: inherit; font-variant: inherit; font-weight: inherit; font-stretch: inherit; line-height: inherit; font-family: inherit; font-size: 18.4px; vertical-align: baseline;">posted in&nbsp;<a href="http://skaka.me/blog/categories/finagle/" style="margin: 0px; padding: 0px; border: 0px; font-style: inherit; font-variant: inherit; font-weight: inherit; font-stretch: inherit; line-height: 1.1em; font-size: 18.4px; vertical-align: baseline; color: #aaaaaa; transition: color 0.3s; white-space: pre-wrap; word-wrap: break-word;">finagle</a>,&nbsp;<a href="http://skaka.me/blog/categories/wei-fu-wu/" style="margin: 0px; padding: 0px; border: 0px; font-style: inherit; font-variant: inherit; font-weight: inherit; font-stretch: inherit; line-height: 1.1em; font-size: 18.4px; vertical-align: baseline; color: #aaaaaa; transition: color 0.3s; white-space: pre-wrap; word-wrap: break-word;">微服务</a></span></footer></article><article style="margin: 0px 0px 0px 5em; padding: 1em 0px 0.7em 4.5em; border: 0px; font-variant-numeric: inherit; font-stretch: inherit; line-height: 27.6px; font-family: &quot;PT Serif&quot;, Georgia, Times, &quot;Times New Roman&quot;, serif; font-size: 18.4px; vertical-align: baseline; position: relative; color: #aaaaaa; background: url(&quot;data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACgAAAABCAYAAACsXeyTAAAAFUlEQVR4AWNIS0sr/v//PwMUDzo+ADqMahmdZfljAAAAAElFTkSuQmCC&quot;) left bottom repeat-x #f8f8f8;"><h1><a href="http://skaka.me/blog/2016/05/01/finagle2/" style="margin: 0px; padding: 0px; border: 0px; font-style: inherit; font-variant: inherit; font-weight: normal; font-stretch: inherit; line-height: inherit; font-family: inherit; font-size: 27.6px; vertical-align: baseline; transition: color 0.3s; white-space: pre-wrap; word-wrap: break-word; text-decoration: none; display: inline-block;">微服务框架Finagle介绍 Part2: 在Finagle中开发基于Http协议的应用</a></h1><time datetime="2016-05-01T10:17:35+08:00" pubdate="" style="margin: 0px; padding: 0px; border: 0px; font-style: inherit; font-variant: inherit; font-weight: inherit; font-stretch: inherit; line-height: 1.2em; font-family: &quot;PT Sans&quot;, &quot;Helvetica Neue&quot;, Arial, sans-serif; font-size: 0.9em; vertical-align: baseline; position: absolute; text-align: right; left: 0em; top: 1.8em;"><span style="margin: 0px; padding: 0px; border: 0px; font-style: inherit; font-variant: inherit; font-weight: inherit; font-stretch: inherit; line-height: inherit; font-family: inherit; font-size: 16.56px; vertical-align: baseline; display: inline-block; text-transform: uppercase;">MAY</span>&nbsp;<span style="margin: 0px; padding: 0px; border: 0px; font-style: inherit; font-variant: inherit; font-weight: inherit; font-stretch: inherit; line-height: inherit; font-family: inherit; font-size: 16.56px; vertical-align: baseline; display: inline-block;">01</span></time><footer style="margin: 0px; padding: 0px; border: 0px; font-style: inherit; font-variant: inherit; font-weight: inherit; font-stretch: inherit; line-height: inherit; font-family: &quot;PT Sans&quot;, &quot;Helvetica Neue&quot;, Arial, sans-serif; font-size: 18.4px; vertical-align: baseline;"><span style="margin: 0px; padding: 0px; border: 0px; font-style: inherit; font-variant: inherit; font-weight: inherit; font-stretch: inherit; line-height: inherit; font-family: inherit; font-size: 18.4px; vertical-align: baseline;">posted in&nbsp;<a href="http://skaka.me/blog/categories/finagle/" style="margin: 0px; padding: 0px; border: 0px; font-style: inherit; font-variant: inherit; font-weight: inherit; font-stretch: inherit; line-height: 1.1em; font-size: 18.4px; vertical-align: baseline; color: #aaaaaa; transition: color 0.3s; white-space: pre-wrap; word-wrap: break-word;">finagle</a>,&nbsp;<a href="http://skaka.me/blog/categories/wei-fu-wu/" style="margin: 0px; padding: 0px; border: 0px; font-style: inherit; font-variant: inherit; font-weight: inherit; font-stretch: inherit; line-height: 1.1em; font-size: 18.4px; vertical-align: baseline; color: #aaaaaa; transition: color 0.3s; white-space: pre-wrap; word-wrap: break-word;">微服务</a></span></footer></article><article style="margin: 0px 0px 0px 5em; padding: 1em 0px 0.7em 4.5em; border: 0px; font-variant-numeric: inherit; font-stretch: inherit; line-height: 27.6px; font-family: &quot;PT Serif&quot;, Georgia, Times, &quot;Times New Roman&quot;, serif; font-size: 18.4px; vertical-align: baseline; position: relative; color: #aaaaaa; background: url(&quot;data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACgAAAABCAYAAACsXeyTAAAAFUlEQVR4AWNIS0sr/v//PwMUDzo+ADqMahmdZfljAAAAAElFTkSuQmCC&quot;) left bottom repeat-x #f8f8f8;"><h1><a href="http://skaka.me/blog/2016/04/21/springcloud1/" style="margin: 0px; padding: 0px; border: 0px; font-style: inherit; font-variant: inherit; font-weight: normal; font-stretch: inherit; line-height: inherit; font-family: inherit; font-size: 27.6px; vertical-align: baseline; transition: color 0.3s; white-space: pre-wrap; word-wrap: break-word; text-decoration: none; display: inline-block;" target="_blank">微服务框架Spring Cloud介绍 Part1: 使用事件和消息队列实现分布式事务</a></h1><time datetime="2016-04-21T11:21:45+08:00" pubdate="" style="margin: 0px; padding: 0px; border: 0px; font-style: inherit; font-variant: inherit; font-weight: inherit; font-stretch: inherit; line-height: 1.2em; font-family: &quot;PT Sans&quot;, &quot;Helvetica Neue&quot;, Arial, sans-serif; font-size: 0.9em; vertical-align: baseline; position: absolute; text-align: right; left: 0em; top: 1.8em;"><span style="margin: 0px; padding: 0px; border: 0px; font-style: inherit; font-variant: inherit; font-weight: inherit; font-stretch: inherit; line-height: inherit; font-family: inherit; font-size: 16.56px; vertical-align: baseline; display: inline-block; text-transform: uppercase;">APR</span>&nbsp;<span style="margin: 0px; padding: 0px; border: 0px; font-style: inherit; font-variant: inherit; font-weight: inherit; font-stretch: inherit; line-height: inherit; font-family: inherit; font-size: 16.56px; vertical-align: baseline; display: inline-block;">21</span></time><footer style="margin: 0px; padding: 0px; border: 0px; font-style: inherit; font-variant: inherit; font-weight: inherit; font-stretch: inherit; line-height: inherit; font-family: &quot;PT Sans&quot;, &quot;Helvetica Neue&quot;, Arial, sans-serif; font-size: 18.4px; vertical-align: baseline;"><span style="margin: 0px; padding: 0px; border: 0px; font-style: inherit; font-variant: inherit; font-weight: inherit; font-stretch: inherit; line-height: inherit; font-family: inherit; font-size: 18.4px; vertical-align: baseline;">posted in&nbsp;<a href="http://skaka.me/blog/categories/spring-cloud/" style="margin: 0px; padding: 0px; border: 0px; font-style: inherit; font-variant: inherit; font-weight: inherit; font-stretch: inherit; line-height: 1.1em; font-size: 18.4px; vertical-align: baseline; color: #aaaaaa; transition: color 0.3s; white-space: pre-wrap; word-wrap: break-word;">spring cloud</a>,&nbsp;<a href="http://skaka.me/blog/categories/fen-bu-shi-shi-wu/" style="margin: 0px; padding: 0px; border: 0px; font-style: inherit; font-variant: inherit; font-weight: inherit; font-stretch: inherit; line-height: 1.1em; font-size: 18.4px; vertical-align: baseline; color: #aaaaaa; transition: color 0.3s; white-space: pre-wrap; word-wrap: break-word;">分布式事务</a>,&nbsp;<a href="http://skaka.me/blog/categories/wei-fu-wu/" style="margin: 0px; padding: 0px; border: 0px; font-style: inherit; font-variant: inherit; font-weight: inherit; font-stretch: inherit; line-height: 1.1em; font-size: 18.4px; vertical-align: baseline; color: #aaaaaa; transition: color 0.3s; white-space: pre-wrap; word-wrap: break-word;">微服务</a></span></footer></article><article style="margin: 0px 0px 0px 5em; padding: 1em 0px 0.7em 4.5em; border: 0px; font-variant-numeric: inherit; font-stretch: inherit; line-height: 27.6px; font-family: &quot;PT Serif&quot;, Georgia, Times, &quot;Times New Roman&quot;, serif; font-size: 18.4px; vertical-align: baseline; position: relative; color: #aaaaaa; background: none #f8f8f8;"><h1><a href="http://skaka.me/blog/2016/03/19/finagle1/" style="margin: 0px; padding: 0px; border: 0px; font-style: inherit; font-variant: inherit; font-weight: normal; font-stretch: inherit; line-height: inherit; font-family: inherit; font-size: 27.6px; vertical-align: baseline; transition: color 0.3s; white-space: pre-wrap; word-wrap: break-word; text-decoration: none; display: inline-block;">微服务框架Finagle介绍 Part1: Future, Service, Filter</a></h1><time datetime="2016-03-19T21:33:12+08:00" pubdate="" style="margin: 0px; padding: 0px; border: 0px; font-style: inherit; font-variant: inherit; font-weight: inherit; font-stretch: inherit; line-height: 1.2em; font-family: &quot;PT Sans&quot;, &quot;Helvetica Neue&quot;, Arial, sans-serif; font-size: 0.9em; vertical-align: baseline; position: absolute; text-align: right; left: 0em; top: 1.8em;"><span style="margin: 0px; padding: 0px; border: 0px; font-style: inherit; font-variant: inherit; font-weight: inherit; font-stretch: inherit; line-height: inherit; font-family: inherit; font-size: 16.56px; vertical-align: baseline; display: inline-block; text-transform: uppercase;">MAR</span>&nbsp;<span style="margin: 0px; padding: 0px; border: 0px; font-style: inherit; font-variant: inherit; font-weight: inherit; font-stretch: inherit; line-height: inherit; font-family: inherit; font-size: 16.56px; vertical-align: baseline; display: inline-block;">19</span></time><footer style="margin: 0px; padding: 0px; border: 0px; font-style: inherit; font-variant: inherit; font-weight: inherit; font-stretch: inherit; line-height: inherit; font-family: &quot;PT Sans&quot;, &quot;Helvetica Neue&quot;, Arial, sans-serif; font-size: 18.4px; vertical-align: baseline;"><span style="margin: 0px; padding: 0px; border: 0px; font-style: inherit; font-variant: inherit; font-weight: inherit; font-stretch: inherit; line-height: inherit; font-family: inherit; font-size: 18.4px; vertical-align: baseline;">posted in&nbsp;<a href="http://skaka.me/blog/categories/finagle/" style="margin: 0px; padding: 0px; border: 0px; font-style: inherit; font-variant: inherit; font-weight: inherit; font-stretch: inherit; line-height: 1.1em; font-size: 18.4px; vertical-align: baseline; color: #aaaaaa; transition: color 0.3s; white-space: pre-wrap; word-wrap: break-word;">finagle</a>,&nbsp;<a href="http://skaka.me/blog/categories/wei-fu-wu/" style="margin: 0px; padding: 0px; border: 0px; font-style: inherit; font-variant: inherit; font-weight: inherit; font-stretch: inherit; line-height: 1.1em; font-size: 18.4px; vertical-align: baseline; color: #aaaaaa; transition: color 0.3s; white-space: pre-wrap; word-wrap: break-word;">微服务</a></span></footer></article><img src ="http://www.blogjava.net/paulwong/aggbug/431788.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/paulwong/" target="_blank">paulwong</a> 2016-09-11 20:49 <a href="http://www.blogjava.net/paulwong/archive/2016/09/11/431788.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>JHipster</title><link>http://www.blogjava.net/paulwong/archive/2016/09/11/431787.html</link><dc:creator>paulwong</dc:creator><author>paulwong</author><pubDate>Sun, 11 Sep 2016 08:40:00 GMT</pubDate><guid>http://www.blogjava.net/paulwong/archive/2016/09/11/431787.html</guid><wfw:comment>http://www.blogjava.net/paulwong/comments/431787.html</wfw:comment><comments>http://www.blogjava.net/paulwong/archive/2016/09/11/431787.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/paulwong/comments/commentRss/431787.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/paulwong/services/trackbacks/431787.html</trackback:ping><description><![CDATA[基于SPRING CLOUD的微服务框架<br /><a href="http://jhipster.cn/" target="_blank">http://jhipster.cn/</a><img src ="http://www.blogjava.net/paulwong/aggbug/431787.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/paulwong/" target="_blank">paulwong</a> 2016-09-11 16:40 <a href="http://www.blogjava.net/paulwong/archive/2016/09/11/431787.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>spring cloud项目读取配置管理</title><link>http://www.blogjava.net/paulwong/archive/2016/09/11/431785.html</link><dc:creator>paulwong</dc:creator><author>paulwong</author><pubDate>Sun, 11 Sep 2016 08:26:00 GMT</pubDate><guid>http://www.blogjava.net/paulwong/archive/2016/09/11/431785.html</guid><wfw:comment>http://www.blogjava.net/paulwong/comments/431785.html</wfw:comment><comments>http://www.blogjava.net/paulwong/archive/2016/09/11/431785.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/paulwong/comments/commentRss/431785.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/paulwong/services/trackbacks/431785.html</trackback:ping><description><![CDATA[摘要<br />spring cloud config server配置好了数据库连接信息，这个项目读取config，获取连接信息。这里以mybtis作为列子。从服务器读取jdbc信息后，运行mybatis程序。<br /><br />确认服务是否成功<br />        http://localhost:8888/demo-config/test<br /><div style="background-color:#eeeeee;font-size:13px;border:1px solid #CCCCCC;padding-right: 5px;padding-bottom: 4px;padding-left: 4px;padding-top: 4px;width: 98%;word-break:break-all"><!--<br /><br />Code highlighting produced by Actipro CodeHighlighter (freeware)<br />http://www.CodeHighlighter.com/<br /><br />-->{"name":"demo-config","profiles":<span style="color: #800000; font-weight: bold; ">[</span><span style="color: #800000; ">"test"</span><span style="color: #800000; font-weight: bold; ">]</span>,"label":"master","version":"02d28ad4925aa9bd1bf8a48d2edbf04ce61aa45a","propertySources":<span style="color: #800000; font-weight: bold; ">[</span><span style="color: #800000; ">{"name":"https://git.oschina.net/penghaozhong/demo.git/demo-config-repo/demo-config-test.properties","source":{"jdbc.url":"jdbc:mysql://localhost:3306/demo?characterEncoding=UTF-8","jdbc.username":"root","jdbc.driver":"com.mysql.jdbc.Driver","jdbc.password":"xxxxxx","jdbc.type":"mysql"}}</span><span style="color: #800000; font-weight: bold; ">]</span>}</div><br />&nbsp; &nbsp; 2. 配置读取配置文件<br /><br /><span style="color: #3d464d; font-family: &quot;Pingfang SC&quot;, STHeiti, &quot;Lantinghei SC&quot;, &quot;Open Sans&quot;, Arial, &quot;Hiragino Sans GB&quot;, &quot;Microsoft YaHei&quot;, &quot;WenQuanYi Micro Hei&quot;, SimSun, sans-serif; font-size: 16px; line-height: 30px;">&nbsp;&nbsp;</span><img height="404" src="http://static.oschina.net/uploads/space/2016/0721/134039_2SWP_124056.png" width="990" style="box-sizing: inherit; -webkit-tap-highlight-color: transparent; border: none; margin: auto; max-width: 80%; height: auto; color: #3d464d; font-family: &quot;Pingfang SC&quot;, STHeiti, &quot;Lantinghei SC&quot;, &quot;Open Sans&quot;, Arial, &quot;Hiragino Sans GB&quot;, &quot;Microsoft YaHei&quot;, &quot;WenQuanYi Micro Hei&quot;, SimSun, sans-serif; font-size: 16px; line-height: 30px;"  alt="" /><br /><br /><br /><br />在bootstrap.properties中添加读取配置管理的地址。<br /><br />3. 读取配置文件属性，这里采用@ConfigurationProperties<br /><div style="background-color:#eeeeee;font-size:13px;border:1px solid #CCCCCC;padding-right: 5px;padding-bottom: 4px;padding-left: 4px;padding-top: 4px;width: 98%;word-break:break-all"><!--<br /><br />Code highlighting produced by Actipro CodeHighlighter (freeware)<br />http://www.CodeHighlighter.com/<br /><br />--><span style="color: #008000; ">/**</span><span style="color: #008000; "><br />&nbsp;*&nbsp;读取数据库配置文件<br />&nbsp;*&nbsp;</span><span style="color: #808080; ">@author</span><span style="color: #008000; ">&nbsp;penghaozhong<br />&nbsp;*<br />&nbsp;</span><span style="color: #008000; ">*/</span><br />@ConfigurationProperties(prefix&nbsp;=&nbsp;DataSourceProperties.PREFIX,&nbsp;ignoreUnknownFields&nbsp;=&nbsp;<span style="color: #0000FF; ">false</span>)<br /><span style="color: #0000FF; ">public</span>&nbsp;&nbsp;<span style="color: #0000FF; ">class</span>&nbsp;&nbsp;DataSourceProperties&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #0000FF; ">public</span>&nbsp;DataSourceProperties()&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #0000FF; ">super</span>();<br />&nbsp;&nbsp;&nbsp;&nbsp;}<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #008000; ">//</span><span style="color: #008000; ">对应配置文件里的配置键</span><span style="color: #008000; "><br /></span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #0000FF; ">public</span>&nbsp;<span style="color: #0000FF; ">final</span>&nbsp;<span style="color: #0000FF; ">static</span>&nbsp;String&nbsp;PREFIX="jdbc";&nbsp;&nbsp;&nbsp;&nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #0000FF; ">private</span>&nbsp;String&nbsp;type;&nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #0000FF; ">private</span>&nbsp;String&nbsp;driver;&nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #0000FF; ">private</span>&nbsp;String&nbsp;url;&nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #0000FF; ">private</span>&nbsp;String&nbsp;username;&nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #0000FF; ">private</span>&nbsp;String&nbsp;password;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #0000FF; ">public</span>&nbsp;String&nbsp;getType()&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #0000FF; ">return</span>&nbsp;type;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #0000FF; ">public</span>&nbsp;<span style="color: #0000FF; ">void</span>&nbsp;setType(String&nbsp;type)&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #0000FF; ">this</span>.type&nbsp;=&nbsp;type;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #0000FF; ">public</span>&nbsp;String&nbsp;getDriver()&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #0000FF; ">return</span>&nbsp;driver;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #0000FF; ">public</span>&nbsp;<span style="color: #0000FF; ">void</span>&nbsp;setDriver(String&nbsp;driver)&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #0000FF; ">this</span>.driver&nbsp;=&nbsp;driver;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #0000FF; ">public</span>&nbsp;String&nbsp;getUrl()&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #0000FF; ">return</span>&nbsp;url;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #0000FF; ">public</span>&nbsp;<span style="color: #0000FF; ">void</span>&nbsp;setUrl(String&nbsp;url)&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #0000FF; ">this</span>.url&nbsp;=&nbsp;url;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #0000FF; ">public</span>&nbsp;String&nbsp;getUsername()&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #0000FF; ">return</span>&nbsp;username;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #0000FF; ">public</span>&nbsp;<span style="color: #0000FF; ">void</span>&nbsp;setUsername(String&nbsp;username)&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #0000FF; ">this</span>.username&nbsp;=&nbsp;username;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #0000FF; ">public</span>&nbsp;String&nbsp;getPassword()&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #0000FF; ">return</span>&nbsp;password;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #0000FF; ">public</span>&nbsp;<span style="color: #0000FF; ">void</span>&nbsp;setPassword(String&nbsp;password)&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #0000FF; ">this</span>.password&nbsp;=&nbsp;password;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br /><br />}</div><br /><br />4. 配置mybatis<br /><div style="background-color:#eeeeee;font-size:13px;border:1px solid #CCCCCC;padding-right: 5px;padding-bottom: 4px;padding-left: 4px;padding-top: 4px;width: 98%;word-break:break-all"><!--<br /><br />Code highlighting produced by Actipro CodeHighlighter (freeware)<br />http://www.CodeHighlighter.com/<br /><br />-->@Configuration<br />@MapperScan("com.phz.test.spring.cloud.demo")<br />@EnableConfigurationProperties(DataSourceProperties.<span style="color: #0000FF; ">class</span>)<br />@EnableTransactionManagement<br /><span style="color: #0000FF; ">public</span>&nbsp;<span style="color: #0000FF; ">class</span>&nbsp;MybatisDataSource&nbsp;{<br /><br />&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #008000; ">//</span><span style="color: #008000; ">&nbsp;mybaits&nbsp;mapper&nbsp;xml搜索路径</span><span style="color: #008000; "><br /></span>&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #0000FF; ">private</span>&nbsp;<span style="color: #0000FF; ">final</span>&nbsp;<span style="color: #0000FF; ">static</span>&nbsp;String&nbsp;MAPPERLOCATIONS&nbsp;=&nbsp;"classpath:/mappings/**/*.xml";<br />&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #0000FF; ">private</span>&nbsp;<span style="color: #0000FF; ">final</span>&nbsp;<span style="color: #0000FF; ">static</span>&nbsp;String&nbsp;CONFIGLOCATION&nbsp;=&nbsp;"classpath:/mybatis-config.xml";<br /><br />&nbsp;&nbsp;&nbsp;&nbsp;@Autowired<br />&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #0000FF; ">private</span>&nbsp;&nbsp;DataSourceProperties&nbsp;dataSourceProperties;<br />&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #0000FF; ">private</span>&nbsp;DruidDataSource&nbsp;datasource&nbsp;=&nbsp;<span style="color: #0000FF; ">null</span>;<br /><br />&nbsp;&nbsp;&nbsp;&nbsp;@Bean(destroyMethod&nbsp;=&nbsp;"close")<br />&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #0000FF; ">public</span>&nbsp;&nbsp;DataSource&nbsp;dataSource(){<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;datasource&nbsp;=&nbsp;<span style="color: #0000FF; ">new</span>&nbsp;DruidDataSource();&nbsp;&nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;datasource.setUrl(dataSourceProperties.getUrl());<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;datasource.setDbType(dataSourceProperties.getType());<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;datasource.setDriverClassName(dataSourceProperties.getDriver());<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;datasource.setUsername(dataSourceProperties.getUsername());<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;datasource.setPassword(dataSourceProperties.getPassword());<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #0000FF; ">return</span>&nbsp;datasource;<br />&nbsp;&nbsp;&nbsp;&nbsp;}<br /><br />&nbsp;&nbsp;&nbsp;&nbsp;@PreDestroy<br />&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #0000FF; ">public</span>&nbsp;<span style="color: #0000FF; ">void</span>&nbsp;close()&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #0000FF; ">if</span>(datasource&nbsp;!=&nbsp;<span style="color: #0000FF; ">null</span>){<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;datasource.close();<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br />&nbsp;&nbsp;&nbsp;&nbsp;}<br /><br />&nbsp;&nbsp;&nbsp;&nbsp;@Bean<br />&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #0000FF; ">public</span>&nbsp;SqlSessionFactory&nbsp;sqlSessionFactoryBean()&nbsp;<span style="color: #0000FF; ">throws</span>&nbsp;Exception&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;SqlSessionFactoryBean&nbsp;sqlSessionFactoryBean&nbsp;=&nbsp;<span style="color: #0000FF; ">new</span>&nbsp;SqlSessionFactoryBean();<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;sqlSessionFactoryBean.setDataSource(dataSource());<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;PathMatchingResourcePatternResolver&nbsp;resolver&nbsp;=&nbsp;<span style="color: #0000FF; ">new</span>&nbsp;PathMatchingResourcePatternResolver();<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;sqlSessionFactoryBean.setMapperLocations(resolver.getResources(MAPPERLOCATIONS));<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;sqlSessionFactoryBean.setConfigLocation(resolver.getResource(CONFIGLOCATION));<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;sqlSessionFactoryBean.setTypeAliasesPackage("com.phz.test.spring.cloud.demo.entity");<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #0000FF; ">return</span>&nbsp;sqlSessionFactoryBean.getObject();<br />&nbsp;&nbsp;&nbsp;&nbsp;}<br /><br />&nbsp;&nbsp;&nbsp;&nbsp;@Bean<br />&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #0000FF; ">public</span>&nbsp;PlatformTransactionManager&nbsp;transactionManager()&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #0000FF; ">return</span>&nbsp;<span style="color: #0000FF; ">new</span>&nbsp;DataSourceTransactionManager(dataSource());<br />&nbsp;&nbsp;&nbsp;&nbsp;}<br /><br />}</div><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><img src ="http://www.blogjava.net/paulwong/aggbug/431785.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/paulwong/" target="_blank">paulwong</a> 2016-09-11 16:26 <a href="http://www.blogjava.net/paulwong/archive/2016/09/11/431785.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>MICROSERVICE 资源</title><link>http://www.blogjava.net/paulwong/archive/2016/09/01/431723.html</link><dc:creator>paulwong</dc:creator><author>paulwong</author><pubDate>Thu, 01 Sep 2016 13:46:00 GMT</pubDate><guid>http://www.blogjava.net/paulwong/archive/2016/09/01/431723.html</guid><wfw:comment>http://www.blogjava.net/paulwong/comments/431723.html</wfw:comment><comments>http://www.blogjava.net/paulwong/archive/2016/09/01/431723.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/paulwong/comments/commentRss/431723.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/paulwong/services/trackbacks/431723.html</trackback:ping><description><![CDATA[Spring Cloud 为开发者提供了在分布式系统（如配置管理、服务发现、断路器、智能路由、微代理、控制总线、一次性 Token、全局锁、决策竞选、分布式会话和集群状态）操作的开发工具。使用 Spring Cloud 开发者可以快速实现上述这些模式。<br />
<br />
<span style="color: #333333; font-family: &quot;Helvetica Neue&quot;, Helvetica, Arial, &quot;PingFang SC&quot;, &quot;Hiragino Sans GB&quot;, &quot;WenQuanYi Micro Hei&quot;, &quot;Microsoft Yahei&quot;, sans-serif; line-height: 22.4px;">主要有eureka做服务发现、config做分布式配置、zuul做api-gateway、feign做客户端负载均衡、hystrix做断路器、turbine做聚合的monitor、graphite做指标监控。</span><br />
<br />
<a href="http://blog.csdn.net/liaokailin/article/category/6212338" target="_blank">http://blog.csdn.net/liaokailin/article/category/6212338</a><br />
<br />
<br />
MICROSERVICE WITH SPRING-CLOUD.<br />
<a href="https://github.com/kennyk65/Microservices-With-Spring-Student-Files" target="_blank">https://github.com/kennyk65/Microservices-With-Spring-Student-Files<br />
</a>
<br />
<br />
<br />
<br />
!!!spring-cloud-study<br />
<a href="http://git.oschina.net/itmuch/spring-cloud-study" target="_blank">http://git.oschina.net/itmuch/spring-cloud-study</a><img src ="http://www.blogjava.net/paulwong/aggbug/431723.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/paulwong/" target="_blank">paulwong</a> 2016-09-01 21:46 <a href="http://www.blogjava.net/paulwong/archive/2016/09/01/431723.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item></channel></rss>