Spring-boot-starter常用依賴模塊有哪些-創(chuàng)新互聯(lián)

              這篇文章給大家分享的是有關(guān)Spring-boot-starter常用依賴模塊有哪些的內(nèi)容。小編覺得挺實(shí)用的,因此分享給大家做個(gè)參考,一起跟隨小編過來看看吧。

              在武侯等地區(qū),都構(gòu)建了全面的區(qū)域性戰(zhàn)略布局,加強(qiáng)發(fā)展的系統(tǒng)性、市場前瞻性、產(chǎn)品創(chuàng)新能力,以專注、極致的服務(wù)理念,為客戶提供成都網(wǎng)站制作、網(wǎng)站建設(shè)、外貿(mào)網(wǎng)站建設(shè) 網(wǎng)站設(shè)計(jì)制作按需制作,公司網(wǎng)站建設(shè),企業(yè)網(wǎng)站建設(shè),成都品牌網(wǎng)站建設(shè),營銷型網(wǎng)站,成都外貿(mào)網(wǎng)站建設(shè)公司,武侯網(wǎng)站建設(shè)費(fèi)用合理。

              Spring-boot的2大優(yōu)點(diǎn):

              1.基于Spring框架的“約定優(yōu)先于配置(COC)”理念以及最佳實(shí)踐之路。

              2.針對(duì)日常企業(yè)應(yīng)用研發(fā)各種場景的Spring-boot-starter自動(dòng)配置依賴模塊,且“開箱即用”(約定spring-boot-starter- 作為命名前綴,都位于org.springframenwork.boot包或者命名空間下)。

              應(yīng)用日志和spring-boot-starter-logging

              常見的日志系統(tǒng)大致有:java.util默認(rèn)提供的日志支持,log4j,log4j2,commons logging,下面的spring-boot-starter-logging也是其中的一種。

              maven依賴:

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

              springBoot將使用logback作為應(yīng)用日志的框架,程序啟動(dòng)時(shí),由org.springframework.boot.logging-Logging-Application-Lisetener根據(jù)情況初始化并使用。

              如果要想改變springBoot提供的應(yīng)用日志設(shè)定,可以通過一下原則:

              遵循logback的約定,在classpath中使用自己定制的logback.xml配置文件。

              在文件系統(tǒng)的任意一個(gè)位置提供自己的logback.xml配置文件,然后通過logging.config配置項(xiàng)指向這個(gè)配置文件然后引用它,例如在application.properties中指定如下的配置:

              logging.config=/{some.path.you.defined}/any-logfile-name-I-like.log}

              快速web應(yīng)用開發(fā)與spring-boot-starter-web

              maven依賴:

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

              在當(dāng)下項(xiàng)目運(yùn)行mvn spring-boot:run就可以直接啟用一個(gè)嵌套了tomcat的web應(yīng)用。

              如果沒有提供任何服務(wù)的Cotroller,訪問任何路徑都會(huì)返回一個(gè)springBoot默認(rèn)的錯(cuò)誤頁面(Whitelabel error page)。

              嵌入式Web容器層面的約定和定制

              spring-boot-starter-web默認(rèn)使用嵌套式的Tomcat作為Web容器對(duì)外提供HTTP服務(wù),默認(rèn)端口8080對(duì)外監(jiān)聽和提供服務(wù)。

              我們同樣可以使用 spring-boot-starter-jetty 或者 spring-boot-starter-undertow 作為Web容器。

              想改變默認(rèn)的配置端口,可以在application.properties中指定:

              server.port = 9000(the port number you want)

              類似的配置還有:

              server.address
              server.ssl.*
              server.tomcat.*

              如果上訴仍然沒有辦法滿足要求,springBoot支持對(duì)嵌入式的Web容器實(shí)例進(jìn)行定制,可以通過向IoC容器中注冊(cè)一個(gè)EmbeddedServletContainerCustomizer類型的組件來對(duì)嵌入式的Web容器進(jìn)行定制

              public class UnveilSpringEmbeddedTomcatCustomizer implements EmbeddedServletContainer{
                  public void customize(ConfigurableEmbeddedServletContainer container){
                    container.setPort(9999);
                    container.setContextPath("C\\hello");
                            ...
                  }
                }

              數(shù)據(jù)訪問與spring-boot-starter-jdbc

              maven依賴:

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

              默認(rèn)情況下,當(dāng)我們沒有配置任何DataSource,SpringBoot會(huì)為我們自動(dòng)配置一個(gè)DataSource,這種自動(dòng)配置的方式一般適用于測試,開發(fā)還是自己配置一個(gè)DataSource的實(shí)例比較好。

              如果我們的工程只依賴一個(gè)數(shù)據(jù)庫,那么,使用DataSource自動(dòng)配置模塊提供的參數(shù)是最方便的:

              spring.datasource.url=jdbc:mysql://{datasource host}:3306/{databaseName}
              spring.datasource.username={database username}
              spring.datasource.passwd={database passwd}

              還會(huì)自動(dòng)配置的有:JdbcTemplate DateSourceTransactionManager等,我們只要在使用的時(shí)候注入(@Autowired)就好了

              此外,SpringBoot還支持的數(shù)據(jù)庫有spring-boot-data-jpa spring-boot-data-mongodb

              spring-boot-starter-aop應(yīng)用及其使用場景

              AOP:Aspect Oriented Programming,面向切面編程

              maven依賴:

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

              spring-boot-starter-aop主要由2部分組成:

              1.位于spring-boot-autoconfigure的org.sringframework.boot.autoconfigure.aop.AopAutoConfiguration提供的@Configuration配置類和相應(yīng)的配置項(xiàng),即下面的2個(gè)配置項(xiàng):

              spring.aop.auto=true
              spring.aop.proxy-target-class=false

              2.spring-boot-starter-aop模塊提供了針對(duì)spring-aop aspectjrt 和aspectjweaver的依賴

              應(yīng)用安全與spring-boot-starter-security //todo

              感謝各位的閱讀!關(guān)于“Spring-boot-starter常用依賴模塊有哪些”這篇文章就分享到這里了,希望以上內(nèi)容可以對(duì)大家有一定的幫助,讓大家可以學(xué)到更多知識(shí),如果覺得文章不錯(cuò),可以把它分享出去讓更多的人看到吧!

              當(dāng)前標(biāo)題:Spring-boot-starter常用依賴模塊有哪些-創(chuàng)新互聯(lián)
              文章URL:http://www.muchs.cn/article4/dhoioe.html

              成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供企業(yè)網(wǎng)站制作自適應(yīng)網(wǎng)站、微信小程序、GoogleApp開發(fā)、網(wǎng)站建設(shè)

              廣告

              聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場,如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來源: 創(chuàng)新互聯(lián)

              外貿(mào)網(wǎng)站制作