第一个springboot项目之hello-world

第一步,创建maven工程,请参照上一篇博客,

他的父级pom.xml

<?xml version="1.0" encoding="UTF-8"?>
<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.6.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>


<groupId>cn.ffcs.tsp</groupId>
<artifactId>springboot</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>pom</packaging>

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

<!-- 私服地址 -->
<distributionManagement>
<repository>
<id>releases</id>
<name>Internal Releases</name>
<url>http://127.0.0.1:8081/nexus/content/repositories/releases</url>
</repository>
<snapshotRepository>
<id>snapshots</id>
<name>Internal Snapshots</name>
<url>http://127.0.0.1:8081/nexus/content/repositories/snapshots</url>
</snapshotRepository>
</distributionManagement>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<spring.version>4.3.16.RELEASE</spring.version>
<!-- 默认是1.6,需要手动配置 -->
<jdk.version>1.8</jdk.version>
<mybatis.version>5.2.0</mybatis.version>
<mybatis-spring.version>2.1.0</mybatis-spring.version>
</properties>

<dependencies>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<scope>test</scope>
</dependency>
</dependencies>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-dependencies</artifactId>
<version>Dalston.SR2</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>

<modules>
<module>springbootDemo</module>
<module>springbootMybatis</module>
</modules>
</project>

spring-boot-starter-parent---->包中定义了resource底下的文件类型,然后有引入spring-boot-dependencies,这个引入了许多jar包,spring-boot-starter-web这个是一些注解在这个包中RestController,requestMapping等等

spring-cloud-dependencies主要是spring-cloud的jar包,用dependencyManagement管理,可以避免jar包版本不统一问题,这里可以删除。

我们创建的springbootDemo项目的pom.xml如下:  

<?xml version="1.0"?>
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>cn.ffcs.tsp</groupId>
<artifactId>springboot</artifactId>
<version>1.0-SNAPSHOT</version>
</parent>
<groupId>cn.ffcs.tsp.msa</groupId>
<artifactId>springbootDemo</artifactId>
<version>1.0.0-SNAPSHOT</version>
<name>springbootDemo</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>

控制类如下

运行项目之后,访问http://localhost:8080/firstSpringboot/home

原文地址:https://www.cnblogs.com/hejj-bk/p/springboot.html