SpringBoot入门与建立统一的父pom.xml文件

SpringBoot入门与建立统一的父pom.xml文件

SpringBoot建立统一的父pom.xml文件

在之前所建立的SpringBoot项目只是根据官方文档实现的一个基础程序模型,但是这样的代码肯定不合适于实际的项目开发,因为从实际的Maven项目来讲,应该要有统一的父pom.xml文件。

统一的父pom管理

首先建立一个microboot的maven项目:修改pom.xml文件。

xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">

4.0.0

com.gwolf

SpringBoot

1.0-SNAPSHOT

pom

SpringBoot

http://maven.apache.org

UTF-8

删除父项目中所有的源代码目录:只留下父pom.xml文件。

在父pom文件中配置插件,不然项目编译会出错:

xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">

4.0.0

UTF-8

1.8

com.gwolf

SpringBoot

1.0-SNAPSHOT

pom

SpringBoot

http://maven.apache.org

SpringBoot

org.apache.maven.plugins

maven-compiler-plugin

${jdk.version}

${jdk.version}

${project.build.sourceEncoding}

在maven配置文件中加入SpringBoot依赖包:

org.springframework.boot

spring-boot-dependencies

1.5.4.RELEASE

pom

import

建立一个springboot-base的子模块,实现springboot的基础操作。

在springboot-base子模块中加入SpringBoot web的依赖包:

org.springframework.boot

spring-boot-starter-web

建立一个SpringBoot测试类:

package com.gwolf;

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

public String index() {

return "Greetings from Spring Boot!";

}

public static void main(String[] args) {

SpringApplication.run(SampleController.class, args);

}

}

运行上述程序,程序运行成功。