锘??xml version="1.0" encoding="utf-8" standalone="yes"?>久久久无码精品亚洲日韩蜜臀浪潮 ,亚洲性日韩精品国产一区二区,亚洲国产精品一区二区三区在线观看http://www.tkk7.com/paulwong/category/55116.htmlzh-cnWed, 01 Dec 2021 16:36:18 GMTWed, 01 Dec 2021 16:36:18 GMT60SPRING CLOUD - REACTIVE FEIGNhttp://www.tkk7.com/paulwong/archive/2021/12/01/436078.htmlpaulwongpaulwongWed, 01 Dec 2021 08:45:00 GMThttp://www.tkk7.com/paulwong/archive/2021/12/01/436078.htmlhttp://www.tkk7.com/paulwong/comments/436078.htmlhttp://www.tkk7.com/paulwong/archive/2021/12/01/436078.html#Feedback0http://www.tkk7.com/paulwong/comments/commentRss/436078.htmlhttp://www.tkk7.com/paulwong/services/trackbacks/436078.html
pom.xml
<dependency>
    <groupId>com.playtika.reactivefeign</groupId>
    <artifactId>feign-reactor-spring-cloud-starter</artifactId>
    <version>3.1.2</version>
    <type>pom</type>
</dependency>


LoanDecisionClientReactive.java
package com.paul.testspringcloudstream.loancheck.service;

import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;

import com.paul.testspringcloudstream.common.model.Loan;

import reactivefeign.spring.config.ReactiveFeignClient;
import reactor.core.publisher.Mono;

@ReactiveFeignClient(name = "loan-decision")
public interface LoanDecisionClientReactive {
    
    @PostMapping("/loan-decision")
    public Mono<Loan> getDecision(@RequestBody Loan loan);

}

LoanCheckConfiguration.java
@Configuration
@Import({
    MongoDbConsumerConfiguration.class,
})
@EnableDiscoveryClient
@EnableReactiveFeignClients("com.paul.testspringcloudstream.loancheck.service")
public class LoanCheckConfiguration {
}


浣跨敤鍚宖eign
@Autowired
private LoanDecisionClientReactive loanDecisionClientReactive;

Reference
https://blog.csdn.net/LCBUSHIHAHA/article/details/113817966

瀹樻柟SAMPLE
https://github.com/kptfh/feign-reactive-sample

paulwong 2021-12-01 16:45 鍙戣〃璇勮
]]>
Spring bootstrap.yml 涓嶇鐢紝澶辨晥瑙e喅鏂規錛坰pring cloud 2020.x.x錛?/title><link>http://www.tkk7.com/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.tkk7.com/paulwong/archive/2021/12/01/436076.html</guid><wfw:comment>http://www.tkk7.com/paulwong/comments/436076.html</wfw:comment><comments>http://www.tkk7.com/paulwong/archive/2021/12/01/436076.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.tkk7.com/paulwong/comments/commentRss/436076.html</wfw:commentRss><trackback:ping>http://www.tkk7.com/paulwong/services/trackbacks/436076.html</trackback:ping><description><![CDATA[<div>鍗囩駭spring cloud鐗堟湰涔嬪悗鍙戠幇bootstrap.yml 澶辨晥浜嗭紝闃呰瀹樻柟鏂囨。寰楃煡錛岄渶瑕佹柊澧炰竴涓紩鐢ㄦ潵寮鍚痓ootstrap.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; "><</span><span style="color: #800000; ">dependency</span><span style="color: #0000FF; ">></span><br />    <span style="color: #0000FF; "><</span><span style="color: #800000; ">groupId</span><span style="color: #0000FF; ">></span>org.springframework.cloud<span style="color: #0000FF; "></</span><span style="color: #800000; ">groupId</span><span style="color: #0000FF; ">></span><br />    <span style="color: #0000FF; "><</span><span style="color: #800000; ">artifactId</span><span style="color: #0000FF; ">></span>spring-cloud-starter-bootstrap<span style="color: #0000FF; "></</span><span style="color: #800000; ">artifactId</span><span style="color: #0000FF; ">></span><br /><span style="color: #0000FF; "></</span><span style="color: #800000; ">dependency</span><span style="color: #0000FF; ">></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.tkk7.com/paulwong/aggbug/436076.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.tkk7.com/paulwong/" target="_blank">paulwong</a> 2021-12-01 10:29 <a href="http://www.tkk7.com/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 Suppliershttp://www.tkk7.com/paulwong/archive/2021/11/23/436060.htmlpaulwongpaulwongTue, 23 Nov 2021 02:03:00 GMThttp://www.tkk7.com/paulwong/archive/2021/11/23/436060.htmlhttp://www.tkk7.com/paulwong/comments/436060.htmlhttp://www.tkk7.com/paulwong/archive/2021/11/23/436060.html#Feedback0http://www.tkk7.com/paulwong/comments/commentRss/436060.htmlhttp://www.tkk7.com/paulwong/services/trackbacks/436060.htmlSupplier 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 Function or Consumer beans. This means that you often need a way to trigger them to be executed periodically.

For imperative functions the framework by default "polls" a Supplier function every 1 second, but that duration is configurable using the spring.cloud.stream.poller.fixed-delay property.

However, for reactive functions supplying a Flux 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 Supplier because you are producing a finite stream of events you can still do so using @PollableBean. This annotation then allows you to configure how often the function is triggered using the same spring.cloud.stream.poller.fixed-delay property!

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.

Example code:

@PollableBean 
public Supplier<Flux<String>> stringSupplier() { return () -> Flux.just("foo","bar","baz"); }


Reference:
https://solace.community/discussion/360/pollablebean-for-reactive-suppliers-in-spring-cloud-stream

paulwong 2021-11-23 10:03 鍙戣〃璇勮
]]>
EVEN DRIVEN - SPRING CLOUD STREAM - 浠庨潪SCS緇勪歡鍙戦佹秷鎭埌SCS緇勪歡http://www.tkk7.com/paulwong/archive/2021/11/19/436054.htmlpaulwongpaulwongFri, 19 Nov 2021 03:47:00 GMThttp://www.tkk7.com/paulwong/archive/2021/11/19/436054.htmlhttp://www.tkk7.com/paulwong/comments/436054.htmlhttp://www.tkk7.com/paulwong/archive/2021/11/19/436054.html#Feedback0http://www.tkk7.com/paulwong/comments/commentRss/436054.htmlhttp://www.tkk7.com/paulwong/services/trackbacks/436054.html
閭d箞鍦⊿PRING CLOUD STREAM涓紝濡傛灉瑕佷粠闈濻PRING CLOUD STREAM浠g爜鍙戦丮ESSAGE鍒癝PRING CLOUD STREAM紼嬪簭錛岄氬父灝辮鍏堥氱煡妗嗘灦鑷姩鐢熸垚涓涓猄OURCE銆?br />
application.property
spring.cloud.stream.source=supplier
spring.cloud.stream.bindings.supplier-out-0.destination=notification-events

java
streamBridge.send("supplier-out-0", userDto);

Reference:
https://blog.devgenius.io/event-driven-microservices-with-spring-cloud-stream-e034eee3f394


paulwong 2021-11-19 11:47 鍙戣〃璇勮
]]>
EVEN DRIVEN - SPRING CLOUD STREAM - Error Handlinghttp://www.tkk7.com/paulwong/archive/2021/11/17/436052.htmlpaulwongpaulwongWed, 17 Nov 2021 02:50:00 GMThttp://www.tkk7.com/paulwong/archive/2021/11/17/436052.htmlhttp://www.tkk7.com/paulwong/comments/436052.htmlhttp://www.tkk7.com/paulwong/archive/2021/11/17/436052.html#Feedback0http://www.tkk7.com/paulwong/comments/commentRss/436052.htmlhttp://www.tkk7.com/paulwong/services/trackbacks/436052.html
@ServiceActivator(inputChannel = "my-destination.my-group.errors")
    public void handleError(ErrorMessage message) {
        Throwable throwable = message.getPayload();
        log.error("鎴幏寮傚父", throwable);

        Message<?> originalMessage = message.getOriginalMessage();
        assert originalMessage != null;

        log.info("鍘熷娑堟伅浣?nbsp;= {}", new String((byte[]) originalMessage.getPayload()));
    }

璇︽儏鍙傝冿細
https://www.itmuch.com/spring-cloud/spring-cloud-stream-error-handling/

paulwong 2021-11-17 10:50 鍙戣〃璇勮
]]>
EVEN DRIVEN - SPRING CLOUD STREAM - Function Componenthttp://www.tkk7.com/paulwong/archive/2021/11/15/436051.htmlpaulwongpaulwongMon, 15 Nov 2021 09:40:00 GMThttp://www.tkk7.com/paulwong/archive/2021/11/15/436051.htmlhttp://www.tkk7.com/paulwong/comments/436051.htmlhttp://www.tkk7.com/paulwong/archive/2021/11/15/436051.html#Feedback0http://www.tkk7.com/paulwong/comments/commentRss/436051.htmlhttp://www.tkk7.com/paulwong/services/trackbacks/436051.html
緇勪歡鍦板潃錛?br />https://github.com/spring-cloud/stream-applications/tree/main/functions

鐗規畩緇勪歡錛屽皢FUNCTION鍙樻垚HTTP ENDPOINTS錛?br />https://github.com/spring-cloud/spring-cloud-function/tree/main/spring-cloud-starter-function-web
https://github.com/spring-cloud/spring-cloud-function/tree/main/spring-cloud-starter-function-webflux



paulwong 2021-11-15 17:40 鍙戣〃璇勮
]]>
EVEN DRIVEN - SPRING CLOUD STREAM - Routing Functionhttp://www.tkk7.com/paulwong/archive/2021/11/15/436050.htmlpaulwongpaulwongMon, 15 Nov 2021 06:46:00 GMThttp://www.tkk7.com/paulwong/archive/2021/11/15/436050.htmlhttp://www.tkk7.com/paulwong/comments/436050.htmlhttp://www.tkk7.com/paulwong/archive/2021/11/15/436050.html#Feedback0http://www.tkk7.com/paulwong/comments/commentRss/436050.htmlhttp://www.tkk7.com/paulwong/services/trackbacks/436050.html瀵規帴RoutingFunction鍙彂閫佹秷鎭埌鍏跺閮―ESTINATION涓垨鐢?#8220;锝?#8221;榪炴帴絎﹁繛鎺ャ?br />
application.yaml
# This setting can increase or decrease the rate of message production (1000 = 1s)
#
 spring.cloud.stream.poller.fixed-delay=1000
#
 DefaultPollerProperties

# This setting can control which function method in our code will be triggered if there are multiple
#
 spring.cloud.function.definition=supplyLoan

# Give the autogenerated binding a friendlier name
spring:
   application:
      name: loan-check-rabbit
   banner:
      location: classpath:/banner-rabbit.txt
   cloud:
      #BindingServiceProperties
      stream:
         #StreamFunctionProperties
         function:
            definition: loadCheckerFunction;loanCheckerDecieder;loanCheckerConsumer;\
                        loanDeclinedConsumer;loanApprovedConsumer;loanCheckerProcessor|functionRouter
            routing:
               enabled: true
         #BindingProperties
         bindings:
            loanCheckerProcessor|functionRouter-in-0:
               destination: queue.pretty.log.messages
               binder: local_rabbit
               
            loanApprovedConsumer-in-0:
               destination: load.approved
               binder: local_rabbit
            loanDeclinedConsumer-in-0:
               destination: load.declined
               binder: local_rabbit
               
            loanCheckerDecieder-in-0:
               destination: queue.pretty.log.messages.222
               binder: local_rabbit
            loanCheckerDecieder-out-0:
               destination: queue.pretty.approved.messages
               binder: local_rabbit
            loanCheckerConsumer-in-0:
               destination: queue.pretty.approved.messages
               binder: local_rabbit
         #BinderProperties
         binders:
            local_rabbit:
               type: rabbit
               environment:
                  spring:
                     rabbitmq:
                        host: 10.80.27.69
                        port: 5672
                        username: guest
                        password: guest
                        virtual-host: my-virtual-host
                        
                        
logging:
   level:
      root: info
      org.springframework:
         cloud.function: debug
         #retry: debug


LoanCheckConfiguration.java
package com.paul.testspringcloudstream.loancheck.config;

import java.util.function.Consumer;
import java.util.function.Function;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.function.context.MessageRoutingCallback;
import org.springframework.cloud.stream.function.StreamBridge;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.integration.support.MessageBuilder;
import org.springframework.messaging.Message;

import com.paul.testspringcloudstream.common.model.Loan;
import com.paul.testspringcloudstream.common.model.Status;
import com.paul.testspringcloudstream.loancheck.router.LoanCheckerRouter;
import com.paul.testspringcloudstream.loancheck.service.LoanProcessor;
import com.paul.testspringcloudstream.loancheck.service.LoanService;

@Configuration
public class LoanCheckConfiguration {
    
    private static final Logger log = LoggerFactory.getLogger(LoanCheckConfiguration.class);
    private static final Long MAX_AMOUNT = 10000L;
    private static final String LOG_PATTERN = "{} - {} {} for ${} for {}";
    
    @Autowired
    public void test(Consumer<Loan> loanCheckerConsumer) {
        log.info("{}", loanCheckerConsumer.getClass());
    }
    
    
    @Bean
    public Consumer<Loan> loanCheckerConsumer(){
        return loan -> 
            log.info(LOG_PATTERN, "loanCheckerConsumer", loan.getStatus(), loan.getUuid(), loan.getAmount(), loan.getName());
    }
    
    @Bean
    public Consumer<Loan> loanDeclinedConsumer(){
        return loan -> 
            log.info(LOG_PATTERN, "loanDeclinedConsumer", loan.getStatus(), loan.getUuid(), loan.getAmount(), loan.getName());
    }
    
    @Bean
    public Consumer<Loan> loanApprovedConsumer(){
        return loan -> 
            log.info(LOG_PATTERN, "loanApprovedConsumer", loan.getStatus(), loan.getUuid(), loan.getAmount(), loan.getName());
    }
    
    @Bean
    public MessageRoutingCallback loanCheckerRouter() {
        return new LoanCheckerRouter();
    }
    
    @Bean
    public Function<Loan, Loan> loanCheckerProcessor(
        LoanService loanService
    ){
        return loan -> loanService.check(loan);
    }
    
    @Bean
    public Function<Loan, Message<Loan>> loanCheckerProcessorBak(
        LoanService loanService
    ){
        return loan -> {
            Loan result = loanService.check(loan);
            String sendTo = Status.DECLINED.name().equals(result.getStatus()) ? 
                        LoanProcessor.DECLINED_OUT : LoanProcessor.APPROVED_OUT;
            
            return MessageBuilder.withPayload(result)
                        .setHeader("spring.cloud.stream.sendto.destination", sendTo)
                        .build();
        };
    }
    
    @Bean
    public Consumer<Loan> loanCheckerDecieder(StreamBridge streamBridge){
        return loan -> {
            log.info(LOG_PATTERN, "loanCheckerDecieder", loan.getStatus(), loan.getUuid(), loan.getAmount(), loan.getName());

            if (loan.getAmount() > MAX_AMOUNT) {
                loan.setStatus(Status.DECLINED.name());
                streamBridge.send(LoanProcessor.DECLINED_OUT, "local_rabbit", loan);
            } else {
                loan.setStatus(Status.APPROVED.name());
                streamBridge.send(LoanProcessor.APPROVED_OUT, "local_rabbit", loan);
            }

            log.info(LOG_PATTERN, "loanCheckerDecieder", loan.getStatus(), loan.getUuid(), loan.getAmount(), loan.getName());
        };
    }

}


LoanCheckerRouter.java錛屽皢璺敱鏉′歡緇熶竴鍦ㄦ澶?br />
package com.paul.testspringcloudstream.loancheck.router;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.cloud.function.context.MessageRoutingCallback;
import org.springframework.messaging.Message;

import com.paul.testspringcloudstream.common.model.Loan;
import com.paul.testspringcloudstream.common.model.Status;

public class LoanCheckerRouter implements MessageRoutingCallback{
    
    private static final Logger log = LoggerFactory.getLogger(LoanCheckerRouter.class);

    @Override
    public String functionDefinition(Message<?> message) {
        
//        byte[] resultByte = (byte[])message.getPayload();
//        String resultString = new String(resultByte);
//        
//        return "loanDeclinedConsumer";
        
        Loan result = (Loan)message.getPayload();
        
        log.info("Loan status: {}", result.getStatus());
        
        return Status.DECLINED.name().equals(result.getStatus()) ? 
                    "loanDeclinedConsumer" : "loanApprovedConsumer";
    }

}


paulwong 2021-11-15 14:46 鍙戣〃璇勮
]]>
EVEN DRIVEN - SPRING CLOUD STREAM 3.x - Functional Programming Modelhttp://www.tkk7.com/paulwong/archive/2021/11/10/436035.htmlpaulwongpaulwongWed, 10 Nov 2021 07:10:00 GMThttp://www.tkk7.com/paulwong/archive/2021/11/10/436035.htmlhttp://www.tkk7.com/paulwong/comments/436035.htmlhttp://www.tkk7.com/paulwong/archive/2021/11/10/436035.html#Feedback0http://www.tkk7.com/paulwong/comments/commentRss/436035.htmlhttp://www.tkk7.com/paulwong/services/trackbacks/436035.htmlSPRING CLOUD STREAM 3.x 鐗堟湰鏃訛紝涔嬪墠鐨勪竴浜涚紪紼嬫ā寮忥紝濡侤Enablebindding錛孈StreamListenner絳夋敞閲婅搴熷純浜嗭紝榪欐槸鐢變簬涓浜涙鏋剁殑浠g爜蹇呴渶鐢辯敤鎴風紪鍐欙紝濡傞厤緗鏋剁敤鐨処nput MessageChannel錛孫utput  MessageChannel錛岃繛鎺essageHandler涓嶮essageChannel絳夛紝琚涓轟笉蹇呰鐨勫姩浣溿備負浜嗙畝鍖栫敤鎴蜂唬鐮侊紝浜庢槸鎺ㄥ嚭Functional Programming Model銆?br />
寮曞叆浜嗘柊鍚嶈瘝錛歋upplier銆丗unction涓嶤onsumer銆傚疄闄呬笂榪欏嚑涓被鍙涓篈dapter錛屽鏋滀箣鍓嶅凡緇忔湁瀛樺湪鐨凷ervice綾伙紝涓旀柟娉曞悕涓哄悇縐嶅悇鏍鳳紝鍙互閲嶆柊鍖呰鎴怱upplier銆丗unction涓嶤onsumer錛屽茍鍦ㄥ浐瀹氱殑鏂規硶鍚嶏細apply/get/accept涓皟鐢⊿ervice鐨勬柟娉曘?br />

Supplier

褰撳湪閰嶇疆鏂囦歡涓敞鍏ユ綾誨瀷鐨凚ean錛屽茍鍦╯pring.cloud.stream.function.definition鍔犲叆姝ean鐨勫悕縐幫紝SPRING CLOUD STREAM灝變細甯綘鐢熸垚涓涓狾utput  MessageChannel錛屽茍榪炴帴涓婃Bean錛屽悗緇彧闇瑕佸湪BINDDING涓姞鍏ュ搴旂殑Destination Name錛屽嵆鍙悜BROKER鍙戞秷鎭簡銆?br />

Consumer

褰撳湪閰嶇疆鏂囦歡涓敞鍏ユ綾誨瀷鐨凚ean錛屽茍鍦╯pring.cloud.stream.function.definition鍔犲叆姝ean鐨勫悕縐幫紝SPRING CLOUD STREAM灝變細甯綘鐢熸垚涓涓狪nput  MessageChannel錛屽茍榪炴帴涓婃Bean錛屽悗緇彧闇瑕佸湪BINDDING涓姞鍏ュ搴旂殑Destination Name錛屽嵆鍙敹鍒癇ROKER鎺ㄩ佸叧浜庢Destination鐨勬秷鎭簡銆?br />

Function

褰撳湪閰嶇疆鏂囦歡涓敞鍏ユ綾誨瀷鐨凚ean錛屽茍鍦╯pring.cloud.stream.function.definition鍔犲叆姝ean鐨勫悕縐幫紝SPRING CLOUD STREAM灝變細甯綘鐢熸垚涓涓狪nput鍜孫utput  MessageChannel錛屽茍榪炴帴涓婃Bean錛屽悗緇彧闇瑕佸湪BINDDING涓垎鍒Input鍜孫utput MessageChannel鍔犲叆瀵瑰簲鐨凞estination Name1/Name2錛屽嵆鍙敹鍒癇ROKER鎺ㄩ佸叧浜庢Destination鐨勬秷鎭紝涔熷彲浠ュ悜BROKER鍙戞秷鎭簡銆?br />

涓嶴PRING INTEGRATION鐨勬暣鍚?/h2>濡傛灉瑕佸娑堟伅榪涜澶嶆潅澶勭悊錛屽鎷嗗垎娑堟伅銆佽仛鍚堟秷鎭両F ELSE娑堟伅絳夛紝灝辮鍊熷姪SPRING INTEGRATION浜嗐?br />
@Bean
    public IntegrationFlow upperCaseFlow(LoanService loanService) {
        return IntegrationFlows
                    //turn this IntegrationFlow as a gateway, here is a Function interface 
                    
//with loadCheckerFunction as bean name
                    .from(LoadCheckerFunction.class, gateway -> gateway.beanName("loadCheckerFunction"))
                    .handle(loanService, "check")
                    .logAndReply(LoggingHandler.Level.WARN);
    }

    public interface LoadCheckerFunction extends Function<Loan, Loan>{

    }

IntegrationFlows.from(Class<?> serviceInterface)鏄彲浠ュ皢鏈琁ntegrationFlow鍖呰鎴恠erviceInterface鐨勫疄鐜扮被錛屽鏋滆皟鐢ㄦ鎺ュ彛錛屾渶緇堜細榪斿洖IntegrationFlow鏈鍚庝竴涓楠ょ殑瀹炰綋錛屽鏋滆繖涓猻erviceInterface鏄疐unction鐨勮瘽錛屽垰濂藉拰SPRING CLOUD STREAM瀵規帴涓娿?br />
鍚庣畫鍦╯pring.cloud.stream.function.definition鍔犲叆姝ean鐨勫悕縐發oadCheckerFunction錛孲PRING CLOUD STREAM灝變細甯綘鐢熸垚涓涓狪nput鍜孫utput  MessageChannel錛屽茍榪炴帴涓婃Bean錛屽啀鍦˙INDDING涓垎鍒Input鍜孫utput MessageChannel鍔犲叆瀵瑰簲鐨凞estination Name1/Name2錛屽嵆鍙敹鍒癇ROKER鎺ㄩ佸叧浜庢Destination鐨勬秷鎭紝涔熷彲浠ュ悜BROKER鍙戞秷鎭?br />
application.yaml
# This setting can increase or decrease the rate of message production (1000 = 1s)
# spring.cloud.stream.poller.fixed-delay=1000

# This setting can control which function method in our code will be triggered if there are multiple
# spring.cloud.function.definition=supplyLoan

# Give the autogenerated binding a friendlier name

spring:
   application:
      name: loan-check-rabbit
   banner:
      location: classpath:/banner-rabbit.txt
   cloud:
      stream:
         function.definition: loadCheckerFunction
         #BindingProperties
         bindings:
            loadCheckerFunction-in-0:
               destination: queue.pretty.log.messages
               binder: local_rabbit
            loadCheckerFunction-out-0:
               destination: queue.pretty.approved.messages
               binder: local_rabbit
         #BinderProperties
         binders:
            local_rabbit:
               type: rabbit
               environment:
                  spring:
                     rabbitmq:
                        host: 10.80.27.69
                        port: 5672
                        username: guest
                        password: guest
                        virtual-host: my-virtual-host

Reference

https://spring.io/blog/2019/10/25/spring-cloud-stream-and-spring-integration

paulwong 2021-11-10 15:10 鍙戣〃璇勮
]]>
EVEN DRIVEN - SPRING CLOUD STREAM - SPRING CLOUD寰湇鍔$殑EVEN DRIVEN妗嗘灦http://www.tkk7.com/paulwong/archive/2021/11/05/436031.htmlpaulwongpaulwongFri, 05 Nov 2021 06:58:00 GMThttp://www.tkk7.com/paulwong/archive/2021/11/05/436031.htmlhttp://www.tkk7.com/paulwong/comments/436031.htmlhttp://www.tkk7.com/paulwong/archive/2021/11/05/436031.html#Feedback0http://www.tkk7.com/paulwong/comments/commentRss/436031.htmlhttp://www.tkk7.com/paulwong/services/trackbacks/436031.html
鍗矨寰湇鍔″簲鐢ㄥ皢鏁版嵁鍙戦佸埌MESSAGE BROKER涓殑鏌愪釜DESTINATION錛屾DESTINATION鏄箍鎾瀷錛岄潪鐐瑰鐐瑰瀷銆侭寰湇鍔″簲鐢ㄨ闃呮DESTINATION錛屽綋鏈夋柊MESSAGE鍒拌揪姝ESTINATION鏃訛紝MESSAGE BROKER浼氬皢姝ESSAGE鎺ㄩ佺粰B搴旂敤銆傛墍鏈夊姝ESSAGE鏈夐渶瑕佺殑搴旂敤鍧囧彲璁㈤槄錛屼粠鑰屾敹鍒版MESSAGE銆?br />
SPRING CLOUD 涓璄VENT DRIVEN鐨勬鏋跺氨鏄疭PRING CLOUD STREAM銆傚叾搴曞眰鏄嬌鐢⊿PRING INTEGRATION瀹炵幇銆?br />
SPRING CLOUD STREAM鏈変互涓嬫柊鍚嶈瘝錛?br />
  • BINDER錛?/li>
鏄MESSAGE BROKER鎿嶄綔鏂規硶鐨勬娊璞★紝鍗沖簲鐢ㄩ氳繃姝INDER鎿嶄綔MESSAGE BROKER銆傜洰鍓嶅彧瀹炵幇浜哛ABITMQ鍜孠AFKA銆?br />
  • CHANNEL
MESSAGE浠嶴PRING CLOUD STREAM浼犵粰搴旂敤鎴栫浉鍙嶆槸閫氳繃CHANNEL浼犻掔殑錛岃繖鐐瑰拰SPRING INTEGRATION鏄竴鏍風殑銆?br />
  • SOURCE
MESSAGE浠庡簲鐢ㄤ紶緇橲PRING CLOUD STREAM鐨凜HANNEL錛屽彨@INPUT錛屽寘鍚繖縐岰HANNEL鐨勬帴鍙e彨SOURCE銆?br />
  • SINK
MESSAGE浠嶴PRING CLOUD STREAM浼犵粰搴旂敤鐨凜HANNEL錛屽彨@OUPUT錛屽寘鍚繖縐岰HANNEL鐨勬帴鍙e彨SINK銆?br />
  • BIDDING
緇戝畾鍝釜@INPUT鎴栧摢涓狜OUPUT涓庡摢涓狣ESTINATION鍙戦佹垨鎺ユ敹鍏崇郴鐨凪APPING銆?br />
  • EnableBinding
搴旂敤鍚姩鏃跺氨浼氬緩绔婨nableBinding鎸囧畾鐨勬帴鍙d腑鐨凜HANNEL
  • 娑堣垂鑰呯兢緇?/li>
榛樿涓嬪鏋滃悓涓涓簲鐢ㄩ儴緗蹭簡澶氫釜瀹炰緥錛屽垯姣忎釜瀹炰緥閮戒細鏀跺埌MESSAGE錛岃繖鏃跺鏋滆緗簡娑堣垂鑰呯兢緇勫悕縐幫紝鍒欏悓涓涓悕縐頒笅鐨勫涓疄渚嬶紝鍙湁涓涓兘鏀跺埌MESSAGE銆?br />
  • PARTITION
濡傛灉涓篗ESSAGE鎸囧畾瑙勫垯錛屽MESSAGE鏌愪釜瀛楁鍊間互A寮澶翠負涓涓鍒欙紝浠寮澶翠負涓涓鍒欙紝閭d箞浠寮澶寸殑MESSAGE浼氭斁鍒板悓涓涓垎鍖轟腑銆?br />
榪欐牱浣跨敤灝卞緢綆鍗曚簡錛屽彧瑕佸彇寰桹UTPUT CHANNEL錛屽氨鍙互鍙戦丮ESSAGE錛屽皢浠g爜鍏寵仈鍒癐NPUT CHANNEL錛屽氨鑳藉湪鏀跺埌MESSAGE鏃訛紝鐩稿叧浠g爜灝變細琚墽琛屻?br />


paulwong 2021-11-05 14:58 鍙戣〃璇勮
]]>
SPRING CLOUD ALIBABAhttp://www.tkk7.com/paulwong/archive/2021/05/11/435871.htmlpaulwongpaulwongTue, 11 May 2021 06:04:00 GMThttp://www.tkk7.com/paulwong/archive/2021/05/11/435871.htmlhttp://www.tkk7.com/paulwong/comments/435871.htmlhttp://www.tkk7.com/paulwong/archive/2021/05/11/435871.html#Feedback0http://www.tkk7.com/paulwong/comments/commentRss/435871.htmlhttp://www.tkk7.com/paulwong/services/trackbacks/435871.htmlhttps://mp.weixin.qq.com/mp/appmsgalbum?__biz=MzAwMTk4NjM1MA==&action=getalbum&album_id=1418244755364134912&scene=173&from_msgid=2247484698&from_itemidx=1&count=3&nolastread=1#wechat_redirect

SpringCloud alibaba瀹炴垬緋誨垪鏂囩珷姹囨?/span>
https://segmentfault.com/a/1190000023541535?utm_source=sf-similar-article

paulwong 2021-05-11 14:04 鍙戣〃璇勮
]]>
SPRING CLOUD JWT璧勬簮http://www.tkk7.com/paulwong/archive/2017/03/24/432401.htmlpaulwongpaulwongFri, 24 Mar 2017 15:11:00 GMThttp://www.tkk7.com/paulwong/archive/2017/03/24/432401.htmlhttp://www.tkk7.com/paulwong/comments/432401.htmlhttp://www.tkk7.com/paulwong/archive/2017/03/24/432401.html#Feedback0http://www.tkk7.com/paulwong/comments/commentRss/432401.htmlhttp://www.tkk7.com/paulwong/services/trackbacks/432401.htmlhttps://github.com/thomas-kendall/trivia-microservices


涓涓猄pring Boot錛?JWT錛孉ugularJS鎺ュ彛瀹夊叏楠岃瘉鐨勭畝鍗曚緥瀛?br />http://blog.csdn.net/offbye/article/details/47607711



https://github.com/tuanngda/spring-boot-oauth2-demo


Spring Oauth2 with JWT Sample
http://www.tuicool.com/articles/EjUFZj7


http://stackoverflow.com/questions/38156213/spring-cloud-zuul-jwt-for-value-reference-tokens

paulwong 2017-03-24 23:11 鍙戣〃璇勮
]]>
浣跨敤Spring Cloud Security OAuth2鎼緩鎺堟潈鏈嶅姟http://www.tkk7.com/paulwong/archive/2016/09/16/431797.htmlpaulwongpaulwongFri, 16 Sep 2016 10:22:00 GMThttp://www.tkk7.com/paulwong/archive/2016/09/16/431797.htmlhttp://www.tkk7.com/paulwong/comments/431797.htmlhttp://www.tkk7.com/paulwong/archive/2016/09/16/431797.html#Feedback0http://www.tkk7.com/paulwong/comments/commentRss/431797.htmlhttp://www.tkk7.com/paulwong/services/trackbacks/431797.htmlSpring Cloud Security OAuth2 鏄?Spring 瀵?OAuth2 鐨勫紑婧愬疄鐜幫紝浼樼偣鏄兘涓嶴pring Cloud鎶鏈嚎鏃犵紳闆嗘垚錛屽鏋滃叏閮ㄤ嬌鐢ㄩ粯璁ら厤緗紝寮鍙戣呭彧闇瑕佹坊鍔犳敞瑙e氨鑳藉畬鎴?OAuth2 鎺堟潈鏈嶅姟鐨勬惌寤恒?/p>

1. 娣誨姞渚濊禆

鎺堟潈鏈嶅姟鏄熀浜嶴pring Security鐨勶紝鍥犳闇瑕佸湪欏圭洰涓紩鍏ヤ袱涓緷璧栵細

<dependency>
        <groupId>org.springframework.cloud</groupId>
        <artifactId>spring-cloud-starter-security</artifactId>
</dependency>

<dependency>
         <groupId>org.springframework.cloud</groupId>
         <artifactId>spring-cloud-starter-oauth2</artifactId>
 </dependency>


鍓嶈呬負 Security錛屽悗鑰呬負Security鐨凮Auth2鎵╁睍銆?/p>

2. 娣誨姞娉ㄨВ鍜岄厤緗?/h1>

鍦ㄥ惎鍔ㄧ被涓坊鍔?code style="box-sizing: border-box; font-family: "Source Code Pro", 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娉ㄨВ錛?br />

@SpringBootApplication
@EnableAuthorizationServer
public class AlanOAuthApplication {
    public static void main(String[] args) {
        SpringApplication.run(AlanOAuthApplication.class, args);
    }
}


瀹屾垚榪欎簺鎴戜滑鐨勬巿鏉冩湇鍔℃渶鍩烘湰鐨勯鏋跺氨宸茬粡鎼緩瀹屾垚浜嗐備絾鏄鎯寵窇閫氭暣涓祦紼嬶紝鎴戜滑蹇呴』鍒嗛厤 client_idclient_secret鎵嶈銆係pring Security OAuth2鐨勯厤緗柟娉曟槸緙栧啓@Configuration綾葷戶鎵?code style="box-sizing: border-box; font-family: "Source Code Pro", 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 style="box-sizing: border-box; font-family: "Source Code Pro", 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)鏂規硶錛屽錛?br />

@Override
    public void configure(ClientDetailsServiceConfigurer clients) throws Exception {
        clients.inMemory() // 浣跨敤in-memory瀛樺偍
                .withClient("client") // client_id
                .secret("secret") // client_secret
                .authorizedGrantTypes("authorization_code") // 璇lient鍏佽鐨勬巿鏉冪被鍨?/span>
                .scopes("app"); // 鍏佽鐨勬巿鏉冭寖鍥?/span>
    }


3. 鎺堟潈嫻佺▼

璁塊棶鎺堟潈欏甸潰錛?br />

localhost:8080/oauth/authorize?client_id=client&response_type=code&redirect_uri=http://www.baidu.com


姝ゆ椂嫻忚鍣ㄤ細璁╀綘杈撳叆鐢ㄦ埛鍚嶅瘑鐮侊紝榪欐槸鍥犱負 Spring Security 鍦ㄩ粯璁ゆ儏鍐典笅浼氬鎵鏈塙RL娣誨姞Basic Auth璁よ瘉銆傞粯璁ょ殑鐢ㄦ埛鍚嶄負user, 瀵嗙爜鏄殢鏈虹敓鎴愮殑錛屽湪鎺у埗鍙版棩蹇椾腑鍙互鐪嬪埌銆?/p>

oauth2

鐢婚铏界劧寰堢畝闄嬶紝浣嗘槸鍩烘湰鍔熻兘閮藉叿澶囦簡銆傜偣鍑?code style="box-sizing: border-box; font-family: "Source Code Pro", 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 style="box-sizing: border-box; font-family: "Source Code Pro", 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鍙傛暟錛?/p>

榪欓噷鍐欏浘鐗囨弿榪? title=

鎷垮埌code浠ュ悗錛屽氨鍙互璋冪敤

POST/GET http://client:secret@localhost:8080/oauth/token
  • 1

鏉ユ崲鍙?code style="box-sizing: border-box; font-family: "Source Code Pro", 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浜嗭細

curl -X POST -H "Cache-Control: no-cache" -H "Content-Type: application/x-www-form-urlencoded" -d 'grant_type=authorization_code&code=Li4NZo&redirect_uri=http://www.baidu.com' "http://client:secret@localhost:8080/oauth/token"

榪斿洖濡備笅錛?br />

{
  "access_token": "32a1ca28-bc7a-4147-88a1-c95abcc30556",
  "token_type": "bearer",
  "expires_in": 2591999,
  "scope": "app"
}

鍒版鎴戜滑鏈鏈鍩烘湰鐨勬巿鏉冩湇鍔″氨鎼緩瀹屾垚浜嗐傜劧鑰岋紝榪欎粎浠呮槸涓猟emo錛屽鏋滆鍦ㄧ敓浜х幆澧冧腑浣跨敤錛岃繕闇瑕佸仛鏇村鐨勫伐浣溿?/p>

4. 浣跨敤MySQL瀛樺偍access_token鍜宑lient淇℃伅

鎶婃巿鏉冩湇鍔″櫒涓殑鏁版嵁瀛樺偍鍒版暟鎹簱涓茍涓嶉毦錛屽洜涓?Spring Cloud Security OAuth 宸茬粡涓烘垜浠璁″ソ浜嗕竴濂桽chema鍜屽搴旂殑DAO瀵硅薄銆備絾鍦ㄤ嬌鐢ㄤ箣鍓嶏紝鎴戜滑闇瑕佸厛瀵圭浉鍏崇殑綾繪湁涓瀹氱殑浜嗚В銆?/p>

4.1 鐩稿叧鎺ュ彛

Spring Cloud Security OAuth2閫氳繃DefaultTokenServices綾繪潵瀹屾垚token鐢熸垚銆佽繃鏈熺瓑 OAuth2 鏍囧噯瑙勫畾鐨勪笟鍔¢昏緫錛岃?code style="box-sizing: border-box; font-family: "Source Code Pro", 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鍙堟槸閫氳繃TokenStore鎺ュ彛瀹屾垚瀵圭敓鎴愭暟鎹殑鎸佷箙鍖栥傚湪涓婇潰鐨刣emo涓紝TokenStore鐨勯粯璁ゅ疄鐜頒負InMemoryTokenStore錛屽嵆鍐呭瓨瀛樺偍銆?瀵逛簬Client淇℃伅錛?code style="box-sizing: border-box; font-family: "Source Code Pro", 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鎺ュ彛璐熻矗浠庡瓨鍌ㄤ粨搴撲腑璇誨彇鏁版嵁錛屽湪涓婇潰鐨刣emo涓粯璁や嬌鐢ㄧ殑涔熸槸InMemoryClientDetialsService瀹炵幇綾匯傝鍒拌繖閲屽氨鑳界湅鍑猴紝瑕佹兂浣跨敤鏁版嵁搴撳瓨鍌紝鍙渶瑕佹彁渚涜繖浜涙帴鍙g殑瀹炵幇綾誨嵆鍙傚簡騫哥殑鏄紝妗嗘灦宸茬粡涓烘垜浠啓濂絁DBC瀹炵幇浜嗭紝鍗?code style="box-sizing: border-box; font-family: "Source Code Pro", 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 style="box-sizing: border-box; font-family: "Source Code Pro", 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銆?/p>

4.2 寤鴻〃

瑕佹兂浣跨敤榪欎簺JDBC瀹炵幇錛岄鍏堣寤鴻〃銆傛鏋朵負鎴戜滑鎻愬墠璁捐濂戒簡schema, 鍦╣ithub涓婏細https://github.com/spring-projects/spring-security-oauth/blob/master/spring-security-oauth2/src/test/resources/schema.sql

鍦ㄤ嬌鐢ㄨ繖濂楄〃緇撴瀯涔嬪墠瑕佹敞鎰忕殑鏄紝瀵逛簬MySQL鏉ヨ錛岄粯璁ゅ緩琛ㄨ鍙ヤ腑涓婚敭鏄痸archar(255)綾誨瀷錛屽湪mysql涓墽琛屼細鎶ラ敊錛屽師鍥犳槸mysql瀵箆archar涓婚敭闀垮害鏈夐檺鍒躲傛墍浠ヨ繖閲屾敼鎴?28鍗沖彲銆傚叾嬈★紝璇彞涓細鏈夋煇浜涘瓧孌典負LONGVARBINARY綾誨瀷錛屽畠瀵瑰簲mysql鐨?code style="box-sizing: border-box; font-family: "Source Code Pro", 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綾誨瀷錛屼篃闇瑕佷慨鏀逛竴涓嬨?/p>

4.3 閰嶇疆

鏁版嵁搴撳緩濂藉悗錛屼笅涓姝ュ氨鏄厤緗鏋朵嬌鐢↗DBC瀹炵幇銆傛柟娉曡繕鏄紪鍐?code style="box-sizing: border-box; font-family: "Source Code Pro", 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 style="box-sizing: border-box; font-family: "Source Code Pro", 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錛?br />

@Autowired
    private AuthenticationManager authenticationManager;

    @Autowired
    private DataSource dataSource;
    @Bean // 澹版槑TokenStore瀹炵幇
    public TokenStore tokenStore() {
        return new JdbcTokenStore(dataSource);
    }
    @Bean // 澹版槑 ClientDetails瀹炵幇
    public ClientDetailsService clientDetails() {
        return new JdbcClientDetailsService(dataSource);
    }
    @Override // 閰嶇疆妗嗘灦搴旂敤涓婅堪瀹炵幇
    public void configure(AuthorizationServerEndpointsConfigurer endpoints) throws Exception {
        endpoints.authenticationManager(authenticationManager);
        endpoints.tokenStore(tokenStore());

        // 閰嶇疆TokenServices鍙傛暟
        DefaultTokenServices tokenServices = new DefaultTokenServices();
        tokenServices.setTokenStore(endpoints.getTokenStore());
        tokenServices.setSupportRefreshToken(false);
        tokenServices.setClientDetailsService(endpoints.getClientDetailsService());
        tokenServices.setTokenEnhancer(endpoints.getTokenEnhancer());
        tokenServices.setAccessTokenValiditySeconds( (int) TimeUnit.DAYS.toSeconds(30)); // 30澶?/span>
        endpoints.tokenServices(tokenServices);
    }

瀹屾垚榪欎簺鍚庯紝妗嗘灦灝變細灝嗕腑闂翠駭鐢熺殑鏁版嵁鍐欏埌mysql涓簡銆?code style="box-sizing: border-box; font-family: "Source Code Pro", 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鏄痗lient琛紝鍙互鐩存帴鍦ㄨ琛ㄤ腑娣誨姞璁板綍鏉ユ坊鍔燾lient: 
榪欓噷鍐欏浘鐗囨弿榪? title=

4.4 闇瑕佹敞鎰忕殑鍦版柟

榪欓噷涓嶅緱涓嶈 Spring 璁捐鏈変竴涓钁╁湴鐨勬柟銆傛敞鎰忕湅oauth_access_token琛ㄦ槸瀛樻斁璁塊棶浠ょ墝鐨勶紝浣嗘槸騫舵病鏈夌洿鎺ュ湪瀛楁涓瓨鏀総oken銆係pring 浣跨敤OAuth2AccessToken鏉ユ娊璞′笌浠ょ墝鏈夊叧鐨勬墍鏈夊睘鎬э紝鍦ㄥ啓鍏ュ埌鏁版嵁搴撴椂錛?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: "Source Code Pro", 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瀛楁涓備篃灝辨槸璇達紝濡傛灉鍙湅鏁版嵁琛ㄤ綘鏄湅涓嶅嚭access_token鐨勫兼槸澶氬皯錛岃繃鏈熸椂闂寸瓑淇℃伅鐨勩傝繖灝辯粰璧勬簮鏈嶅姟鍣ㄧ殑瀹炵幇甯︽潵浜嗛夯鐑︺傛垜浠殑璧勬簮鎻愪緵鏂瑰茍娌℃湁浣跨敤Spring Security錛屼篃涓嶆兂寮曞叆 Spring Security 鐨勪換浣曚緷璧栵紝榪欐椂鍊欏氨鍙兘灝?nbsp;DefaultOAuth2AccessToken鐨勬簮鐮乧opy鍒拌祫婧愭彁渚涙柟鐨勯」鐩腑錛岀劧鍚庤鍙?code style="box-sizing: border-box; font-family: "Source Code Pro", 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瀛楁騫跺弽搴忓垪鍖栬繕鍘熷璞℃潵鑾峰彇token淇℃伅銆備絾鏄鏋滆繖鏍峰仛榪樹細閬囧埌鍙嶅簭鍒楀寲鍏煎鎬х殑闂錛屽叿浣撹В鍐蟲柟娉曞弬鑰冩垜鍙︿竴綃囧崥鏂?http://blog.csdn.net/neosmith/article/details/52539614

5. 鎬葷粨

鑷蟲涓涓兘鍦ㄧ敓浜х幆澧冧笅浣跨敤鐨勬巿鏉冩湇鍔″氨鎼緩濂戒簡銆傚叾瀹炴垜浠湪瀹為檯浣跨敤鏃跺簲璇ラ傚綋瀹氬埗JdbcTokenStore鎴?code style="box-sizing: border-box; font-family: "Source Code Pro", 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鏉ュ疄閫傚簲涓氬姟闇瑕侊紝鐢氳嚦鍙互鐩存帴浠?寮濮嬪疄鐜版帴鍙o紝瀹屽叏涓嶇敤妗嗘灦鎻愪緵鐨勫疄鐜般傚彟澶栵紝Spring 鐩存帴灝?code style="box-sizing: border-box; font-family: "Source Code Pro", 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 style="box-sizing: border-box; font-family: "Source Code Pro", 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錛屼絾鏄氳繃鍔犲瘑鐨勬柟娉曚篃鍙互瀹炵幇錛屽畬鍏ㄤ笉搴旇鐩存帴鎵斿瓧鑺傘備笉榪囬氳繃瀹氬埗TokenStore鎺ュ彛錛屾垜浠彲浠ヤ嬌鐢ㄨ嚜宸辯殑琛ㄧ粨鏋勮屼笉鎷樻償浜庨粯璁ゅ疄鐜般?br />
http://blog.csdn.net/tracker_w/article/category/6360121

http://blog.csdn.net/neosmith/article/details/52539927



paulwong 2016-09-16 18:22 鍙戣〃璇勮
]]>
浣跨敤Spring Cloud Feign浣滀負HTTP瀹㈡埛绔皟鐢ㄨ繙紼婬TTP鏈嶅姟http://www.tkk7.com/paulwong/archive/2016/09/16/431796.htmlpaulwongpaulwongFri, 16 Sep 2016 10:13:00 GMThttp://www.tkk7.com/paulwong/archive/2016/09/16/431796.htmlhttp://www.tkk7.com/paulwong/comments/431796.htmlhttp://www.tkk7.com/paulwong/archive/2016/09/16/431796.html#Feedback0http://www.tkk7.com/paulwong/comments/commentRss/431796.htmlhttp://www.tkk7.com/paulwong/services/trackbacks/431796.html鍦⊿pring Cloud Netflix鏍堜腑錛屽悇涓井鏈嶅姟閮芥槸浠TTP鎺ュ彛鐨勫艦寮忔毚闇茶嚜韜湇鍔$殑錛屽洜姝ゅ湪璋冪敤榪滅▼鏈嶅姟鏃跺氨蹇呴』浣跨敤HTTP瀹㈡埛绔傛垜浠彲浠ヤ嬌鐢↗DK鍘熺敓鐨?code style="box-sizing: border-box; font-family: "Source Code Pro", 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銆丄pache鐨?code style="box-sizing: border-box; font-family: "Source Code Pro", 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銆丯etty鐨勫紓姝TTP Client, Spring鐨?code style="box-sizing: border-box; font-family: "Source Code Pro", 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銆備絾鏄紝鐢ㄨ搗鏉ユ渶鏂逛究銆佹渶浼橀泤鐨勮繕鏄灞濬eign浜嗐?/p>

Feign綆浠?/h1>

Feign鏄竴縐嶅0鏄庡紡銆佹ā鏉垮寲鐨凥TTP瀹㈡埛绔傚湪Spring Cloud涓嬌鐢‵eign, 鎴戜滑鍙互鍋氬埌浣跨敤HTTP璇鋒眰榪滅▼鏈嶅姟鏃惰兘涓庤皟鐢ㄦ湰鍦版柟娉曚竴鏍風殑緙栫爜浣撻獙錛屽紑鍙戣呭畬鍏ㄦ劅鐭ヤ笉鍒拌繖鏄繙紼嬫柟娉曪紝鏇存劅鐭ヤ笉鍒拌繖鏄釜HTTP璇鋒眰銆傛瘮濡傦細

@Autowired
private AdvertGropRemoteService service; // 榪滅▼鏈嶅姟

public AdvertGroupVO foo(Integer groupId) {
    return service.findByGroupId(groupId); // 閫氳繃HTTP璋冪敤榪滅▼鏈嶅姟
}

寮鍙戣呴氳繃service.findByGroupId()灝辮兘瀹屾垚鍙戦丠TTP璇鋒眰鍜岃В鐮丠TTP榪斿洖緇撴灉騫跺皝瑁呮垚瀵硅薄鐨勮繃紼嬨?/p>

Feign鐨勫畾涔?/h1>

涓轟簡璁〧eign鐭ラ亾鍦ㄨ皟鐢ㄦ柟娉曟椂搴旇鍚戝摢涓湴鍧鍙戣姹備互鍙婅姹傞渶瑕佸甫鍝簺鍙傛暟錛屾垜浠渶瑕佸畾涔変竴涓帴鍙o細

@FeignClient(name = "ea")  //  [A]
public interface AdvertGroupRemoteService {

    @RequestMapping(value = "/group/{groupId}", method = RequestMethod.GET) // [B]
    AdvertGroupVO findByGroupId(@PathVariable("groupId") Integer adGroupId) // [C]

    @RequestMapping(value = "/group/{groupId}", method = RequestMethod.PUT)
    void update(@PathVariable("groupId") Integer groupId, @RequestParam("groupName") String groupName)

A: @FeignClient鐢ㄤ簬閫氱煡Feign緇勪歡瀵硅鎺ュ彛榪涜浠g悊(涓嶉渶瑕佺紪鍐欐帴鍙e疄鐜?錛屼嬌鐢ㄨ呭彲鐩存帴閫氳繃@Autowired娉ㄥ叆銆?/p>

B: @RequestMapping琛ㄧず鍦ㄨ皟鐢ㄨ鏂規硶鏃墮渶瑕佸悜/group/{groupId}鍙戦?code style="box-sizing: border-box; font-family: "Source Code Pro", 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璇鋒眰銆?/p>

C: @PathVariable涓?code style="box-sizing: border-box; font-family: "Source Code Pro", 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涓搴旀敞瑙e惈涔夌浉鍚屻?/p>

Spring Cloud搴旂敤鍦ㄥ惎鍔ㄦ椂錛孎eign浼氭壂鎻忔爣鏈?code style="box-sizing: border-box; font-family: "Source Code Pro", 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娉ㄨВ鐨勬帴鍙o紝鐢熸垚浠g悊錛屽茍娉ㄥ唽鍒癝pring瀹瑰櫒涓傜敓鎴愪唬鐞嗘椂Feign浼氫負姣忎釜鎺ュ彛鏂規硶鍒涘緩涓涓?code style="box-sizing: border-box; font-family: "Source Code Pro", 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瀵硅薄錛岃瀵硅薄灝佽浜咹TTP璇鋒眰闇瑕佺殑鍏ㄩ儴淇℃伅錛岃姹傚弬鏁板悕銆佽姹傛柟娉曠瓑淇℃伅閮芥槸鍦ㄨ繖涓繃紼嬩腑紜畾鐨勶紝Feign鐨勬ā鏉垮寲灝變綋鐜板湪榪欓噷銆?/p>

鍦ㄦ湰渚嬩腑錛屾垜浠皢Feign涓嶦ureka鍜孯ibbon緇勫悎浣跨敤錛?code style="box-sizing: border-box; font-family: "Source Code Pro", 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")鎰忎負閫氱煡Feign鍦ㄨ皟鐢ㄨ鎺ュ彛鏂規硶鏃惰鍚慐ureka涓煡璇㈠悕涓?code style="box-sizing: border-box; font-family: "Source Code Pro", 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鐨勬湇鍔★紝浠庤屽緱鍒版湇鍔RL銆?/p>

Feign鐨凟ncoder銆丏ecoder鍜孍rrorDecoder

Feign灝嗘柟娉曠鍚嶄腑鏂規硶鍙傛暟瀵硅薄搴忓垪鍖栦負璇鋒眰鍙傛暟鏀懼埌HTTP璇鋒眰涓殑榪囩▼錛屾槸鐢辯紪鐮佸櫒(Encoder)瀹屾垚鐨勩傚悓鐞嗭紝灝咹TTP鍝嶅簲鏁版嵁鍙嶅簭鍒楀寲涓簀ava瀵硅薄鏄敱瑙g爜鍣?Decoder)瀹屾垚鐨勩?/p>

榛樿鎯呭喌涓嬶紝Feign浼氬皢鏍囨湁@RequestParam娉ㄨВ鐨勫弬鏁拌漿鎹㈡垚瀛楃涓叉坊鍔犲埌URL涓紝灝嗘病鏈夋敞瑙g殑鍙傛暟閫氳繃Jackson杞崲鎴恓son鏀懼埌璇鋒眰浣撲腑銆傛敞鎰忥紝濡傛灉鍦?code style="box-sizing: border-box; font-family: "Source Code Pro", 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涓殑method灝嗚姹傛柟寮忔寚瀹氫負POST錛岄偅涔堟墍鏈夋湭鏍囨敞瑙g殑鍙傛暟灝嗕細琚拷鐣ワ紝渚嬪錛?br />

@FeignClient(name = "ea")  //  [A]
public interface AdvertGroupRemoteService {

    @RequestMapping(value = "/group/{groupId}", method = RequestMethod.GET) // [B]
    AdvertGroupVO findByGroupId(@PathVariable("groupId") Integer adGroupId) // [C]

    @RequestMapping(value = "/group/{groupId}", method = RequestMethod.PUT)
    void update(@PathVariable("groupId") Integer groupId, @RequestParam("groupName") String groupName)

姝ゆ椂鍥犱負澹版槑鐨勬槸GET璇鋒眰娌℃湁璇鋒眰浣擄紝鎵浠?code style="box-sizing: border-box; font-family: "Source Code Pro", 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鍙傛暟灝變細琚拷鐣ャ?/p>

鍦⊿pring Cloud鐜涓嬶紝Feign鐨凟ncoder*鍙細鐢ㄦ潵緙栫爜娌℃湁娣誨姞娉ㄨВ鐨勫弬鏁?銆傚鏋滀綘鑷畾涔変簡Encoder, 閭d箞鍙湁鍦ㄧ紪鐮?code style="box-sizing: border-box; font-family: "Source Code Pro", 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鍙傛暟鏃舵墠浼氳皟鐢ㄤ綘鐨凟ncoder銆傚浜嶥ecoder, 榛樿浼氬鎵樼粰SpringMVC涓殑MappingJackson2HttpMessageConverter綾昏繘琛岃В鐮併傚彧鏈夊綋鐘舵佺爜涓嶅湪200 ~ 300涔嬮棿鏃禘rrorDecoder鎵嶄細琚皟鐢ㄣ侲rrorDecoder鐨勪綔鐢ㄦ槸鍙互鏍規嵁HTTP鍝嶅簲淇℃伅榪斿洖涓涓紓甯革紝璇ュ紓甯稿彲浠ュ湪璋冪敤Feign鎺ュ彛鐨勫湴鏂硅鎹曡幏鍒般傛垜浠洰鍓嶅氨閫氳繃ErrorDecoder鏉ヤ嬌Feign鎺ュ彛鎶涘嚭涓氬姟寮傚父浠ヤ緵璋冪敤鑰呭鐞嗐?/p>

Feign鐨凥TTP Client

Feign鍦ㄩ粯璁ゆ儏鍐典笅浣跨敤鐨勬槸JDK鍘熺敓鐨?code style="box-sizing: border-box; font-family: "Source Code Pro", 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鍙戦丠TTP璇鋒眰錛屾病鏈夎繛鎺ユ睜錛屼絾鏄姣忎釜鍦板潃浼氫繚鎸佷竴涓暱榪炴帴錛屽嵆鍒╃敤HTTP鐨?code style="box-sizing: border-box; font-family: "Source Code Pro", 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 銆傛垜浠彲浠ョ敤Apache鐨凥TTP Client鏇挎崲Feign鍘熷鐨刪ttp client, 浠庤岃幏鍙栬繛鎺ユ睜銆佽秴鏃舵椂闂寸瓑涓庢ц兘鎭伅鐩稿叧鐨勬帶鍒惰兘鍔涖係pring Cloud浠?code style="box-sizing: border-box; font-family: "Source Code Pro", 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鐗堟湰寮濮嬫敮鎸佽繖縐嶆浛鎹紝棣栧厛鍦ㄩ」鐩腑澹版槑Apache HTTP Client鍜?code style="box-sizing: border-box; font-family: "Source Code Pro", 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渚濊禆錛?br />

@RequestMapping(value = "/group/{groupId}", method = RequestMethod.GET)
void update(@PathVariable("groupId") Integer groupId, @RequestParam("groupName") String groupName, DataObject obj);

鐒跺悗鍦?code style="box-sizing: border-box; font-family: "Source Code Pro", 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涓坊鍔狅細

feign.httpclient.enabled=true

鎬葷粨

閫氳繃Feign錛?鎴戜滑鑳芥妸HTTP榪滅▼璋冪敤瀵瑰紑鍙戣呭畬鍏ㄩ忔槑錛屽緱鍒頒笌璋冪敤鏈湴鏂規硶涓鑷寸殑緙栫爜浣撻獙銆傝繖涓鐐逛笌闃塊噷Dubbo涓毚闇茶繙紼嬫湇鍔$殑鏂瑰紡綾諱技錛屽尯鍒湪浜嶥ubbo鏄熀浜庣鏈変簩榪涘埗鍗忚錛岃孎eign鏈川涓婅繕鏄釜HTTP瀹㈡埛绔傚鏋滄槸鍦ㄧ敤Spring Cloud Netflix鎼緩寰湇鍔★紝閭d箞Feign鏃犵枒鏄渶浣抽夋嫨銆?br />
http://blog.csdn.net/tracker_w/article/category/6360121
http://blog.csdn.net/neosmith/article/details/52449921



paulwong 2016-09-16 18:13 鍙戣〃璇勮
]]>
寰湇鍔℃鏋禨pring Cloudhttp://www.tkk7.com/paulwong/archive/2016/09/11/431788.htmlpaulwongpaulwongSun, 11 Sep 2016 12:49:00 GMThttp://www.tkk7.com/paulwong/archive/2016/09/11/431788.htmlhttp://www.tkk7.com/paulwong/comments/431788.htmlhttp://www.tkk7.com/paulwong/archive/2016/09/11/431788.html#Feedback0http://www.tkk7.com/paulwong/comments/commentRss/431788.htmlhttp://www.tkk7.com/paulwong/services/trackbacks/431788.html2016

paulwong 2016-09-11 20:49 鍙戣〃璇勮
]]>
JHipsterhttp://www.tkk7.com/paulwong/archive/2016/09/11/431787.htmlpaulwongpaulwongSun, 11 Sep 2016 08:40:00 GMThttp://www.tkk7.com/paulwong/archive/2016/09/11/431787.htmlhttp://www.tkk7.com/paulwong/comments/431787.htmlhttp://www.tkk7.com/paulwong/archive/2016/09/11/431787.html#Feedback0http://www.tkk7.com/paulwong/comments/commentRss/431787.htmlhttp://www.tkk7.com/paulwong/services/trackbacks/431787.htmlhttp://jhipster.cn/

paulwong 2016-09-11 16:40 鍙戣〃璇勮
]]>
spring cloud欏圭洰璇誨彇閰嶇疆綆$悊http://www.tkk7.com/paulwong/archive/2016/09/11/431785.htmlpaulwongpaulwongSun, 11 Sep 2016 08:26:00 GMThttp://www.tkk7.com/paulwong/archive/2016/09/11/431785.htmlhttp://www.tkk7.com/paulwong/comments/431785.htmlhttp://www.tkk7.com/paulwong/archive/2016/09/11/431785.html#Feedback0http://www.tkk7.com/paulwong/comments/commentRss/431785.htmlhttp://www.tkk7.com/paulwong/services/trackbacks/431785.htmlspring cloud config server閰嶇疆濂戒簡鏁版嵁搴撹繛鎺ヤ俊鎭紝榪欎釜欏圭洰璇誨彇config錛岃幏鍙栬繛鎺ヤ俊鎭傝繖閲屼互mybtis浣滀負鍒楀瓙銆備粠鏈嶅姟鍣ㄨ鍙杍dbc淇℃伅鍚庯紝榪愯mybatis紼嬪簭銆?br />
紜鏈嶅姟鏄惁鎴愬姛
http://localhost:8888/demo-config/test
{"name":"demo-config","profiles":["test"],"label":"master","version":"02d28ad4925aa9bd1bf8a48d2edbf04ce61aa45a","propertySources":[{"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"}}]}

    2. 閰嶇疆璇誨彇閰嶇疆鏂囦歡

  



鍦╞ootstrap.properties涓坊鍔犺鍙栭厤緗鐞嗙殑鍦板潃銆?br />
3. 璇誨彇閰嶇疆鏂囦歡灞炴э紝榪欓噷閲囩敤@ConfigurationProperties
/**
 * 璇誨彇鏁版嵁搴撻厤緗枃浠?br /> * 
@author penghaozhong
 *
 
*/
@ConfigurationProperties(prefix = DataSourceProperties.PREFIX, ignoreUnknownFields = false)
public  class  DataSourceProperties {
    
        public DataSourceProperties() {
        super();
    }
        //瀵瑰簲閰嶇疆鏂囦歡閲岀殑閰嶇疆閿?/span>
        public final static String PREFIX="jdbc";    
        
        private String type; 
        private String driver; 
        private String url; 
        private String username; 
        private String password;
        
        public String getType() {
            return type;
        }
        public void setType(String type) {
            this.type = type;
        }
        public String getDriver() {
            return driver;
        }
        public void setDriver(String driver) {
            this.driver = driver;
        }
        public String getUrl() {
            return url;
        }
        public void setUrl(String url) {
            this.url = url;
        }
        public String getUsername() {
            return username;
        }
        public void setUsername(String username) {
            this.username = username;
        }
        public String getPassword() {
            return password;
        }
        public void setPassword(String password) {
            this.password = password;
        }

}


4. 閰嶇疆mybatis
@Configuration
@MapperScan("com.phz.test.spring.cloud.demo")
@EnableConfigurationProperties(DataSourceProperties.class)
@EnableTransactionManagement
public class MybatisDataSource {

    // mybaits mapper xml鎼滅儲璺緞
    private final static String MAPPERLOCATIONS = "classpath:/mappings/**/*.xml";
    private final static String CONFIGLOCATION = "classpath:/mybatis-config.xml";

    @Autowired
    private  DataSourceProperties dataSourceProperties;
    private DruidDataSource datasource = null;

    @Bean(destroyMethod = "close")
    public  DataSource dataSource(){
        datasource = new DruidDataSource();  
        datasource.setUrl(dataSourceProperties.getUrl());
        datasource.setDbType(dataSourceProperties.getType());
        datasource.setDriverClassName(dataSourceProperties.getDriver());
        datasource.setUsername(dataSourceProperties.getUsername());
        datasource.setPassword(dataSourceProperties.getPassword());
        return datasource;
    }

    @PreDestroy
    public void close() {
        if(datasource != null){
            datasource.close();
        }
    }

    @Bean
    public SqlSessionFactory sqlSessionFactoryBean() throws Exception {
        SqlSessionFactoryBean sqlSessionFactoryBean = new SqlSessionFactoryBean();
        sqlSessionFactoryBean.setDataSource(dataSource());
        PathMatchingResourcePatternResolver resolver = new PathMatchingResourcePatternResolver();
        sqlSessionFactoryBean.setMapperLocations(resolver.getResources(MAPPERLOCATIONS));
        sqlSessionFactoryBean.setConfigLocation(resolver.getResource(CONFIGLOCATION));
        sqlSessionFactoryBean.setTypeAliasesPackage("com.phz.test.spring.cloud.demo.entity");
        return sqlSessionFactoryBean.getObject();
    }

    @Bean
    public PlatformTransactionManager transactionManager() {
        return new DataSourceTransactionManager(dataSource());
    }

}













paulwong 2016-09-11 16:26 鍙戣〃璇勮
]]>
主站蜘蛛池模板: 亚洲国产精华液2020| 亚洲黄页网在线观看| 一级免费黄色毛片| 亚洲成a人无码av波多野按摩 | 桃子视频在线观看高清免费完整| 亚洲国产精品线在线观看| 中文字幕乱码一区二区免费| 在线亚洲人成电影网站色www| 国产精品九九久久免费视频| 亚洲精品无码久久久久sm| 免费看成人AA片无码视频吃奶| 亚洲大尺度无码无码专区| 日本免费久久久久久久网站| 337p日本欧洲亚洲大胆精品555588| 国产91色综合久久免费分享| 亚洲中文字幕无码一去台湾 | 亚洲av日韩aⅴ无码色老头| 四虎影视免费永久在线观看| 乱淫片免费影院观看| 亚洲爆乳精品无码一区二区三区| 久9热免费精品视频在线观看| 亚洲激情视频网站| 暖暖免费高清日本一区二区三区| 日亚毛片免费乱码不卡一区| 亚洲AV电影院在线观看| 蜜桃视频在线观看免费网址入口| 色九月亚洲综合网| 亚洲AV日韩AV天堂一区二区三区| 国产精品入口麻豆免费观看| 美女免费视频一区二区三区| 国产亚洲精品国产| 成年女人毛片免费播放人| eeuss影院www天堂免费| 亚洲男女性高爱潮网站| 国产一级理论免费版| 久久国产精品2020免费m3u8| 亚洲另类无码一区二区三区| 亚洲色欲久久久综合网| 成人免费无码视频在线网站| 国产无遮挡又黄又爽免费网站| 日韩亚洲国产高清免费视频|