第二章:SpringBoot基礎知識-springboot基本概念--創建統一父pom

源碼下載:https://u11556602.ctfile.com/fs/11556602-361219278java

                https://download.csdn.net/download/qq_36267875/11089023web

在以前所創建的springboot項目只是根據官方文檔實現的一個基礎程序模型,可是這樣的代碼確定不適合於實際的項目開發,由於從實際的maven項目來說,應該要有統一的父pom.xml文件。spring

統一父pom管理apache

1.首先創建一個microboot的maven項目;springboot

將<packaging>jar</packaging>改爲 <packaging>pom</packaging>app

用<dependencyManagement>將<dependencies>中的內容包裹起來maven

<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>

  <groupId>cn.mldn</groupId>
  <artifactId>microboot</artifactId>
  <version>0.0.1-SNAPSHOT</version>
  <packaging>jar</packaging>

  <name>microboot</name>
  <url>http://maven.apache.org</url>

  <properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
  </properties>

	<dependencyManagement>
	  <dependencies>
	    <dependency>
	      <groupId>junit</groupId>
	      <artifactId>junit</artifactId>
	      <version>3.8.1</version>
	      <scope>test</scope>
	    </dependency>
	  </dependencies>
	</dependencyManagement>  
</project>

將項目中無用的源文件都刪除乾淨spring-boot

將項目中不須要的文件也刪除掉ui

再刪除一次url

將下面的配置拷貝過來

<properties>
		<jdk.version>1.8</jdk.version>
		<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
	</properties>
<build>
		<finalName>microboot</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>
<dependency>
				<groupId>org.springframework.boot</groupId>
				<artifactId>spring-boot-dependencies</artifactId>
				<version>1.5.4.RELEASE</version>
				<type>pom</type>
				<scope>import</scope>
			</dependency>

2.創建microboot-base的子模塊,實現以前一樣的功能,修改pom.xml文件,追加springboot的web啓動包

在項目上右鍵,新建 maven module 

而後打開pom文件,將黃色感嘆號提示的代碼刪除掉

3.創建與以前一樣的程序類

package cn.mldn.microboot;

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("/")
    @ResponseBody
    String home() {
        return "www.mldn.cn";
    }

    public static void main(String[] args) throws Exception {
        SpringApplication.run(SampleController.class, args);
    }
}

在這樣的狀態下,才能夠進行咱們後續的代碼編寫。

相關文章
相關標籤/搜索