1.创建maven jar项目 在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.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.bjsxt</groupId>
<artifactId>01-spring-boot-hello</artifactId>
<version>0.0.1-SNAPSHOT</version>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.5.10.RELEASE</version>
</parent>
<!-- 修改jdk版本 -->
<properties>
<java.version>1.7</java.version>
</properties>
<dependencies>
<!-- springBoot的启动器 -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
</dependencies>
</project>
2.创建启动类
@SpringBootApplication
public class App {
public static void main(String[] args) {
SpringApplication.run(App.class, args);
}
}
注意:启动类要放在@controller类的同包或者上层包中
3.创建controller类
package com.jiayun.spring.study;
import java.util.HashMap;
import java.util.Map;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
@Controller
public class HelloWorld {
@RequestMapping("/hello")
@ResponseBody
private Map<String, String> hello() {
Map<String, String> map = new HashMap<String, String>();
map.put("hello", "SpringBoot");
return map;
}
}
4.运行启动类的main方法
项目名上右键 maven UpdateProject
项目名上右键 ---> run as ---> MavenBuild... 在弹框的Globles 中输入:dependency:purge-local-repository(清理本地仓库)
等待的爽歪歪!