springcloudѧϰ֮·: (Ò») ×î¼òµ¥µÄ´î½¨springc¡
2019-10-08 09:28:59À´Ô´£º²©¿ÍÔ° ÔĶÁ ()
springcloudѧϰ֮·: (Ò») ×î¼òµ¥µÄ´î½¨springcloudµÄ·½·¨
²Î¿¼×ÊÁÏ: [JavaEE] Îå·ÖÖӴSpringCloud»·¾³, ½øÈë΢·þÎñʱ´ú
¸ÐлÉÏƪ²©ÎÄ´óÀдøÁì×ß½øspringcloudÊÀ½ç, ±¾²©ÎÄÖ÷ҪĿµÄΪ¼Ç¼×Ô¼ºÑ§Ï°springcloudµÄµãµãµÎµÎ, ¸ø×Ô¼ºµÄ֪ʶ½øÐÐÕûÀí, Èç¹ûÄÜ°ïÖú¸ü¶àµÄС»ï°ïÄǾ͸üºÃÁË.
ps: ±¾ÎÄÖ÷Òª×÷Ϊ±¸Íü¼°¿ìËٴspringcloudÖ®ÓÃ, Ö»¼Ç¼Ö÷Òª²½Öè. ÔÎĽ²Êö¸ü¼ÓϸÖÂ, ÏëÉîÈëѧϰµÄͬѧÍƼöµã»÷ÉÏ·½Á¬½Óѧϰ.
²Ù×÷ϵͳ: Windows 10
IDE: IntelliJ IDEA 2018.3.6
JAVA: JDK 1.8.X
Meave: 3.6.0
SpringBoot: 2.1.7
1. ´´½¨Ò»¸ö¹¤³Ì
´´½¨springboot¹¤³Ì
2. ´´½¨Eureka×¢²áÖÐÐÄ
ÒÀȻѡÔñspringboot¹¤³Ì
Ñ¡Ôñeureka·þÎñÆ÷
µ¼°ü, ¿ªÆô·þÎñ¹ÜÀíÆ÷
Ϊeureka×¢²áÖÐÐÄÌí¼Ó×¢½â¿ªÆô·þÎñ
ÅäÖÃeureka×¢²áÖÐÐÄÅäÖÃÎļþ
server: # ÅäÖ÷þÎñ¶Ë¿Ú port: 8081 eureka: client: service-url: # ÅäÖÃeureka·þÎñÆ÷µØÖ· defaultZone: http://127.0.0.1:8081/eureka #ÊÇ·ñÐèÒª½«×Ô¼º×¢²áµ½×¢²áÖÐÐÄ(×¢²áÖÐÐļ¯ÈºÐèÒªÉèÖÃΪtrue) register-with-eureka: false #ÊÇ·ñÐèÒªËÑË÷·þÎñÐÅÏ¢ ÒòΪ×Ô¼ºÊÇ×¢²áÖÐÐÄËùÒÔΪfalse fetch-registry: false
×¢ÒâËõ½ø, ÒòΪyml
ʹÓÃËõ½øÀ´Çø·Ö²»Í¬×ֶεÄ.
ÔËÐÐServiceEurekaApplicationÎļþÆô¶¯ÏîÄ¿, ·ÃÎÊ×¢²áÖÐÐÄ
http://localhost:8081
3. ´´½¨Á½¸ö΢·þÎñservice-a,service-b
´´½¨Ò»¸öspringbootÄ£¿é
Æð¸öÃû×Ö
Ñ¡Ôñweb
Ñ¡Ôñ¿Í»§Ä£¿é
·ÓÉÉèÖÃ
ÅäÖÃ΢·þÎñµÄÈë¿ÚÎļþ @EnableEurekaClient
ÅäÖÃapplication.yml
service-a
server: # ·þÎñ¶Ë¿ÚºÅ port: 8082 spring: application: # ·þÎñÃû³Æ - ·þÎñÖ®¼äʹÓÃÃû³Æ½øÐÐͨѶ name: service-objcat-a eureka: client: service-url: # Ìîдע²áÖÐÐÄ·þÎñÆ÷µØÖ· defaultZone: http://localhost:8081/eureka # ÊÇ·ñÐèÒª½«×Ô¼º×¢²áµ½×¢²áÖÐÐÄ register-with-eureka: true # ÊÇ·ñÐèÒªËÑË÷·þÎñÐÅÏ¢ fetch-registry: true instance: # ʹÓÃipµØÖ·×¢²áµ½×¢²áÖÐÐÄ prefer-ip-address: true # ×¢²áÖÐÐÄÁбíÖÐÏÔʾµÄ״̬²ÎÊý instance-id: ${spring.cloud.client.ip-address}:${server.port}
service-b
server: # ·þÎñ¶Ë¿ÚºÅ port: 8083 spring: application: # ·þÎñÃû³Æ - ·þÎñÖ®¼äʹÓÃÃû³Æ½øÐÐͨѶ name: service-objcat-b eureka: client: service-url: # Ìîдע²áÖÐÐÄ·þÎñÆ÷µØÖ· defaultZone: http://localhost:8081/eureka # ÊÇ·ñÐèÒª½«×Ô¼º×¢²áµ½×¢²áÖÐÐÄ register-with-eureka: true # ÊÇ·ñÐèÒªËÑË÷·þÎñÐÅÏ¢ fetch-registry: true instance: # ʹÓÃipµØÖ·×¢²áµ½×¢²áÖÐÐÄ prefer-ip-address: true # ×¢²áÖÐÐÄÁбíÖÐÏÔʾµÄ״̬²ÎÊý instance-id: ${spring.cloud.client.ip-address}:${server.port}
ÔËÐÐ΢·þÎñ
·Ö±ðÔËÐÐ×¢²áÖÐÐļ°Î¢·þÎñÄ£¿é
³öÏֶ˿ںűíʾÆô¶¯³É¹¦
±àд²âÊÔ½Ó¿Ú
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; @RestController public class TestAController { @RequestMapping("testA") public String TestAController(){ return "Hello,SpringCloud for TestA"; } }
ÖØÆô·þÎñ
·ÃÎÊÏÂÃæµØÖ·
http://localhost:8082/testA
·ÃÎʳɹ¦
ʹÓ÷þÎñbµ÷Ó÷þÎñaµÄ½Ó¿Ú
ÕâʱÎÒÃǾÍÐèÒªÓõ½eurka(×¢²áÖÐÐÄ)
ºÍfeign
¿Í»§¶ËÁË
Ê×ÏÈÎÒÃÇÔÚservice-bÖд´½¨interface
ÔÚ΢·þÎñbÖÐ, ´´½¨Ò»¸öServiceAFeignClient½Ó¿Ú
import org.springframework.cloud.openfeign.FeignClient; import org.springframework.web.bind.annotation.RequestMapping; // ÌîÈë×¢²áÖÐÐÄÖеÄÓ¦ÓÃÃû, Ò²¾ÍÊÇÒªµ÷ÓõÄ΢·þÎñµÄÓ¦ÓÃÃû // ÔÚeurekaÒ³ÃæÖпÉÒÔÕÒµ½ @FeignClient("SERVICE-OBJCAT-A") public interface ServiceAFeignClient { @RequestMapping("testA") public String TestAController(); }
Ó¦ÓÃÃû¿ÉÒÔÔÚeurekaÖÐÕÒµ½
http://localhost:8081
ÔÚ·þÎñbÖÐÌí¼Ó¸ö¿ØÖÆÆ÷
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.cloud.netflix.eureka.EnableEurekaClient; import org.springframework.cloud.openfeign.EnableFeignClients; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; @RestController // Ìí¼Ó×¢½âÉùÃ÷ÊÇ×¢²áÖÐÐÄ¿Í»§¶Ë @EnableEurekaClient // ʵÏÖ²»Í¬×Ó·þÎñµ÷Óà @EnableFeignClients public class TestBController { @Autowired private ServiceAFeignClient serviceAFeignClient; @RequestMapping("call") public String call(){ String result = serviceAFeignClient.TestAController(); return "b to a ·ÃÎʽá¹û ---" + result; } }
½â¾ö@AutowiredʵÀý±¨´í
ÖØÐÂÔËÐзþÎñb ÔÚÍøÕ¾ÉÏ·ÃÎÊÊÔÊÔ°É
http://localhost:8083/call
PS: ÔÚspringcloudÖÐÒ»¸ö×Ó·þÎñµ÷ÓÃÁíÒ»¸ö×Ó·þÎñĬÈϳ¬Ê±Ê±¼äÊÇ1s, Ò²¾ÍÊÇ˵ҪÊDZ»µ÷ÓõÄ×Ó·þÎñ·µ»Ø³¬¹ýÒ»Ãë¾Í»á³öÏÖ´íÎó, Õë¶Ô´ËÎÊÌâÐèÒªÐ޸ĵ÷Ó÷þÎñµÄymlÎļþ.
¾ÙÀý: ÔÚ±¾°¸ÀýÖÐ, service-aÊDZ»µ÷ÓÃÕß, service-bÊǵ÷ÓÃÕß, ÔòÔÚservice-bµÄymlÎļþÖмÓÈë
ribbon: #½¨Á¢Á¬½Ó³¬Ê±Ê±¼ä ReadTimeout: 5000 #¶ÁÈ¡×ÊÔ´³¬Ê±¼ä ConnectTimeout: 5000
×¢ÒâÊ×ÐÐËõ½ø, service-bÍêÕûÅäÖÃÈçÏÂ
server: # ·þÎñ¶Ë¿ÚºÅ port: 8083 spring: application: # ·þÎñÃû³Æ - ·þÎñÖ®¼äʹÓÃÃû³Æ½øÐÐͨѶ name: service-objcat-b eureka: client: service-url: # Ìîдע²áÖÐÐÄ·þÎñÆ÷µØÖ· defaultZone: http://localhost:8081/eureka # ÊÇ·ñÐèÒª½«×Ô¼º×¢²áµ½×¢²áÖÐÐÄ register-with-eureka: true # ÊÇ·ñÐèÒªËÑË÷·þÎñÐÅÏ¢ fetch-registry: true instance: # ʹÓÃipµØÖ·×¢²áµ½×¢²áÖÐÐÄ prefer-ip-address: true # ×¢²áÖÐÐÄÁбíÖÐÏÔʾµÄ״̬²ÎÊý instance-id: ${spring.cloud.client.ip-address}:${server.port} ribbon: #½¨Á¢Á¬½Ó³¬Ê±Ê±¼ä ReadTimeout: 5000 #¶ÁÈ¡×ÊÔ´³¬Ê±¼ä ConnectTimeout: 5000
ÔÎÄÁ´½Ó:https://www.cnblogs.com/zhainan-blog/p/11634621.html
ÈçÓÐÒÉÎÊÇëÓëÔ×÷ÕßÁªÏµ
±êÇ©£º
°æȨÉêÃ÷£º±¾Õ¾ÎÄÕ²¿·Ö×ÔÍøÂ磬ÈçÓÐÇÖȨ£¬ÇëÁªÏµ£ºwest999com@outlook.com
Ìرð×¢Ò⣺±¾Õ¾ËùÓÐתÔØÎÄÕÂÑÔÂÛ²»´ú±í±¾Õ¾¹Ûµã£¬±¾Õ¾ËùÌṩµÄÉãÓ°ÕÕƬ£¬²å»£¬Éè¼Æ×÷Æ·£¬ÈçÐèʹÓã¬ÇëÓëÔ×÷ÕßÁªÏµ£¬°æȨ¹éÔ×÷ÕßËùÓÐ
ÉÏһƪ£º@AsyncÔ´Âë̽¾¿
- ѧϰJava 8 Stream Api (4) - Stream Öն˲Ù×÷Ö® collect 2020-06-11
- javaѧϰ֮µÚÒ»Ìì 2020-06-11
- Javaѧϰ֮µÚ¶þÌì 2020-06-11
- Spring WebFlux ѧϰ±Ê¼Ç - (Ò») Ç°´«:ѧϰJava 8 Stream Ap 2020-06-11
- Linux¼òµ¥ÃüÁîµÄѧϰ 2020-06-10
IDC×ÊѶ£º Ö÷»ú×ÊѶ ×¢²á×ÊѶ ÍйÜ×ÊѶ vps×ÊѶ ÍøÕ¾½¨Éè
ÍøÕ¾ÔËÓª£º ½¨Õ¾¾Ñé ²ß»®Ó¯Àû ËÑË÷ÓÅ»¯ ÍøÕ¾Íƹã Ãâ·Ñ×ÊÔ´
ÍøÕ¾ÁªÃË£º ÁªÃËÐÂÎÅ ÁªÃ˽éÉÜ ÁªÃ˵ãÆÀ Íø׬¼¼ÇÉ
ÐÐÒµ×ÊѶ£º ËÑË÷ÒýÇæ ÍøÂçÓÎÏ· µç×ÓÉÌÎñ ¹ã¸æ´«Ã½
ÍøÂç±à³Ì£º Asp.Net±à³Ì Asp±à³Ì Php±à³Ì Xml±à³Ì Access Mssql Mysql ÆäËü
·þÎñÆ÷¼¼Êõ£º Web·þÎñÆ÷ Ftp·þÎñÆ÷ Mail·þÎñÆ÷ Dns·þÎñÆ÷ °²È«·À»¤
Èí¼þ¼¼ÇÉ£º ÆäËüÈí¼þ Word Excel Powerpoint Ghost Vista QQ¿Õ¼ä QQ FlashGet ѸÀ×
ÍøÒ³ÖÆ×÷£º FrontPages Dreamweaver Javascript css photoshop fireworks Flash
³ÌÐòÉè¼Æ£º Java¼¼Êõ C/C++ VB delphi
- Photoshop»æÖÆÁ¢Ìå·ç¸ñµÄ΢Ц±íÇé
- PSÎÄ×ÖÌØЧ½Ì³Ì£ºÖÆ×÷¹«Â·ÉϸöÐÔµÄÍ¿Ñ»
- PhotoshopÉè¼Æ¾í±ßЧ¹ûµÄ±äÐνð¸ÕµçÓ°
- PSÉ«²ÊÐÞ¸´½Ì³Ì£ºÀûÓÃÉ«½×¹¤¾ß¿ìËÙ¸øºì
- PS°ë͸Ã÷ÎïÌå¿Ùͼ£ºÀûÓÃͨµÀÑ¡Çø¹¤¾ß¿Ù
- PSº£±¨Éè¼Æ¼¼Çɽ̳̣ºÑ§Ï°ÖÆ×÷¸öÐԵč
- PSͼƬÌØЧÖÆ×÷½Ì³Ì£ºÑ§Ï°¸øÌúËþͼƬÖÆ
- ѧϰÓÃphotoshop°Ñ»ë×ǵĺ£Ë®ÕÕƬºóÆÚ
- PS¹Å·çÕÕƬ½Ì³Ì£º¸ø¹Å·çÃÀÅ®´òÔì³öÅ®ÏÀ
- PS¸öÐÔÈËÎﺣ±¨ÖÆ×÷£ºÉè¼Æ´´ÒâʱÉеIJ£
- ʲôÈí¼þ¿ÉÒÔµÁȡ΢ÐźÅÃÜÂë,ÔõôµÁ±ð
- ´ÅÁ¦ËÑË÷ÍøÕ¾µ¼º½2020Äê¸üÐÂ
- springcloudѧϰ֮·: (Ò») ×î¼òµ¥µÄ´î
- ´´½¨Gradle¹¤³Ì³öÏÖCould not install
- ³¹µ×Ū¶®¡°PKIX path building failed
- TomcatÆô¶¯±¨´í:org.apache.catalina.L
- spring boot ´íÎó£ºCheck your ViewRes
- »ùÓÚHttpClientµÄаæÕý·½½ÌÎñϵͳģÄâ
- Ö»ÓгÌÐòÔ±²ÅÄÜ¿´¶®µÄ³µÅÆ£¬¶®µÃ×ÔÈ»¶®
- mybatis ×¢½â@Results¡¢@Result¡¢@Resu