javascript
第一章:SpringBoot入门
2019獨角獸企業重金招聘Python工程師標準>>>
源碼下載:https://u11556602.ctfile.com/fs/11556602-361219278
????????????????https://download.csdn.net/download/qq_36267875/11089023
1.創建maven項目
2.如果要想開發springboot程序只需要按照官方給出的要求配置一個父pom即可。
將下面的配置拷貝到pom中
<parent><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-parent</artifactId><version>1.5.4.RELEASE</version></parent>就像下面這樣 pom
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"><modelVersion>4.0.0</modelVersion><parent><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-parent</artifactId><version>1.5.4.RELEASE</version></parent><groupId>com.mldn</groupId><artifactId>bootfirst</artifactId><version>0.0.1-SNAPSHOT</version><packaging>jar</packaging><name>bootfirst</name><url>http://maven.apache.org</url><properties><project.build.sourceEncoding>UTF-8</project.build.sourceEncoding></properties><dependencies><dependency><groupId>junit</groupId><artifactId>junit</artifactId><version>3.8.1</version><scope>test</scope></dependency></dependencies> </project>然后發現junit的版本顯示黃色感嘆號,這是因為,我們引入了的parent里面規定了版本號,所以這里的版本號就可以去掉了
設置jdk版本
在<properties>中設置版本號
<properties><jdk.version>1.8</jdk.version><project.build.sourceEncoding>UTF-8</project.build.sourceEncoding></properties>設置插件
<build><finalName>bootfirst</finalName><plugins><plugin><groupId>org.apache.maven.plugins</groupId><artifactId>maven-compiler-plugin</artifactId><configuration><source>${jdk.version}</source><!-- 源代碼使用的開發版本 --><target>${jdk.version}</target><!-- 需要生成的目標class文件的編譯版本 --><encode>${project.build.sourceEncoding}</encode></configuration></plugin></plugins></build>然后更新maven項目,發現版本變成了1.8
配置springboot依賴程序
<dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-web</artifactId></dependency>以上pom文件的配置就完成了,完整的pom文件如下
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"><modelVersion>4.0.0</modelVersion><parent><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-parent</artifactId><version>1.5.4.RELEASE</version></parent><groupId>com.mldn</groupId><artifactId>bootfirst</artifactId><version>0.0.1-SNAPSHOT</version><packaging>jar</packaging><name>bootfirst</name><url>http://maven.apache.org</url><properties><jdk.version>1.8</jdk.version><project.build.sourceEncoding>UTF-8</project.build.sourceEncoding></properties><dependencies><dependency><groupId>junit</groupId><artifactId>junit</artifactId><scope>test</scope></dependency><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-web</artifactId></dependency> </dependencies><build><finalName>bootfirst</finalName><plugins><plugin><groupId>org.apache.maven.plugins</groupId><artifactId>maven-compiler-plugin</artifactId><configuration><source>${jdk.version}</source><!-- 源代碼使用的開發版本 --><target>${jdk.version}</target><!-- 需要生成的目標class文件的編譯版本 --><encode>${project.build.sourceEncoding}</encode></configuration></plugin></plugins></build> </project>3.編寫一個具體的程序
?
package com.mldn.bootfirst;import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.EnableAutoConfiguration; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.ResponseBody;@Controller @EnableAutoConfiguration public class SampleController {@RequestMapping("/")@ResponseBodypublic String home() {return "Hello World!";}public static void main(String[] args) throws Exception {SpringApplication.run(SampleController.class, args);} }然后可以直接通過java去運行該springboot程序。
在SampleController.java文件中,右鍵 Run as --java application
訪問測試?http://localhost:8080/
如果現在是一個maven的普通項目,最簡單的方法是在maven運行的時候輸入:"spring-boot:run"?
在項目上點擊右鍵,run as -- maven build 選擇第四個
開始下載插件,等插件下載完成之后,就可以執行了,就和編譯打包是一樣的
springboot的天生缺陷:是對開發者的要求比較高,必須會maven,ssm整合開發。
?
轉載于:https://my.oschina.net/u/3023191/blog/3032694
總結
以上是生活随笔為你收集整理的第一章:SpringBoot入门的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: LDAPit's usage
- 下一篇: 模块与包