ΪʲôҪѧϰ Spring Boot£¿

2019-02-27 11:52:48À´Ô´£º²©¿ÍÔ° ÔĶÁ ()

ÐÂÀÏ¿Í»§´ó»ØÀ¡,ÔÆ·þÎñÆ÷µÍÖÁ5ÕÛ

ÎÒÃÇÖªµÀ£¬´Ó 2002 Ä꿪ʼ£¬Spring Ò»Ö±ÔÚ·ÉËٵķ¢Õ¹£¬Èç½ñÒѾ­³ÉΪÁËÔÚJava EE£¨Java Enterprise Edition£©¿ª·¢ÖÐÕæÕýÒâÒåÉϵıê×¼£¬µ«ÊÇËæ׿¼ÊõµÄ·¢Õ¹£¬Java EEʹÓà Spring Öð½¥±äµÃ±¿ÖØÆðÀ´£¬´óÁ¿µÄ XML Îļþ´æÔÚÓÚÏîÄ¿Ö®ÖС£·±ËöµÄÅäÖã¬ÕûºÏµÚÈý·½¿ò¼ÜµÄÅäÖÃÎÊÌ⣬µ¼ÖÂÁË¿ª·¢ºÍ²¿ÊðЧÂʵĽµµÍ¡£

2012 Äê 10 Ô£¬Mike Youngstrom ÔÚ Spring jira Öд´½¨ÁËÒ»¸ö¹¦ÄÜÇëÇó£¬ÒªÇóÔÚ Spring ¿ò¼ÜÖÐÖ§³ÖÎÞÈÝÆ÷ Web Ó¦ÓóÌÐòÌåϵ½á¹¹¡£Ëû̸µ½ÁËÔÚÖ÷ÈÝÆ÷Òýµ¼ spring ÈÝÆ÷ÄÚÅäÖà Web ÈÝÆ÷·þÎñ¡£ÕâÊÇ jira ÇëÇóµÄժ¼£º

ÎÒÈÏΪ Spring µÄ Web Ó¦ÓÃÌåϵ½á¹¹¿ÉÒÔ´ó´ó¼ò»¯£¬Èç¹ûËüÌṩÁË´ÓÉϵ½ÏÂÀûÓà Spring ×é¼þºÍÅäÖÃÄ£Ð͵Ť¾ßºÍ²Î¿¼Ìåϵ½á¹¹¡£ÔÚ¼òµ¥µÄ main()·½·¨Òýµ¼µÄ Spring ÈÝÆ÷ÄÚǶÈëºÍͳһÕâЩ³£ÓÃWeb ÈÝÆ÷·þÎñµÄÅäÖá£

ÕâÒ»ÒªÇó´ÙʹÁË 2013 Äê³õ¿ªÊ¼µÄ Spring Boot ÏîÄ¿µÄÑз¢£¬µ½½ñÌ죬Spring Boot µÄ°æ±¾ÒѾ­µ½ÁË 2.0.3 RELEASE¡£Spring Boot ²¢²»ÊÇÓÃÀ´Ìæ´ú Spring µÄ½â¾ö·½°¸£¬¶øÊÇºÍ Spring ¿ò¼Ü½ôÃܽáºÏÓÃÓÚÌáÉý Spring ¿ª·¢ÕßÌåÑéµÄ¹¤¾ß¡£Í¬Ê±Ëü¼¯³ÉÁË´óÁ¿³£ÓõĵÚÈý·½¿âÅäÖã¬Spring BootÓ¦ÓÃÖÐÕâЩµÚÈý·½¿â¼¸ºõ¿ÉÒÔÊÇÁãÅäÖõĿªÏä¼´Óã¨out-of-the-box£©£¬´ó²¿·ÖµÄ Spring Boot Ó¦Óö¼Ö»ÐèÒª·Ç³£ÉÙÁ¿µÄÅäÖôúÂ루»ùÓÚ Java µÄÅäÖã©£¬¿ª·¢ÕßÄܹ»¸ü¼ÓרעÓÚÒµÎñÂß¼­¡£

ΪʲôѧϰSpring Boot

´ÓSpring¹Ù·½À´¿´

ÎÒÃÇ´ò¿ª Spring µÄ¹Ù·½ÍøÕ¾£¬¿ÉÒÔ¿´µ½ÏÂͼ£º

 

 
ͼ0£ºÎªÊ²Ã´ÒªÑ§Ï°Spring Boot£¿

 

ÎÒÃÇ¿ÉÒÔ¿´µ½Í¼Öйٷ½¶Ô Spring Boot µÄ¶¨Î»£ºBuild Anything£¬ BuildÈκζ«Î÷¡£Spring BootÖ¼ÔÚ¾¡¿ÉÄÜ¿ìµØÆô¶¯ºÍÔËÐУ¬²¢ÇÒÖ»Ðè×îÉÙµÄ Spring Ç°ÆÚÅäÖᣠͬʱÎÒÃÇÒ²À´¿´Ò»Ï¹ٷ½¶ÔºóÃæÁ½¸öµÄ¶¨Î»£º

SpringCloud£ºCoordinate Anything£¬Ð­µ÷ÈκÎÊÂÇ飻
SpringCloud Data Flow£ºConnect everything£¬Á¬½ÓÈκζ«Î÷¡£

×ÐϸƷζһÏ£¬Spring ¹ÙÍø¶Ô Spring Boot¡¢SpringCloud ºÍ SpringCloud Data FlowÈýÕ߶¨Î»µÄ´ë´Ç·Ç³£ÓÐζµÀ£¬Í¬Ê±Ò²¿ÉÒÔ¿´³ö£¬Spring ¹Ù·½¶ÔÕâÈý¸ö¼¼Êõ·Ç³£ÖØÊÓ£¬ÊÇÏÖÔÚÒÔ¼°½ñºóѧϰµÄÖص㣨SpringCloud Ïà¹Ø´ïÈ˿ογ̽ìʱҲ»áÉÏÏߣ©¡£

´ÓSpring BootµÄÓŵãÀ´¿´

Spring Boot ÓÐÄÄЩÓŵ㣿Ö÷Òª¸øÎÒÃǽâ¾öÁËÄÄЩÎÊÌâÄØ£¿ÎÒÃÇÒÔÏÂͼÀ´ËµÃ÷£º

 

 
ͼ1£ºÎªÊ²Ã´ÒªÑ§Ï°Spring Boot£¿

 

Á¼ºÃµÄ»ùÒò

Spring Boot ÊÇ°éËæ×Å Spring 4.0 µ®ÉúµÄ£¬´Ó×ÖÃæÀí½â£¬BootÊÇÒýµ¼µÄÒâ˼£¬Òò´Ë Spring Boot Ö¼ÔÚ°ïÖú¿ª·¢Õß¿ìËٴ Spring ¿ò¼Ü¡£Spring Boot ¼Ì³ÐÁËÔ­ÓÐ Spring ¿ò¼ÜµÄÓÅÐã»ùÒò£¬Ê¹ Spring ÔÚʹÓÃÖиü¼Ó·½±ã¿ì½Ý¡£

 

 
ͼ2£ºÎªÊ²Ã´ÒªÑ§Ï°Spring Boot£¿

 

¼ò»¯±àÂë

¾Ù¸öÀý×Ó£¬±ÈÈçÎÒÃÇÒª´´½¨Ò»¸ö web ÏîÄ¿£¬Ê¹Óà Spring µÄÅóÓѶ¼ÖªµÀ£¬ÔÚʹÓà Spring µÄʱºò£¬ÐèÒªÔÚ pom ÎļþÖÐÌí¼Ó¶à¸öÒÀÀµ£¬¶ø Spring Boot Ôò»á°ïÖú¿ª·¢×Å¿ìËÙÆô¶¯Ò»¸ö web ÈÝÆ÷£¬ÔÚ Spring Boot ÖУ¬ÎÒÃÇÖ»ÐèÒªÔÚ pom ÎļþÖÐÌí¼ÓÈçÏÂÒ»¸ö starter-web ÒÀÀµ¼´¿É¡£

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-web</artifactId>
</dependency>

ÎÒÃǵã»÷½øÈë¸ÃÒÀÀµºó¿ÉÒÔ¿´µ½£¬Spring Boot Õâ¸ö starter-web ÒѾ­°üº¬Á˶à¸öÒÀÀµ£¬°üÀ¨Ö®Ç°ÔÚ Spring ¹¤³ÌÖÐÐèÒªµ¼ÈëµÄÒÀÀµ£¬ÎÒÃÇ¿´Ò»ÏÂÆäÖеÄÒ»²¿·Ö£¬ÈçÏ£º

<!-- .....Ê¡ÂÔÆäËûÒÀÀµ -->
<dependency>
    <groupId>org.springframework</groupId>
    <artifactId>spring-web</artifactId>
    <version>5.0.7.RELEASE</version>
    <scope>compile</scope>
</dependency>
<dependency>
    <groupId>org.springframework</groupId>
    <artifactId>spring-webmvc</artifactId>
    <version>5.0.7.RELEASE</version>
    <scope>compile</scope>
</dependency>

ÓÉ´Ë¿ÉÒÔ¿´³ö£¬Spring Boot ´ó´ó¼ò»¯ÁËÎÒÃǵıàÂ룬ÎÒÃDz»ÓÃÒ»¸ö¸öµ¼ÈëÒÀÀµ£¬Ö±½ÓÒ»¸öÒÀÀµ¼´¿É¡£

 

¼ò»¯ÅäÖÃ

Spring ËäȻʹJava EEÇáÁ¿¼¶¿ò¼Ü£¬µ«ÓÉÓÚÆä·±ËöµÄÅäÖã¬Ò»¶È±»ÈËÈÏΪÊÇ“ÅäÖõØÓü”¡£¸÷ÖÖXML¡¢AnnotationÅäÖûáÈÃÈËÑÛ»¨çÔÂÒ£¬¶øÇÒÅäÖöàµÄ»°£¬Èç¹û³ö´íÁËÒ²ºÜÄÑÕÒ³öÔ­Òò¡£Spring Boot¸ü¶àµÄÊDzÉÓà Java Config µÄ·½Ê½£¬¶Ô Spring ½øÐÐÅäÖ᣾ٸöÀý×Ó£º

ÎÒн¨Ò»¸öÀ࣬µ«ÊÇÎÒ²»Óà@Service×¢½â£¬Ò²¾ÍÊÇ˵£¬ËüÊǸöÆÕͨµÄÀ࣬ÄÇôÎÒÃÇÈçºÎʹËüÒ²³ÉΪһ¸ö Bean Èà Spring È¥¹ÜÀíÄØ£¿Ö»ÐèÒª@Configuration ºÍ@BeanÁ½¸ö×¢½â¼´¿É£¬ÈçÏ£º

public class TestService {
    public String sayHello () {
        return "Hello Spring Boot!";
    }
}
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class JavaConfig {
    @Bean
    public TestService getTestService() {
        return new TestService();
    }
}

@Configuration±íʾ¸ÃÀàÊǸöÅäÖÃÀ࣬@Bean±íʾ¸Ã·½·¨·µ»ØÒ»¸ö Bean¡£ÕâÑù¾Í°ÑTestService×÷Ϊ Bean Èà Spring È¥¹ÜÀíÁË£¬ÔÚÆäËûµØ·½£¬ÎÒÃÇÈç¹ûÐèҪʹÓøà Bean£¬ºÍÔ­À´Ò»Ñù£¬Ö±½ÓʹÓÃ@Resource×¢½â×¢Èë½øÀ´¼´¿ÉʹÓ㬷dz£·½±ã¡£

@Resource
private TestService testService;

ÁíÍ⣬²¿ÊðÅäÖ÷½Ã棬ԭÀ´ Spring Óжà¸ö xml ºÍ propertiesÅäÖã¬ÔÚ Spring Boot ÖÐÖ»ÐèÒª¸ö application.yml¼´¿É¡£

 

¼ò»¯²¿Êð

ÔÚʹÓà Spring ʱ£¬ÏîÄ¿²¿ÊðʱÐèÒªÎÒÃÇÔÚ·þÎñÆ÷Éϲ¿Êð tomcat£¬È»ºó°ÑÏîÄ¿´ò³É war °üÈÓµ½ tomcatÀÔÚʹÓà Spring Boot ºó£¬ÎÒÃDz»ÐèÒªÔÚ·þÎñÆ÷ÉÏÈ¥²¿Êð tomcat£¬ÒòΪ Spring Boot ÄÚǶÁË tomcat£¬ÎÒÃÇÖ»ÐèÒª½«ÏîÄ¿´ò³É jar °ü£¬Ê¹Óàjava -jar xxx.jarÒ»¼üʽÆô¶¯ÏîÄ¿¡£

ÁíÍ⣬Ҳ½µµÍ¶ÔÔËÐл·¾³µÄ»ù±¾ÒªÇ󣬻·¾³±äÁ¿ÖÐÓÐJDK¼´¿É¡£

 

¼ò»¯¼à¿Ø

ÎÒÃÇ¿ÉÒÔÒýÈë spring-boot-start-actuator ÒÀÀµ£¬Ö±½ÓʹÓà REST ·½Ê½À´»ñÈ¡½ø³ÌµÄÔËÐÐÆÚÐÔÄܲÎÊý£¬´Ó¶ø´ïµ½¼à¿ØµÄÄ¿µÄ£¬±È½Ï·½±ã¡£µ«ÊÇ Spring Boot Ö»ÊǸö΢¿ò¼Ü£¬Ã»ÓÐÌṩÏàÓ¦µÄ·þÎñ·¢ÏÖÓë×¢²áµÄÅäÌ×¹¦ÄÜ£¬Ã»ÓÐÍâΧ¼à¿Ø¼¯³É·½°¸£¬Ã»ÓÐÍâΧ°²È«¹ÜÀí·½°¸£¬ËùÒÔÔÚ΢·þÎñ¼Ü¹¹ÖУ¬»¹ÐèÒª Spring Cloud À´ÅäºÏÒ»ÆðʹÓá£

 

´ÓδÀ´·¢Õ¹µÄÇ÷ÊÆÀ´¿´

΢·þÎñÊÇδÀ´·¢Õ¹µÄÇ÷ÊÆ£¬ÏîÄ¿»á´Ó´«Í³¼Ü¹¹ÂýÂýתÏò΢·þÎñ¼Ü¹¹£¬ÒòΪ΢·þÎñ¿ÉÒÔʹ²»Í¬µÄÍŶÓרעÓÚ¸üС·¶Î§µÄ¹¤×÷Ö°Ôð¡¢Ê¹ÓöÀÁ¢µÄ¼¼Êõ¡¢¸ü°²È«¸üƵ·±µØ²¿Ê𡣶ø ¼Ì³ÐÁË Spring µÄÓÅÁ¼ÌØÐÔ£¬Óë Spring Ò»ÂöÏà³Ð£¬¶øÇÒ Ö§³Ö¸÷ÖÖREST API µÄʵÏÖ·½Ê½¡£Spring Boot Ò²Êǹٷ½´óÁ¦ÍƼöµÄ¼¼Êõ£¬¿ÉÒÔ¿´³ö£¬Spring Boot ÊÇδÀ´·¢Õ¹µÄÒ»¸ö´óÇ÷ÊÆ¡£

 

 

Ãâ·ÑJava×ÊÁÏÁìÈ¡£¬º­¸ÇÁËJava¡¢Redis¡¢MongoDB¡¢MySQL¡¢Zookeeper¡¢Spring Cloud¡¢Dubbo/Kafka¡¢Hadoop¡¢Hbase¡¢FlinkµÈ¸ß²¢·¢·Ö²¼Ê½¡¢´óÊý¾Ý¡¢»úÆ÷ѧϰµÈ¼¼Êõ¡£

 ´«ËÍÃÅ£ºhttps://mp.weixin.qq.com/s/JzddfH-7yNudmkjT0IRL8Q

 

 

Ô­ÎÄÁ´½Ó:https://www.cnblogs.com/yuxiang1/p/10440306.html
ÈçÓÐÒÉÎÊÇëÓëÔ­×÷ÕßÁªÏµ

±êÇ©£º

°æȨÉêÃ÷£º±¾Õ¾ÎÄÕ²¿·Ö×ÔÍøÂ磬ÈçÓÐÇÖȨ£¬ÇëÁªÏµ£ºwest999com@outlook.com
Ìرð×¢Ò⣺±¾Õ¾ËùÓÐתÔØÎÄÕÂÑÔÂÛ²»´ú±í±¾Õ¾¹Ûµã£¬±¾Õ¾ËùÌṩµÄÉãÓ°ÕÕƬ£¬²å»­£¬Éè¼Æ×÷Æ·£¬ÈçÐèʹÓã¬ÇëÓëÔ­×÷ÕßÁªÏµ£¬°æȨ¹éÔ­×÷ÕßËùÓÐ

ÉÏһƪ£º¸ãJavaµÄÄêн 40W ÊÇʲôˮƽ£¿

ÏÂһƪ£ºjava»ù´¡(Ê®Èý)-----Ïê½âÄÚ²¿Àࡪ¡ªJava¸ß¼¶¿ª·¢±ØÐ붮µÄ