建立 spring-boot 應用通用方法是配置 pom.xml,定義 爲 spring-boot-start-parent。以下:html
<parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>1.4.0.RELEASE</version> </parent> <dependencies> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency> </dependencies>
可是在真正的項目開發中,每每模塊須要定義本身的 而 maven 的 pom 只容許一個 存在,這種狀況下,能夠採用下面的定義來避免使用 spring-boot-start-parent。安裝以下配置的 pom.xml 能夠經過 maven package 生成能夠運行的 jar 包,經過 java -jar xxxx.jar 啓動運行。java
<dependencies> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> <version>1.4.0.RELEASE</version> </dependency> <!--ImportdependencymanagementfromSpringBoot--> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-dependencies</artifactId> <version>1.4.0.RELEASE</version> <type>pom</type> <scope>import</scope> </dependency> </dependencies> <build> <plugins> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> <version>1.4.0.RELEASE</version> <configuration> <executable>true</executable> </configuration> <executions> <execution> <goals> <goal>repackage</goal> </goals> </execution> </executions> </plugin> </plugins> </build>
需求描述:SpringBoot快速入門, 這篇博客記錄如何使用SpringBoot快速建立一個HelloWorld程序。其中,在pom文件中,使用的SpringBoot提供的父依賴項目。在真實的企業級項目,咱們可能會有本身的父項目,不想依賴Spring提供的父項目。那麼如何解決呢?git
<dependencyManagement> <dependencies> <dependency> <!-- Import dependency management from Spring Boot --> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-dependencies</artifactId> <version>1.4.3.RELEASE</version> <type>pom</type> <scope>import</scope> </dependency> </dependencies> </dependencyManagement>
其他配置和SpringBoot快速入門程序同樣,啓動類和測試步驟均同樣。github
源代碼連接:https://github.com/myNameIssls/springboot-studyspring