﻿<?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-随笔分类-SPRING CLOUD</title><link>http://www.blogjava.net/paulwong/category/55116.html</link><description /><language>zh-cn</language><lastBuildDate>Wed, 01 Dec 2021 16:36:18 GMT</lastBuildDate><pubDate>Wed, 01 Dec 2021 16:36:18 GMT</pubDate><ttl>60</ttl><item><title>SPRING CLOUD - REACTIVE FEIGN</title><link>http://www.blogjava.net/paulwong/archive/2021/12/01/436078.html</link><dc:creator>paulwong</dc:creator><author>paulwong</author><pubDate>Wed, 01 Dec 2021 08:45:00 GMT</pubDate><guid>http://www.blogjava.net/paulwong/archive/2021/12/01/436078.html</guid><wfw:comment>http://www.blogjava.net/paulwong/comments/436078.html</wfw:comment><comments>http://www.blogjava.net/paulwong/archive/2021/12/01/436078.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/paulwong/comments/commentRss/436078.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/paulwong/services/trackbacks/436078.html</trackback:ping><description><![CDATA[目前SPRING CLOUD(2020)尚未支持REACTIVE FEIGN，但官方推荐使用feign-reactive。<br /><br />pom.xml<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: #0000FF; ">&lt;</span><span style="color: #800000; ">dependency</span><span style="color: #0000FF; ">&gt;</span><br />&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #0000FF; ">&lt;</span><span style="color: #800000; ">groupId</span><span style="color: #0000FF; ">&gt;</span>com.playtika.reactivefeign<span style="color: #0000FF; ">&lt;/</span><span style="color: #800000; ">groupId</span><span style="color: #0000FF; ">&gt;</span><br />&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #0000FF; ">&lt;</span><span style="color: #800000; ">artifactId</span><span style="color: #0000FF; ">&gt;</span>feign-reactor-spring-cloud-starter<span style="color: #0000FF; ">&lt;/</span><span style="color: #800000; ">artifactId</span><span style="color: #0000FF; ">&gt;</span><br />&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #0000FF; ">&lt;</span><span style="color: #800000; ">version</span><span style="color: #0000FF; ">&gt;</span>3.1.2<span style="color: #0000FF; ">&lt;/</span><span style="color: #800000; ">version</span><span style="color: #0000FF; ">&gt;</span><br />&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #0000FF; ">&lt;</span><span style="color: #800000; ">type</span><span style="color: #0000FF; ">&gt;</span>pom<span style="color: #0000FF; ">&lt;/</span><span style="color: #800000; ">type</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></div><br /><br />LoanDecisionClientReactive.java<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: #0000FF; ">package</span>&nbsp;com.paul.testspringcloudstream.loancheck.service;<br /><br /><span style="color: #0000FF; ">import</span>&nbsp;org.springframework.web.bind.annotation.PostMapping;<br /><span style="color: #0000FF; ">import</span>&nbsp;org.springframework.web.bind.annotation.RequestBody;<br /><br /><span style="color: #0000FF; ">import</span>&nbsp;com.paul.testspringcloudstream.common.model.Loan;<br /><br /><span style="color: #0000FF; ">import</span>&nbsp;reactivefeign.spring.config.ReactiveFeignClient;<br /><span style="color: #0000FF; ">import</span>&nbsp;reactor.core.publisher.Mono;<br /><br />@ReactiveFeignClient(name&nbsp;=&nbsp;"loan-decision")<br /><span style="color: #0000FF; ">public</span>&nbsp;<span style="color: #0000FF; ">interface</span>&nbsp;LoanDecisionClientReactive&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;@PostMapping("/loan-decision")<br />&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #0000FF; ">public</span>&nbsp;Mono&lt;Loan&gt;&nbsp;getDecision(@RequestBody&nbsp;Loan&nbsp;loan);<br /><br />}</div><br />LoanCheckConfiguration.java<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 />@Import({<br />&nbsp;&nbsp;&nbsp;&nbsp;MongoDbConsumerConfiguration.<span style="color: #0000FF; ">class</span>,<br />})<br />@EnableDiscoveryClient<br />@EnableReactiveFeignClients("com.paul.testspringcloudstream.loancheck.service")<br /><span style="color: #0000FF; ">public</span>&nbsp;<span style="color: #0000FF; ">class</span>&nbsp;LoanCheckConfiguration&nbsp;{<br />}</div><br /><br />使用同feign<br /><div style="background-color: #eeeeee; font-size: 13px; border: 1px solid #cccccc; padding: 4px 5px 4px 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;LoanDecisionClientReactive&nbsp;loanDecisionClientReactive;</div><br />Reference<br /><a href="https://blog.csdn.net/LCBUSHIHAHA/article/details/113817966" target="_blank">https://blog.csdn.net/LCBUSHIHAHA/article/details/113817966</a><br /><br />官方SAMPLE<br /><a href="https://github.com/kptfh/feign-reactive-sample" target="_blank">https://github.com/kptfh/feign-reactive-sample</a><img src ="http://www.blogjava.net/paulwong/aggbug/436078.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-12-01 16:45 <a href="http://www.blogjava.net/paulwong/archive/2021/12/01/436078.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Spring bootstrap.yml 不管用，失效解决方案（spring cloud 2020.x.x）</title><link>http://www.blogjava.net/paulwong/archive/2021/12/01/436076.html</link><dc:creator>paulwong</dc:creator><author>paulwong</author><pubDate>Wed, 01 Dec 2021 02:29:00 GMT</pubDate><guid>http://www.blogjava.net/paulwong/archive/2021/12/01/436076.html</guid><wfw:comment>http://www.blogjava.net/paulwong/comments/436076.html</wfw:comment><comments>http://www.blogjava.net/paulwong/archive/2021/12/01/436076.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/paulwong/comments/commentRss/436076.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/paulwong/services/trackbacks/436076.html</trackback:ping><description><![CDATA[<div>升级spring cloud版本之后发现bootstrap.yml 失效了，阅读官方文档得知，需要新增一个引用来开启bootstrap.xml文件的读取，新版spring cloud默认是关闭读取了。</div><div></div><div>增加依赖如下即可：</div><div><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;<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;<span style="color: #0000FF; ">&lt;</span><span style="color: #800000; ">artifactId</span><span style="color: #0000FF; ">&gt;</span>spring-cloud-starter-bootstrap<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></div></div><div></div><div></div><div>官方文档：</div><div>https://docs.spring.io/spring-cloud-config/docs/current/reference/html/#config-first-bootstrap</div><div><img src="https://img-blog.csdnimg.cn/20210306153131455.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3hxOTI5NjA5OTY4,size_16,color_FFFFFF,t_70" width="985" height="278" alt="" /></div><div><br /></div><img src ="http://www.blogjava.net/paulwong/aggbug/436076.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-12-01 10:29 <a href="http://www.blogjava.net/paulwong/archive/2021/12/01/436076.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>EVEN DRIVEN - SPRING CLOUD STREAM - @PollableBean for Reactive Suppliers</title><link>http://www.blogjava.net/paulwong/archive/2021/11/23/436060.html</link><dc:creator>paulwong</dc:creator><author>paulwong</author><pubDate>Tue, 23 Nov 2021 02:03:00 GMT</pubDate><guid>http://www.blogjava.net/paulwong/archive/2021/11/23/436060.html</guid><wfw:comment>http://www.blogjava.net/paulwong/comments/436060.html</wfw:comment><comments>http://www.blogjava.net/paulwong/archive/2021/11/23/436060.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/paulwong/comments/commentRss/436060.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/paulwong/services/trackbacks/436060.html</trackback:ping><description><![CDATA[<p style="font-family: &quot;Open Sans&quot;, -apple-system, BlinkMacSystemFont, HelveticaNeue-Light, &quot;Segoe UI&quot;, &quot;Helvetica Neue&quot;, Helvetica, Raleway, Arial, sans-serif, &quot;Apple Color Emoji&quot;, &quot;Segoe UI Emoji&quot;, &quot;Segoe UI Symbol&quot;, -apple-system, BlinkMacSystemFont, HelveticaNeue-Light, &quot;Segoe UI&quot;, &quot;Helvetica Neue&quot;, Helvetica, Raleway, Arial, sans-serif, &quot;Apple Color Emoji&quot;, &quot;Segoe UI Emoji&quot;, &quot;Segoe UI Symbol&quot;; overflow-wrap: break-word; word-break: break-word; line-height: inherit; color: #222222; font-size: 16px; box-sizing: inherit; margin: 0px 0px 16px; padding: 0px; border: 0px; vertical-align: baseline; outline: 0px; text-overflow: ellipsis; background-color: #ffffff;"><code codeinline"="" spellcheck="false" tabindex="0" style="font-family: Menlo, Monaco, Consolas, &quot;Courier New&quot;, monospace; overflow-wrap: break-word; word-break: break-word; line-height: inherit; font-size: 0.85em; font-weight: inherit; box-sizing: inherit; margin: 0px; padding: 0.2em 0.4em; border: none; font-style: inherit; vertical-align: middle; background: #f7f7f7; overflow: auto; outline: 0px; display: inline; position: static; max-width: 100%; flex-shrink: 0; border-radius: 2px;">Supplier</code>&nbsp;beans, or functions that only publish messages in Spring Cloud Stream, are a bit special in that they aren't triggered by the receiving of events like&nbsp;<code codeinline"="" spellcheck="false" tabindex="0" style="font-family: Menlo, Monaco, Consolas, &quot;Courier New&quot;, monospace; overflow-wrap: break-word; word-break: break-word; line-height: inherit; font-size: 0.85em; font-weight: inherit; box-sizing: inherit; margin: 0px; padding: 0.2em 0.4em; border: none; font-style: inherit; vertical-align: middle; background: #f7f7f7; overflow: auto; outline: 0px; display: inline; position: static; max-width: 100%; flex-shrink: 0; border-radius: 2px;">Function</code>&nbsp;or&nbsp;<code codeinline"="" spellcheck="false" tabindex="0" style="font-family: Menlo, Monaco, Consolas, &quot;Courier New&quot;, monospace; overflow-wrap: break-word; word-break: break-word; line-height: inherit; font-size: 0.85em; font-weight: inherit; box-sizing: inherit; margin: 0px; padding: 0.2em 0.4em; border: none; font-style: inherit; vertical-align: middle; background: #f7f7f7; overflow: auto; outline: 0px; display: inline; position: static; max-width: 100%; flex-shrink: 0; border-radius: 2px;">Consumer</code>&nbsp;beans. This means that you often need a way to trigger them to be executed periodically.</p>
<p style="font-family: &quot;Open Sans&quot;, -apple-system, BlinkMacSystemFont, HelveticaNeue-Light, &quot;Segoe UI&quot;, &quot;Helvetica Neue&quot;, Helvetica, Raleway, Arial, sans-serif, &quot;Apple Color Emoji&quot;, &quot;Segoe UI Emoji&quot;, &quot;Segoe UI Symbol&quot;, -apple-system, BlinkMacSystemFont, HelveticaNeue-Light, &quot;Segoe UI&quot;, &quot;Helvetica Neue&quot;, Helvetica, Raleway, Arial, sans-serif, &quot;Apple Color Emoji&quot;, &quot;Segoe UI Emoji&quot;, &quot;Segoe UI Symbol&quot;; overflow-wrap: break-word; word-break: break-word; line-height: inherit; color: #222222; font-size: 16px; box-sizing: inherit; margin: 8px 0px 16px; padding: 0px; border: 0px; vertical-align: baseline; outline: 0px; text-overflow: ellipsis; background-color: #ffffff;">For&nbsp;<strong style="font-family: inherit; overflow-wrap: break-word; word-break: break-word; line-height: inherit; color: inherit; font-size: inherit; box-sizing: inherit;">imperative</strong>&nbsp;functions the framework by default "polls" a&nbsp;<code codeinline"="" spellcheck="false" tabindex="0" style="font-family: Menlo, Monaco, Consolas, &quot;Courier New&quot;, monospace; overflow-wrap: break-word; word-break: break-word; line-height: inherit; font-size: 0.85em; font-weight: inherit; box-sizing: inherit; margin: 0px; padding: 0.2em 0.4em; border: none; font-style: inherit; vertical-align: middle; background: #f7f7f7; overflow: auto; outline: 0px; display: inline; position: static; max-width: 100%; flex-shrink: 0; border-radius: 2px;">Supplier</code>&nbsp;function every 1 second, but that duration is configurable using the&nbsp;<code codeinline"="" spellcheck="false" tabindex="0" style="font-family: Menlo, Monaco, Consolas, &quot;Courier New&quot;, monospace; overflow-wrap: break-word; word-break: break-word; line-height: inherit; font-size: 0.85em; font-weight: inherit; box-sizing: inherit; margin: 0px; padding: 0.2em 0.4em; border: none; font-style: inherit; vertical-align: middle; background: #f7f7f7; overflow: auto; outline: 0px; display: inline; position: static; max-width: 100%; flex-shrink: 0; border-radius: 2px;">spring.cloud.stream.poller.fixed-delay</code>&nbsp;property.</p>
<p style="font-family: &quot;Open Sans&quot;, -apple-system, BlinkMacSystemFont, HelveticaNeue-Light, &quot;Segoe UI&quot;, &quot;Helvetica Neue&quot;, Helvetica, Raleway, Arial, sans-serif, &quot;Apple Color Emoji&quot;, &quot;Segoe UI Emoji&quot;, &quot;Segoe UI Symbol&quot;, -apple-system, BlinkMacSystemFont, HelveticaNeue-Light, &quot;Segoe UI&quot;, &quot;Helvetica Neue&quot;, Helvetica, Raleway, Arial, sans-serif, &quot;Apple Color Emoji&quot;, &quot;Segoe UI Emoji&quot;, &quot;Segoe UI Symbol&quot;; overflow-wrap: break-word; word-break: break-word; line-height: inherit; color: #222222; font-size: 16px; box-sizing: inherit; margin: 8px 0px 16px; padding: 0px; border: 0px; vertical-align: baseline; outline: 0px; text-overflow: ellipsis; background-color: #ffffff;">However, for&nbsp;<strong style="font-family: inherit; overflow-wrap: break-word; word-break: break-word; line-height: inherit; color: inherit; font-size: inherit; box-sizing: inherit;">reactive</strong>&nbsp;functions supplying a&nbsp;<code codeinline"="" spellcheck="false" tabindex="0" style="font-family: Menlo, Monaco, Consolas, &quot;Courier New&quot;, monospace; overflow-wrap: break-word; word-break: break-word; line-height: inherit; font-size: 0.85em; font-weight: inherit; box-sizing: inherit; margin: 0px; padding: 0.2em 0.4em; border: none; font-style: inherit; vertical-align: middle; background: #f7f7f7; overflow: auto; outline: 0px; display: inline; position: static; max-width: 100%; flex-shrink: 0; border-radius: 2px;">Flux</code>&nbsp;it is only triggered once by default. This is because a Flux itself is potentially an infinite stream of events so in many cases it will only need to be triggered once. But don't worry, if you want to periodically trigger a reactive&nbsp;<code codeinline"="" spellcheck="false" tabindex="0" style="font-family: Menlo, Monaco, Consolas, &quot;Courier New&quot;, monospace; overflow-wrap: break-word; word-break: break-word; line-height: inherit; font-size: 0.85em; font-weight: inherit; box-sizing: inherit; margin: 0px; padding: 0.2em 0.4em; border: none; font-style: inherit; vertical-align: middle; background: #f7f7f7; overflow: auto; outline: 0px; display: inline; position: static; max-width: 100%; flex-shrink: 0; border-radius: 2px;">Supplier</code>&nbsp;because you are producing a finite stream of events you can still do so using&nbsp;<code codeinline"="" spellcheck="false" tabindex="0" style="font-family: Menlo, Monaco, Consolas, &quot;Courier New&quot;, monospace; overflow-wrap: break-word; word-break: break-word; line-height: inherit; font-size: 0.85em; font-weight: inherit; box-sizing: inherit; margin: 0px; padding: 0.2em 0.4em; border: none; font-style: inherit; vertical-align: middle; background: #f7f7f7; overflow: auto; outline: 0px; display: inline; position: static; max-width: 100%; flex-shrink: 0; border-radius: 2px;">@PollableBean</code>. This annotation then allows you to configure how often the function is triggered using the same&nbsp;<code codeinline"="" spellcheck="false" tabindex="0" style="font-family: Menlo, Monaco, Consolas, &quot;Courier New&quot;, monospace; overflow-wrap: break-word; word-break: break-word; line-height: inherit; font-size: 0.85em; font-weight: inherit; box-sizing: inherit; margin: 0px; padding: 0.2em 0.4em; border: none; font-style: inherit; vertical-align: middle; background: #f7f7f7; overflow: auto; outline: 0px; display: inline; position: static; max-width: 100%; flex-shrink: 0; border-radius: 2px;">spring.cloud.stream.poller.fixed-delay</code>&nbsp;property!</p>
<p style="font-family: &quot;Open Sans&quot;, -apple-system, BlinkMacSystemFont, HelveticaNeue-Light, &quot;Segoe UI&quot;, &quot;Helvetica Neue&quot;, Helvetica, Raleway, Arial, sans-serif, &quot;Apple Color Emoji&quot;, &quot;Segoe UI Emoji&quot;, &quot;Segoe UI Symbol&quot;, -apple-system, BlinkMacSystemFont, HelveticaNeue-Light, &quot;Segoe UI&quot;, &quot;Helvetica Neue&quot;, Helvetica, Raleway, Arial, sans-serif, &quot;Apple Color Emoji&quot;, &quot;Segoe UI Emoji&quot;, &quot;Segoe UI Symbol&quot;; overflow-wrap: break-word; word-break: break-word; line-height: inherit; color: #222222; font-size: 16px; box-sizing: inherit; margin: 8px 0px 16px; padding: 0px; border: 0px; vertical-align: baseline; outline: 0px; text-overflow: ellipsis; background-color: #ffffff;">One example use case here could be periodically querying a data store and publishing each entry/row as an event. The number of rows in your data store is a finite number at any given time.</p>
<p style="font-family: &quot;Open Sans&quot;, -apple-system, BlinkMacSystemFont, HelveticaNeue-Light, &quot;Segoe UI&quot;, &quot;Helvetica Neue&quot;, Helvetica, Raleway, Arial, sans-serif, &quot;Apple Color Emoji&quot;, &quot;Segoe UI Emoji&quot;, &quot;Segoe UI Symbol&quot;, -apple-system, BlinkMacSystemFont, HelveticaNeue-Light, &quot;Segoe UI&quot;, &quot;Helvetica Neue&quot;, Helvetica, Raleway, Arial, sans-serif, &quot;Apple Color Emoji&quot;, &quot;Segoe UI Emoji&quot;, &quot;Segoe UI Symbol&quot;; overflow-wrap: break-word; word-break: break-word; line-height: inherit; color: #222222; font-size: 16px; box-sizing: inherit; margin: 8px 0px 16px; padding: 0px; border: 0px; vertical-align: baseline; outline: 0px; text-overflow: ellipsis; background-color: #ffffff;">Example code:</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 />-->@PollableBean&nbsp;<br /><span style="color: #0000FF; ">public</span>&nbsp;Supplier&lt;Flux&lt;String&gt;&gt;&nbsp;stringSupplier()&nbsp;{&nbsp;<span style="color: #0000FF; ">return</span>&nbsp;()&nbsp;-&gt;&nbsp;Flux.just("foo","bar","baz");&nbsp;}</div><br /><br />Reference:<br /><a href="https://solace.community/discussion/360/pollablebean-for-reactive-suppliers-in-spring-cloud-stream" target="_blank">https://solace.community/discussion/360/pollablebean-for-reactive-suppliers-in-spring-cloud-stream</a><img src ="http://www.blogjava.net/paulwong/aggbug/436060.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-11-23 10:03 <a href="http://www.blogjava.net/paulwong/archive/2021/11/23/436060.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>EVEN DRIVEN - SPRING CLOUD STREAM - 从非SCS组件发送消息到SCS组件</title><link>http://www.blogjava.net/paulwong/archive/2021/11/19/436054.html</link><dc:creator>paulwong</dc:creator><author>paulwong</author><pubDate>Fri, 19 Nov 2021 03:47:00 GMT</pubDate><guid>http://www.blogjava.net/paulwong/archive/2021/11/19/436054.html</guid><wfw:comment>http://www.blogjava.net/paulwong/comments/436054.html</wfw:comment><comments>http://www.blogjava.net/paulwong/archive/2021/11/19/436054.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/paulwong/comments/commentRss/436054.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/paulwong/services/trackbacks/436054.html</trackback:ping><description><![CDATA[在SPRING INTEGRATION中，如果要从非SPRING INTEGRATION代码发送MESSAGE到SPRING INTEGRATION程序，通常用BUS GATEWAY。<br />
<br />
那么在SPRING CLOUD STREAM中，如果要从非SPRING CLOUD STREAM代码发送MESSAGE到SPRING CLOUD STREAM程序，通常就要先通知框架自动生成一个SOURCE。<br />
<br />
application.property<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 />
-->spring.cloud.stream.source=supplier<br />
spring.cloud.stream.bindings.supplier-out-0.destination=notification-events</div>
<br />
java<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 />
-->streamBridge.send("supplier-out-0",&nbsp;userDto);</div>
<br />Reference:<br /><a href="https://blog.devgenius.io/event-driven-microservices-with-spring-cloud-stream-e034eee3f394" target="_blank">https://blog.devgenius.io/event-driven-microservices-with-spring-cloud-stream-e034eee3f394</a><br /><img src ="http://www.blogjava.net/paulwong/aggbug/436054.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-11-19 11:47 <a href="http://www.blogjava.net/paulwong/archive/2021/11/19/436054.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>EVEN DRIVEN - SPRING CLOUD STREAM - Error Handling</title><link>http://www.blogjava.net/paulwong/archive/2021/11/17/436052.html</link><dc:creator>paulwong</dc:creator><author>paulwong</author><pubDate>Wed, 17 Nov 2021 02:50:00 GMT</pubDate><guid>http://www.blogjava.net/paulwong/archive/2021/11/17/436052.html</guid><wfw:comment>http://www.blogjava.net/paulwong/comments/436052.html</wfw:comment><comments>http://www.blogjava.net/paulwong/archive/2021/11/17/436052.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/paulwong/comments/commentRss/436052.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/paulwong/services/trackbacks/436052.html</trackback:ping><description><![CDATA[如果Function中抛出异常，系统没有配置捕获异常，则异常消息会被丢弃。通常会进行配置。<br /><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 />-->@ServiceActivator(inputChannel&nbsp;=&nbsp;"my-destination.my-group.errors")<br />&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #0000FF; ">public</span>&nbsp;<span style="color: #0000FF; ">void</span>&nbsp;handleError(ErrorMessage&nbsp;message)&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Throwable&nbsp;throwable&nbsp;=&nbsp;message.getPayload();<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;log.error("截获异常",&nbsp;throwable);<br /><br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Message&lt;?&gt;&nbsp;originalMessage&nbsp;=&nbsp;message.getOriginalMessage();<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #0000FF; ">assert</span>&nbsp;originalMessage&nbsp;!=&nbsp;<span style="color: #0000FF; ">null</span>;<br /><br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;log.info("原始消息体&nbsp;=&nbsp;{}",&nbsp;<span style="color: #0000FF; ">new</span>&nbsp;String((<span style="color: #0000FF; ">byte</span>[])&nbsp;originalMessage.getPayload()));<br />&nbsp;&nbsp;&nbsp;&nbsp;}</div><br />详情参考：<br /><a href="https://www.itmuch.com/spring-cloud/spring-cloud-stream-error-handling/" target="_blank">https://www.itmuch.com/spring-cloud/spring-cloud-stream-error-handling/</a><img src ="http://www.blogjava.net/paulwong/aggbug/436052.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-11-17 10:50 <a href="http://www.blogjava.net/paulwong/archive/2021/11/17/436052.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>EVEN DRIVEN - SPRING CLOUD STREAM - Function Component</title><link>http://www.blogjava.net/paulwong/archive/2021/11/15/436051.html</link><dc:creator>paulwong</dc:creator><author>paulwong</author><pubDate>Mon, 15 Nov 2021 09:40:00 GMT</pubDate><guid>http://www.blogjava.net/paulwong/archive/2021/11/15/436051.html</guid><wfw:comment>http://www.blogjava.net/paulwong/comments/436051.html</wfw:comment><comments>http://www.blogjava.net/paulwong/archive/2021/11/15/436051.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/paulwong/comments/commentRss/436051.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/paulwong/services/trackbacks/436051.html</trackback:ping><description><![CDATA[如果要在SPRING CLOUD STREAM中和其他中间件打交道，如FILE、FTP、HTTP等，则要用到SPRING CLOUD FUNCTION。<br /><br />组件地址：<br /><a href="https://github.com/spring-cloud/stream-applications/tree/main/functions" target="_blank">https://github.com/spring-cloud/stream-applications/tree/main/functions</a><br /><br />特殊组件，将FUNCTION变成HTTP ENDPOINTS：<br /><a target="null"></a><a href="https://github.com/spring-cloud/spring-cloud-function/tree/main/spring-cloud-starter-function-web" target="_blank">https://github.com/spring-cloud/spring-cloud-function/tree/main/spring-cloud-starter-function-web</a><br /><a href="https://github.com/spring-cloud/spring-cloud-function/tree/main/spring-cloud-starter-function-webflux" target="_blank">https://github.com/spring-cloud/spring-cloud-function/tree/main/spring-cloud-starter-function-webflux</a><br /><br /><img src ="http://www.blogjava.net/paulwong/aggbug/436051.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-11-15 17:40 <a href="http://www.blogjava.net/paulwong/archive/2021/11/15/436051.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>EVEN DRIVEN - SPRING CLOUD STREAM - Routing Function</title><link>http://www.blogjava.net/paulwong/archive/2021/11/15/436050.html</link><dc:creator>paulwong</dc:creator><author>paulwong</author><pubDate>Mon, 15 Nov 2021 06:46:00 GMT</pubDate><guid>http://www.blogjava.net/paulwong/archive/2021/11/15/436050.html</guid><wfw:comment>http://www.blogjava.net/paulwong/comments/436050.html</wfw:comment><comments>http://www.blogjava.net/paulwong/archive/2021/11/15/436050.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/paulwong/comments/commentRss/436050.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/paulwong/services/trackbacks/436050.html</trackback:ping><description><![CDATA[SPRING CLOUD STREAM内置了一个RoutingFunction，能将MESSAGE路由到应用的其他FUNCTION中。<br />对接RoutingFunction可发送消息到其外部DESTINATION中或用&#8220;｜&#8221;连接符连接。<br /><br />application.yaml<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; ">&nbsp;This&nbsp;setting&nbsp;can&nbsp;increase&nbsp;or&nbsp;decrease&nbsp;the&nbsp;rate&nbsp;of&nbsp;message&nbsp;production&nbsp;(1000&nbsp;=&nbsp;1s)</span><span style="color: #008000; "><br />#</span><span style="color: #008000; ">&nbsp;spring.cloud.stream.poller.fixed-delay=1000</span><span style="color: #008000; "><br />#</span><span style="color: #008000; ">&nbsp;DefaultPollerProperties</span><span style="color: #008000; "><br /></span><br /><span style="color: #008000; ">#</span><span style="color: #008000; ">&nbsp;This&nbsp;setting&nbsp;can&nbsp;control&nbsp;which&nbsp;function&nbsp;method&nbsp;in&nbsp;our&nbsp;code&nbsp;will&nbsp;be&nbsp;triggered&nbsp;if&nbsp;there&nbsp;are&nbsp;multiple</span><span style="color: #008000; "><br />#</span><span style="color: #008000; ">&nbsp;spring.cloud.function.definition=supplyLoan</span><span style="color: #008000; "><br /></span><br /><span style="color: #008000; ">#</span><span style="color: #008000; ">&nbsp;Give&nbsp;the&nbsp;autogenerated&nbsp;binding&nbsp;a&nbsp;friendlier&nbsp;name</span><span style="color: #008000; "><br /></span>spring:<br />&nbsp;&nbsp;&nbsp;application:<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;name:&nbsp;loan-check-rabbit<br />&nbsp;&nbsp;&nbsp;banner:<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;location:&nbsp;classpath:/banner-rabbit.txt<br />&nbsp;&nbsp;&nbsp;cloud:<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #008000; ">#</span><span style="color: #008000; ">BindingServiceProperties</span><span style="color: #008000; "><br /></span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;stream:<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #008000; ">#</span><span style="color: #008000; ">StreamFunctionProperties</span><span style="color: #008000; "><br /></span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;function:<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;definition:&nbsp;loadCheckerFunction;loanCheckerDecieder;loanCheckerConsumer;\<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;loanDeclinedConsumer;loanApprovedConsumer;loanCheckerProcessor|functionRouter<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;routing:<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;enabled:&nbsp;true<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #008000; ">#</span><span style="color: #008000; ">BindingProperties</span><span style="color: #008000; "><br /></span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;bindings:<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;loanCheckerProcessor|functionRouter-<span style="color: #0000FF; ">in</span>-0:<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;destination:&nbsp;queue.pretty.log.messages<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;binder:&nbsp;local_rabbit<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;loanApprovedConsumer-<span style="color: #0000FF; ">in</span>-0:<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;destination:&nbsp;load.approved<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;binder:&nbsp;local_rabbit<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;loanDeclinedConsumer-<span style="color: #0000FF; ">in</span>-0:<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;destination:&nbsp;load.declined<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;binder:&nbsp;local_rabbit<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;loanCheckerDecieder-<span style="color: #0000FF; ">in</span>-0:<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;destination:&nbsp;queue.pretty.log.messages.222<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;binder:&nbsp;local_rabbit<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;loanCheckerDecieder-out-0:<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;destination:&nbsp;queue.pretty.approved.messages<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;binder:&nbsp;local_rabbit<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;loanCheckerConsumer-<span style="color: #0000FF; ">in</span>-0:<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;destination:&nbsp;queue.pretty.approved.messages<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;binder:&nbsp;local_rabbit<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #008000; ">#</span><span style="color: #008000; ">BinderProperties</span><span style="color: #008000; "><br /></span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;binders:<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;local_rabbit:<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;type:&nbsp;rabbit<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;environment:<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;spring:<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;rabbitmq:<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;host:&nbsp;10.80.27.69<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;port:&nbsp;5672<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;username:&nbsp;guest<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;password:&nbsp;guest<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;virtual-host:&nbsp;my-virtual-host<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br />logging:<br />&nbsp;&nbsp;&nbsp;level:<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;root:&nbsp;info<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;org.springframework:<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;cloud.function:&nbsp;debug<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #008000; ">#</span><span style="color: #008000; ">retry:&nbsp;debug</span></div><br /><br />LoanCheckConfiguration.java<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: #0000FF; ">package</span>&nbsp;com.paul.testspringcloudstream.loancheck.config;<br /><br /><span style="color: #0000FF; ">import</span>&nbsp;java.util.function.Consumer;<br /><span style="color: #0000FF; ">import</span>&nbsp;java.util.function.Function;<br /><br /><span style="color: #0000FF; ">import</span>&nbsp;org.slf4j.Logger;<br /><span style="color: #0000FF; ">import</span>&nbsp;org.slf4j.LoggerFactory;<br /><span style="color: #0000FF; ">import</span>&nbsp;org.springframework.beans.factory.annotation.Autowired;<br /><span style="color: #0000FF; ">import</span>&nbsp;org.springframework.cloud.function.context.MessageRoutingCallback;<br /><span style="color: #0000FF; ">import</span>&nbsp;org.springframework.cloud.stream.function.StreamBridge;<br /><span style="color: #0000FF; ">import</span>&nbsp;org.springframework.context.annotation.Bean;<br /><span style="color: #0000FF; ">import</span>&nbsp;org.springframework.context.annotation.Configuration;<br /><span style="color: #0000FF; ">import</span>&nbsp;org.springframework.integration.support.MessageBuilder;<br /><span style="color: #0000FF; ">import</span>&nbsp;org.springframework.messaging.Message;<br /><br /><span style="color: #0000FF; ">import</span>&nbsp;com.paul.testspringcloudstream.common.model.Loan;<br /><span style="color: #0000FF; ">import</span>&nbsp;com.paul.testspringcloudstream.common.model.Status;<br /><span style="color: #0000FF; ">import</span>&nbsp;com.paul.testspringcloudstream.loancheck.router.LoanCheckerRouter;<br /><span style="color: #0000FF; ">import</span>&nbsp;com.paul.testspringcloudstream.loancheck.service.LoanProcessor;<br /><span style="color: #0000FF; ">import</span>&nbsp;com.paul.testspringcloudstream.loancheck.service.LoanService;<br /><br />@Configuration<br /><span style="color: #0000FF; ">public</span>&nbsp;<span style="color: #0000FF; ">class</span>&nbsp;LoanCheckConfiguration&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #0000FF; ">private</span>&nbsp;<span style="color: #0000FF; ">static</span>&nbsp;<span style="color: #0000FF; ">final</span>&nbsp;Logger&nbsp;log&nbsp;=&nbsp;LoggerFactory.getLogger(LoanCheckConfiguration.<span style="color: #0000FF; ">class</span>);<br />&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #0000FF; ">private</span>&nbsp;<span style="color: #0000FF; ">static</span>&nbsp;<span style="color: #0000FF; ">final</span>&nbsp;Long&nbsp;MAX_AMOUNT&nbsp;=&nbsp;10000L;<br />&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #0000FF; ">private</span>&nbsp;<span style="color: #0000FF; ">static</span>&nbsp;<span style="color: #0000FF; ">final</span>&nbsp;String&nbsp;LOG_PATTERN&nbsp;=&nbsp;"{}&nbsp;-&nbsp;{}&nbsp;{}&nbsp;for&nbsp;${}&nbsp;for&nbsp;{}";<br />&nbsp;&nbsp;&nbsp;&nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;@Autowired<br />&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #0000FF; ">public</span>&nbsp;<span style="color: #0000FF; ">void</span>&nbsp;test(Consumer&lt;Loan&gt;&nbsp;loanCheckerConsumer)&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;log.info("{}",&nbsp;loanCheckerConsumer.getClass());<br />&nbsp;&nbsp;&nbsp;&nbsp;}<br />&nbsp;&nbsp;&nbsp;&nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;@Bean<br />&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #0000FF; ">public</span>&nbsp;Consumer&lt;Loan&gt;&nbsp;loanCheckerConsumer(){<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #0000FF; ">return</span>&nbsp;loan&nbsp;-&gt;&nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;log.info(LOG_PATTERN,&nbsp;"loanCheckerConsumer",&nbsp;loan.getStatus(),&nbsp;loan.getUuid(),&nbsp;loan.getAmount(),&nbsp;loan.getName());<br />&nbsp;&nbsp;&nbsp;&nbsp;}<br />&nbsp;&nbsp;&nbsp;&nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;@Bean<br />&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #0000FF; ">public</span>&nbsp;Consumer&lt;Loan&gt;&nbsp;loanDeclinedConsumer(){<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #0000FF; ">return</span>&nbsp;loan&nbsp;-&gt;&nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;log.info(LOG_PATTERN,&nbsp;"loanDeclinedConsumer",&nbsp;loan.getStatus(),&nbsp;loan.getUuid(),&nbsp;loan.getAmount(),&nbsp;loan.getName());<br />&nbsp;&nbsp;&nbsp;&nbsp;}<br />&nbsp;&nbsp;&nbsp;&nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;@Bean<br />&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #0000FF; ">public</span>&nbsp;Consumer&lt;Loan&gt;&nbsp;loanApprovedConsumer(){<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #0000FF; ">return</span>&nbsp;loan&nbsp;-&gt;&nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;log.info(LOG_PATTERN,&nbsp;"loanApprovedConsumer",&nbsp;loan.getStatus(),&nbsp;loan.getUuid(),&nbsp;loan.getAmount(),&nbsp;loan.getName());<br />&nbsp;&nbsp;&nbsp;&nbsp;}<br />&nbsp;&nbsp;&nbsp;&nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;@Bean<br />&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #0000FF; ">public</span>&nbsp;MessageRoutingCallback&nbsp;loanCheckerRouter()&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #0000FF; ">return</span>&nbsp;<span style="color: #0000FF; ">new</span>&nbsp;LoanCheckerRouter();<br />&nbsp;&nbsp;&nbsp;&nbsp;}<br />&nbsp;&nbsp;&nbsp;&nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;@Bean<br />&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #0000FF; ">public</span>&nbsp;Function&lt;Loan,&nbsp;Loan&gt;&nbsp;loanCheckerProcessor(<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;LoanService&nbsp;loanService<br />&nbsp;&nbsp;&nbsp;&nbsp;){<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #0000FF; ">return</span>&nbsp;loan&nbsp;-&gt;&nbsp;loanService.check(loan);<br />&nbsp;&nbsp;&nbsp;&nbsp;}<br />&nbsp;&nbsp;&nbsp;&nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;@Bean<br />&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #0000FF; ">public</span>&nbsp;Function&lt;Loan,&nbsp;Message&lt;Loan&gt;&gt;&nbsp;loanCheckerProcessorBak(<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;LoanService&nbsp;loanService<br />&nbsp;&nbsp;&nbsp;&nbsp;){<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #0000FF; ">return</span>&nbsp;loan&nbsp;-&gt;&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Loan&nbsp;result&nbsp;=&nbsp;loanService.check(loan);<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;String&nbsp;sendTo&nbsp;=&nbsp;Status.DECLINED.name().equals(result.getStatus())&nbsp;?&nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;LoanProcessor.DECLINED_OUT&nbsp;:&nbsp;LoanProcessor.APPROVED_OUT;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #0000FF; ">return</span>&nbsp;MessageBuilder.withPayload(result)<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;.setHeader("spring.cloud.stream.sendto.destination",&nbsp;sendTo)<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;.build();<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;};<br />&nbsp;&nbsp;&nbsp;&nbsp;}<br />&nbsp;&nbsp;&nbsp;&nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;@Bean<br />&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #0000FF; ">public</span>&nbsp;Consumer&lt;Loan&gt;&nbsp;loanCheckerDecieder(StreamBridge&nbsp;streamBridge){<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #0000FF; ">return</span>&nbsp;loan&nbsp;-&gt;&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;log.info(LOG_PATTERN,&nbsp;"loanCheckerDecieder",&nbsp;loan.getStatus(),&nbsp;loan.getUuid(),&nbsp;loan.getAmount(),&nbsp;loan.getName());<br /><br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #0000FF; ">if</span>&nbsp;(loan.getAmount()&nbsp;&gt;&nbsp;MAX_AMOUNT)&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;loan.setStatus(Status.DECLINED.name());<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;streamBridge.send(LoanProcessor.DECLINED_OUT,&nbsp;"local_rabbit",&nbsp;loan);<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}&nbsp;<span style="color: #0000FF; ">else</span>&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;loan.setStatus(Status.APPROVED.name());<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;streamBridge.send(LoanProcessor.APPROVED_OUT,&nbsp;"local_rabbit",&nbsp;loan);<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br /><br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;log.info(LOG_PATTERN,&nbsp;"loanCheckerDecieder",&nbsp;loan.getStatus(),&nbsp;loan.getUuid(),&nbsp;loan.getAmount(),&nbsp;loan.getName());<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;};<br />&nbsp;&nbsp;&nbsp;&nbsp;}<br /><br />}</div><br /><br />LoanCheckerRouter.java，将路由条件统一在此处<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: #0000FF; ">package</span>&nbsp;com.paul.testspringcloudstream.loancheck.router;<br /><br /><span style="color: #0000FF; ">import</span>&nbsp;org.slf4j.Logger;<br /><span style="color: #0000FF; ">import</span>&nbsp;org.slf4j.LoggerFactory;<br /><span style="color: #0000FF; ">import</span>&nbsp;org.springframework.cloud.function.context.MessageRoutingCallback;<br /><span style="color: #0000FF; ">import</span>&nbsp;org.springframework.messaging.Message;<br /><br /><span style="color: #0000FF; ">import</span>&nbsp;com.paul.testspringcloudstream.common.model.Loan;<br /><span style="color: #0000FF; ">import</span>&nbsp;com.paul.testspringcloudstream.common.model.Status;<br /><br /><span style="color: #0000FF; ">public</span>&nbsp;<span style="color: #0000FF; ">class</span>&nbsp;LoanCheckerRouter&nbsp;<span style="color: #0000FF; ">implements</span>&nbsp;MessageRoutingCallback{<br />&nbsp;&nbsp;&nbsp;&nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #0000FF; ">private</span>&nbsp;<span style="color: #0000FF; ">static</span>&nbsp;<span style="color: #0000FF; ">final</span>&nbsp;Logger&nbsp;log&nbsp;=&nbsp;LoggerFactory.getLogger(LoanCheckerRouter.<span style="color: #0000FF; ">class</span>);<br /><br />&nbsp;&nbsp;&nbsp;&nbsp;@Override<br />&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #0000FF; ">public</span>&nbsp;String&nbsp;functionDefinition(Message&lt;?&gt;&nbsp;message)&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br /><span style="color: #008000; ">//</span><span style="color: #008000; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;byte[]&nbsp;resultByte&nbsp;=&nbsp;(byte[])message.getPayload();<br /></span><span style="color: #008000; ">//</span><span style="color: #008000; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;String&nbsp;resultString&nbsp;=&nbsp;new&nbsp;String(resultByte);<br /></span><span style="color: #008000; ">//</span><span style="color: #008000; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br /></span><span style="color: #008000; ">//</span><span style="color: #008000; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return&nbsp;"loanDeclinedConsumer";</span><span style="color: #008000; "><br /></span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Loan&nbsp;result&nbsp;=&nbsp;(Loan)message.getPayload();<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;log.info("Loan&nbsp;status:&nbsp;{}",&nbsp;result.getStatus());<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #0000FF; ">return</span>&nbsp;Status.DECLINED.name().equals(result.getStatus())&nbsp;?&nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;"loanDeclinedConsumer"&nbsp;:&nbsp;"loanApprovedConsumer";<br />&nbsp;&nbsp;&nbsp;&nbsp;}<br /><br />}</div><img src ="http://www.blogjava.net/paulwong/aggbug/436050.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-11-15 14:46 <a href="http://www.blogjava.net/paulwong/archive/2021/11/15/436050.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>EVEN DRIVEN - SPRING CLOUD STREAM 3.x - Functional Programming Model</title><link>http://www.blogjava.net/paulwong/archive/2021/11/10/436035.html</link><dc:creator>paulwong</dc:creator><author>paulwong</author><pubDate>Wed, 10 Nov 2021 07:10:00 GMT</pubDate><guid>http://www.blogjava.net/paulwong/archive/2021/11/10/436035.html</guid><wfw:comment>http://www.blogjava.net/paulwong/comments/436035.html</wfw:comment><comments>http://www.blogjava.net/paulwong/archive/2021/11/10/436035.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/paulwong/comments/commentRss/436035.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/paulwong/services/trackbacks/436035.html</trackback:ping><description><![CDATA[<div>SPRING CLOUD STREAM 3.x&nbsp;版本时，之前的一些编程模式，如@Enablebindding，@StreamListenner等注释被废弃了，这是由于一些框架的代码必需由用户编写，如配置框架用的Input MessageChannel，Output&nbsp; MessageChannel，连接MessageHandler与MessageChannel等，被视为不必要的动作。为了简化用户代码，于是推出Functional Programming Model。<br /><br />引入了新名词：Supplier、Function与Consumer。实际上这几个类可视为Adapter，如果之前已经有存在的Service类，且方法名为各种各样，可以重新包装成Supplier、Function与Consumer，并在固定的方法名：apply/get/accept中调用Service的方法。<br /><br /><h2>Supplier</h2>当在配置文件中注入此类型的Bean，并在spring.cloud.stream.function.definition加入此Bean的名称，SPRING CLOUD STREAM就会帮你生成一个Output&nbsp; MessageChannel，并连接上此Bean，后续只需要在BINDDING中加入对应的Destination Name，即可向BROKER发消息了。<br /><br /><h2>Consumer</h2>当在配置文件中注入此类型的Bean，并在spring.cloud.stream.function.definition加入此Bean的名称，SPRING CLOUD STREAM就会帮你生成一个Input&nbsp; MessageChannel，并连接上此Bean，后续只需要在BINDDING中加入对应的Destination Name，即可收到BROKER推送关于此Destination的消息了。<br /></div><h2>Function</h2>当在配置文件中注入此类型的Bean，并在spring.cloud.stream.function.definition加入此Bean的名称，SPRING CLOUD STREAM就会帮你生成一个Input和Output&nbsp; MessageChannel，并连接上此Bean，后续只需要在BINDDING中分别对Input和Output&nbsp;MessageChannel加入对应的Destination Name1/Name2，即可收到BROKER推送关于此Destination的消息，也可以向BROKER发消息了。<br /><br /><h2>与SPRING INTEGRATION的整合</h2>如果要对消息进行复杂处理，如拆分消息、聚合消息、IF ELSE消息等，就要借助SPRING INTEGRATION了。<br /><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 />-->@Bean<br />&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #0000FF; ">public</span>&nbsp;IntegrationFlow&nbsp;upperCaseFlow(LoanService&nbsp;loanService)&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #0000FF; ">return</span>&nbsp;IntegrationFlows<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #008000; ">//</span><span style="color: #008000; ">turn&nbsp;this&nbsp;IntegrationFlow&nbsp;as&nbsp;a&nbsp;gateway,&nbsp;here&nbsp;is&nbsp;a&nbsp;Function&nbsp;interface&nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #008000; ">//</span><span style="color: #008000; ">with&nbsp;loadCheckerFunction&nbsp;as&nbsp;bean&nbsp;name</span><span style="color: #008000; "><br /></span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;.from(LoadCheckerFunction.<span style="color: #0000FF; ">class</span>,&nbsp;gateway&nbsp;-&gt;&nbsp;gateway.beanName("loadCheckerFunction"))<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;.handle(loanService,&nbsp;"check")<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;.logAndReply(LoggingHandler.Level.WARN);<br />&nbsp;&nbsp;&nbsp;&nbsp;}<br /><br />&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #0000FF; ">public</span>&nbsp;<span style="color: #0000FF; ">interface</span>&nbsp;LoadCheckerFunction&nbsp;<span style="color: #0000FF; ">extends</span>&nbsp;Function&lt;Loan,&nbsp;Loan&gt;{<br /><br />&nbsp;&nbsp;&nbsp;&nbsp;}</div><br />IntegrationFlows.from(Class&lt;?&gt; serviceInterface)是可以将本IntegrationFlow包装成serviceInterface的实现类，如果调用此接口，最终会返回IntegrationFlow最后一个步骤的实体，如果这个serviceInterface是Function的话，刚好和SPRING CLOUD STREAM对接上。<br /><br />后续在spring.cloud.stream.function.definition加入此Bean的名称loadCheckerFunction，SPRING CLOUD STREAM就会帮你生成一个Input和Output&nbsp; MessageChannel，并连接上此Bean，再在BINDDING中分别对Input和Output&nbsp;MessageChannel加入对应的Destination Name1/Name2，即可收到BROKER推送关于此Destination的消息，也可以向BROKER发消息。<br /><br />application.yaml<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; ">&nbsp;This&nbsp;setting&nbsp;can&nbsp;increase&nbsp;or&nbsp;decrease&nbsp;the&nbsp;rate&nbsp;of&nbsp;message&nbsp;production&nbsp;(1000&nbsp;=&nbsp;1s)<br />#&nbsp;spring.cloud.stream.poller.fixed-delay=1000<br /><br />#&nbsp;This&nbsp;setting&nbsp;can&nbsp;control&nbsp;which&nbsp;function&nbsp;method&nbsp;in&nbsp;our&nbsp;code&nbsp;will&nbsp;be&nbsp;triggered&nbsp;if&nbsp;there&nbsp;are&nbsp;multiple<br />#&nbsp;spring.cloud.function.definition=supplyLoan<br /><br />#&nbsp;Give&nbsp;the&nbsp;autogenerated&nbsp;binding&nbsp;a&nbsp;friendlier&nbsp;name</span><span style="color: #008000; "><br /></span>spring:<br />&nbsp;&nbsp;&nbsp;application:<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;name:&nbsp;loan-check-rabbit<br />&nbsp;&nbsp;&nbsp;banner:<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;location:&nbsp;classpath:/banner-rabbit.txt<br />&nbsp;&nbsp;&nbsp;cloud:<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;stream:<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;function.definition:&nbsp;loadCheckerFunction<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #008000; ">#</span><span style="color: #008000; ">BindingProperties</span><span style="color: #008000; "><br /></span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;bindings:<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;loadCheckerFunction-in-<span style="color: #800000; ">0</span>:<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;destination:&nbsp;queue.pretty.<span style="color: #0000FF; ">log</span>.messages<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;binder:&nbsp;local_rabbit<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;loadCheckerFunction-out-<span style="color: #800000; ">0</span>:<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;destination:&nbsp;queue.pretty.approved.messages<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;binder:&nbsp;local_rabbit<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #008000; ">#</span><span style="color: #008000; ">BinderProperties</span><span style="color: #008000; "><br /></span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;binders:<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;local_rabbit:<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;type:&nbsp;rabbit<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;environment:<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;spring:<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;rabbitmq:<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;host:&nbsp;<span style="color: #800000; ">10.80</span>.<span style="color: #800000; ">27.69</span><br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;port:&nbsp;<span style="color: #800000; ">5672</span><br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;username:&nbsp;guest<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;password:&nbsp;guest<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;virtual-host:&nbsp;<span style="color: #0000FF; ">my</span>-virtual-host</div><br /><h2>Reference</h2><a href="https://spring.io/blog/2019/10/25/spring-cloud-stream-and-spring-integration" target="_blank">https://spring.io/blog/2019/10/25/spring-cloud-stream-and-spring-integration</a><img src ="http://www.blogjava.net/paulwong/aggbug/436035.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-11-10 15:10 <a href="http://www.blogjava.net/paulwong/archive/2021/11/10/436035.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>EVEN DRIVEN - SPRING CLOUD STREAM - SPRING CLOUD微服务的EVEN DRIVEN框架</title><link>http://www.blogjava.net/paulwong/archive/2021/11/05/436031.html</link><dc:creator>paulwong</dc:creator><author>paulwong</author><pubDate>Fri, 05 Nov 2021 06:58:00 GMT</pubDate><guid>http://www.blogjava.net/paulwong/archive/2021/11/05/436031.html</guid><wfw:comment>http://www.blogjava.net/paulwong/comments/436031.html</wfw:comment><comments>http://www.blogjava.net/paulwong/archive/2021/11/05/436031.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/paulwong/comments/commentRss/436031.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/paulwong/services/trackbacks/436031.html</trackback:ping><description><![CDATA[通常微服务应用之间的通信是通过HTTP调用，吞吐性不建都高，高并发的场景建议使用EVENT DRIVEN的框架，即使用MESSAGE通信。<br /><br />即A微服务应用将数据发送到MESSAGE BROKER中的某个DESTINATION，此DESTINATION是广播型，非点对点型。B微服务应用订阅此DESTINATION，当有新MESSAGE到达此DESTINATION时，MESSAGE BROKER会将此MESSAGE推送给B应用。所有对此MESSAGE有需要的应用均可订阅，从而收到此MESSAGE。<br /><br />SPRING CLOUD&nbsp;中EVENT DRIVEN的框架就是SPRING CLOUD STREAM。其底层是使用SPRING INTEGRATION实现。<br /><br />SPRING CLOUD STREAM有以下新名词：<br /><br /><ul><li>BINDER：</li></ul>是对MESSAGE BROKER操作方法的抽象，即应用通过此BINDER操作MESSAGE BROKER。目前只实现了RABITMQ和KAFKA。<br /><ul><li>CHANNEL</li></ul>MESSAGE从SPRING CLOUD STREAM传给应用或相反是通过CHANNEL传递的，这点和SPRING INTEGRATION是一样的。<br /><ul><li>SOURCE</li></ul>MESSAGE从应用传给SPRING CLOUD STREAM的CHANNEL，叫@INPUT，包含这种CHANNEL的接口叫SOURCE。<br /><ul><li>SINK</li></ul>MESSAGE从SPRING CLOUD STREAM传给应用的CHANNEL，叫@OUPUT，包含这种CHANNEL的接口叫SINK。<br /><ul><li>BIDDING</li></ul>绑定哪个@INPUT或哪个@OUPUT与哪个DESTINATION发送或接收关系的MAPPING。<br /><ul><li>EnableBinding</li></ul>应用启动时就会建立EnableBinding指定的接口中的CHANNEL<br /><ul><li>消费者群组</li></ul>默认下如果同一个应用部署了多个实例，则每个实例都会收到MESSAGE，这时如果设置了消费者群组名称，则同一个名称下的多个实例，只有一个能收到MESSAGE。<br /><ul><li>PARTITION</li></ul>如果为MESSAGE指定规则，如MESSAGE某个字段值以A开头为一个规则，以B开头为一个规则，那么以A开头的MESSAGE会放到同一个分区中。<br /><br />这样使用就很简单了，只要取得OUTPUT CHANNEL，就可以发送MESSAGE，将代码关联到INPUT CHANNEL，就能在收到MESSAGE时，相关代码就会被执行。<br /><br /><img src ="http://www.blogjava.net/paulwong/aggbug/436031.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-11-05 14:58 <a href="http://www.blogjava.net/paulwong/archive/2021/11/05/436031.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>SPRING CLOUD ALIBABA</title><link>http://www.blogjava.net/paulwong/archive/2021/05/11/435871.html</link><dc:creator>paulwong</dc:creator><author>paulwong</author><pubDate>Tue, 11 May 2021 06:04:00 GMT</pubDate><guid>http://www.blogjava.net/paulwong/archive/2021/05/11/435871.html</guid><wfw:comment>http://www.blogjava.net/paulwong/comments/435871.html</wfw:comment><comments>http://www.blogjava.net/paulwong/archive/2021/05/11/435871.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/paulwong/comments/commentRss/435871.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/paulwong/services/trackbacks/435871.html</trackback:ping><description><![CDATA[<a href="https://mp.weixin.qq.com/mp/appmsgalbum?__biz=MzAwMTk4NjM1MA==&amp;action=getalbum&amp;album_id=1418244755364134912&amp;scene=173&amp;from_msgid=2247484698&amp;from_itemidx=1&amp;count=3&amp;nolastread=1#wechat_redirect" target="_blank">https://mp.weixin.qq.com/mp/appmsgalbum?__biz=MzAwMTk4NjM1MA==&amp;action=getalbum&amp;album_id=1418244755364134912&amp;scene=173&amp;from_msgid=2247484698&amp;from_itemidx=1&amp;count=3&amp;nolastread=1#wechat_redirect</a><br /><br /><span style="color: #666666; font-family: georgia, verdana, arial, sans-serif; font-size: medium; background-color: #ffffff;">SpringCloud alibaba实战系列文章汇总</span><br style="color: #666666; font-family: georgia, verdana, arial, sans-serif; font-size: medium;" /><a href="https://segmentfault.com/a/1190000023541535?utm_source=sf-similar-article" target="_blank" style="color: #993300; font-family: georgia, verdana, arial, sans-serif; font-size: medium;">https://segmentfault.com/a/1190000023541535?utm_source=sf-similar-article</a><img src ="http://www.blogjava.net/paulwong/aggbug/435871.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-05-11 14:04 <a href="http://www.blogjava.net/paulwong/archive/2021/05/11/435871.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>SPRING CLOUD JWT资源</title><link>http://www.blogjava.net/paulwong/archive/2017/03/24/432401.html</link><dc:creator>paulwong</dc:creator><author>paulwong</author><pubDate>Fri, 24 Mar 2017 15:11:00 GMT</pubDate><guid>http://www.blogjava.net/paulwong/archive/2017/03/24/432401.html</guid><wfw:comment>http://www.blogjava.net/paulwong/comments/432401.html</wfw:comment><comments>http://www.blogjava.net/paulwong/archive/2017/03/24/432401.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/paulwong/comments/commentRss/432401.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/paulwong/services/trackbacks/432401.html</trackback:ping><description><![CDATA[<br /><a href="https://github.com/thomas-kendall/trivia-microservices" target="_blank">https://github.com/thomas-kendall/trivia-microservices</a><br /><br /><br />一个Spring Boot， JWT，AugularJS接口安全验证的简单例子<br /><a href="http://blog.csdn.net/offbye/article/details/47607711" target="_blank">http://blog.csdn.net/offbye/article/details/47607711</a><br /><br /><br /><br /><a href="https://github.com/tuanngda/spring-boot-oauth2-demo" target="_blank">https://github.com/tuanngda/spring-boot-oauth2-demo</a><br /><br /><br />Spring Oauth2 with JWT Sample<br /><a href="http://www.tuicool.com/articles/EjUFZj7" target="_blank">http://www.tuicool.com/articles/EjUFZj7</a><br /><br /><br /><a href="http://stackoverflow.com/questions/38156213/spring-cloud-zuul-jwt-for-value-reference-tokens" target="_blank">http://stackoverflow.com/questions/38156213/spring-cloud-zuul-jwt-for-value-reference-tokens</a><img src ="http://www.blogjava.net/paulwong/aggbug/432401.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> 2017-03-24 23:11 <a href="http://www.blogjava.net/paulwong/archive/2017/03/24/432401.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></channel></rss>