spring boot框架eclipse快速搭建


1.maven安裝配置好,使用eclipse創建maven項目(選擇maven-archetype-quickstart)

2.然后進入http://docs.spring.io/spring-boot/docs/1.5.1.RELEASE/reference/htmlsingle/(maven installation)配置pom.xml文件

<!-- Inherit defaults from Spring Boot -->
    <parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>1.5.1.RELEASE</version> </parent> <!-- Add typical dependencies for a web application --> <dependencies> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency> </dependencies> <!-- Package as an executable jar --> <build> <plugins> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> </plugin> </plugins> </build>

注釋:eclipse創建maven項目時,自動加入了junit,我在創建時刪除了junit模塊依賴 與 test源碼包

3.編寫測試類

 1 package hello;
 2 
 3 import org.springframework.boot.*;
 4 import org.springframework.boot.autoconfigure.*;
 5 import org.springframework.stereotype.*;
 6 import org.springframework.web.bind.annotation.*;
 7 
 8 @Controller
 9 @EnableAutoConfiguration
10 public class App{
11 
12     @RequestMapping("/")
13     @ResponseBody
14     String home() {
15         return "Hello World!";
16     }
17 
18     public static void main(String[] args) throws Exception {
19         SpringApplication.run(App.class, args);
20     }
21 }

4.最后進入項目根目錄pom.xml文件下,執行mvn clean install

耐心等待maven構建完,運行App main方法,服務啟動,成功。

啟動后默認訪問端口及地址是:http://127.0.0.1:8080

 

打包:

mvn clean install

會在項目target目錄下生成jar執行文件

 

發布:

java -jar *-SNAPSHOT.jar

 

關注我的微信共享學習,討論更多技術知識


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM