一 创建Maven项目
二 编辑.m2/settings.xml,修改Maven镜像配置为阿里云
<mirror>
<id>nexus-aliyun</id>
<mirrorOf>*</mirrorOf>
<name> nexus aliyun </name>
<url> http://maven.aliyun.com/nexus/content/groups/public</url>;
</mirror>
三 编辑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.0http://maven.apache.org/xsd/maven-4.0.0.xsd";>
<modelVersion>4.0.0</modelVersion>
<groupId>com.imooc</groupId>
<artifactId>girl</artifactId>
<version>0.0.1-SNAPSHOT</version>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.4.1.RELEASE</version>
</parent>
<properties>
<java.version>1.8</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
</dependencies>
</project>
四 创建启动程序
package com.imooc;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
public class GirlApplication {
public static void main(String[] args){
SpringApplication.run(GirlApplication.class, args);
}
}
五 创建Controller
package com.imooc;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
@RestController
public class HelloController {
@RequestMapping(value="/hello",method=RequestMethod.GET)
public String say()
{
return "Hello Spring Boot!";
}
}
六 启动项目的三种方式
1 在IDE中启动
2 进入项目目录,通过下面方式启动
mvn spring-boot:run
3 编译程序生成jar包,然后通过java命令启动jar包
mvn install
java –jar program.jar
七 测试结果