久久精品精选,精品九九视频,www久久只有这里有精品,亚洲熟女乱色综合一区
    分享

    SpringBoot項目 Component Autowired

     KyunraWang 2017-03-23

    SpringBoot是做微服務架構非常好的一套框架,下面來講講我的第一個SpringBoot項目;

    1、依賴

    1. <properties>  
    2.     <spring.boot.version>1.3.2.RELEASE</spring.boot.version>  
    3. </properties>  
    4. dependencies>  
    5.     <dependency>  
    6.         <groupId>org.springframework.boot</groupId>  
    7.         <artifactId>spring-boot-starter-web</artifactId>  
    8.         <version>${spring.boot.version}</version>  
    9.     </dependency>  
    10.     <dependency>  
    11.         <groupId>org.springframework.boot</groupId>  
    12.         <artifactId>spring-boot-starter</artifactId>  
    13.         <version>${spring.boot.version}</version>  
    14.     </dependency>  
    15.     <dependency>  
    16.         <groupId>org.springframework.boot</groupId>  
    17.         <artifactId>spring-boot-starter-test</artifactId>  
    18.         <scope>test</scope>  
    19.         <version>${spring.boot.version}</version>  
    20.     </dependency>  
    21.     <dependency>  
    22.         <groupId>org.assertj</groupId>  
    23.         <artifactId>assertj-core</artifactId>  
    24.         <version>3.4.1</version>  
    25.     </dependency>  
    26.     <dependency>  
    27.         <groupId>org.springframework</groupId>  
    28.         <artifactId>spring-test</artifactId>  
    29.         <version>2.5</version>  
    30.     </dependency>  
    31. </dependencies>  
    32. <build>  
    33.     <plugins>  
    34.         <plugin>  
    35.             <groupId>org.springframework.boot</groupId>  
    36.             <artifactId>spring-boot-maven-plugin</artifactId>  
    37.             <version>${spring.boot.version}</version>  
    38.             <executions>  
    39.                 <execution>  
    40.                     <goals>  
    41.                         <goal>repackage</goal>  
    42.                     </goals>  
    43.                 </execution>  
    44.             </executions>  
    45.         </plugin>  
    46.     </plugins>  
    47. </build>  

    2、Application類,這是SpringBoot啟動服務的類;

    1. package simple;  
    2.   
    3. import org.springframework.beans.factory.annotation.Autowired;  
    4. import org.springframework.beans.factory.annotation.Qualifier;  
    5. import org.springframework.boot.CommandLineRunner;  
    6. import org.springframework.boot.SpringApplication;  
    7. import org.springframework.boot.autoconfigure.SpringBootApplication;  
    8. import simple.service.ExampleOneService;  
    9.   
    10. /** 
    11.  * Created by LK on 2016/4/24. 
    12.  */  
    13. @SpringBootApplication  
    14. public class SimpleApplication implements CommandLineRunner{  
    15.   
    16.     @Autowired  
    17.     @Qualifier("exampleOneService")  
    18.     private ExampleOneService exampleOneService;  
    19.   
    20.     public void run(String... strings) throws Exception {  
    21.         System.out.println(this.exampleOneService.getExampleOneMessage());  
    22.         if(strings.length > 0 && strings[0].equals("exitcode")){  
    23.             throw new ExitException();  
    24.         }  
    25.     }  
    26.     public static void main(String[] args) {  
    27.         SpringApplication.run(SimpleApplication.class,args);  
    28.     }  
    29. }  

    3、由于上面需要引用服務才可以獲得內容,所以我們也得創建一個服務類;

    1. package simple.service;  
    2.   
    3. import org.springframework.beans.factory.annotation.Value;  
    4. import org.springframework.stereotype.Component;  
    5.   
    6. /** 
    7.  * Created by LK on 2016/4/24. 
    8.  */  
    9. @Component  
    10. public class ExampleOneService {  
    11.     @Value("${name:我的第一個SpringBoot}")  //name:后面的值可以在resources里面的application.properties中配置,如果不配置,那么久默認為程序里面的值  
    12.     private String name;  
    13.   
    14.     public String getExampleOneMessage(){  
    15.         return "看," + name;  
    16.     }  
    17. }  

    4、上面說application.properties,那么我們還得創建一個這樣子的文件,并配置好需要的信息;

    1. name:我的第一個SpringBoot  

    5、去到
    1. SimpleApplication 類中,右鍵運行main運行項目,又或者Teminal控制臺執行mvn spring-boot:run可以運行項目  
    1. </pre><pre code_snippet_id="1660186" snippet_file_name="blog_20160424_7_6717521" name="code" class="java">  

      本站是提供個人知識管理的網絡存儲空間,所有內容均由用戶發布,不代表本站觀點。請注意甄別內容中的聯系方式、誘導購買等信息,謹防詐騙。如發現有害或侵權內容,請點擊一鍵舉報。
      轉藏 分享 獻花(0

      0條評論

      發表

      請遵守用戶 評論公約

      類似文章 更多

      主站蜘蛛池模板: 国产欧美久久一区二区三区| 精品无码一区在线观看| 国产高跟黑色丝袜在线 | 精品人妻无码专区在中文字幕| 亚洲日韩精品无码av海量| 婷婷色爱区综合五月激情韩国| 亚洲AV无码一区东京热久久| 国产精品美女久久久久久麻豆| 韩国无码AV片在线观看网站 | 亚洲人成电影在线天堂色| 亚洲性色AV一区二区三区| 最新中文字幕国产精品| 日韩A人毛片精品无人区乱码| 99国产欧美另类久久久精品| 亚洲人成中文字幕在线观看| 国产一区二区三区在线观看免费| 亚洲AV美女在线播放啊| 亚洲精品日韩久久精品| 88国产精品欧美一区二区三区| 高清无码爆乳潮喷在线观看| 99精品国产在热久久婷婷| 国产99在线 | 免费| 精品一区二区亚洲国产| 少妇肉麻粗话对白视频| 国产成人综合95精品视频| 国产美女高潮流白浆视频| 夜夜高潮夜夜爽高清完整版1| 午夜福利片1000无码免费| 人人妻人人澡人人爽人人DVD | 激情综合婷婷色五月蜜桃| 天堂亚洲免费视频| 公喝错春药让我高潮| 又粗又大又黄又硬又爽免费看| 欧洲一区二区中文字幕| 在线亚洲人成电影网站色WWW| 精品国产AV最大网站| 国产成人亚洲综合图区| 久久综合九色欧美综合狠狠| 狠狠色噜噜狠狠狠狠AV| 免费看成人毛片无码视频| 国产一区二区三区导航|