1.访问SpringBoot官网
可以看到SpringBoot官网已经给出了引用方法,我们只需要按照它的方法在项目中引用就可以了
2.新建项目及配置
新建一个hello文件,然后hello文件内新建SampleController类
然后按照官网教程输入
package hello;
import org.springframework.boot.*;
import org.springframework.boot.autoconfigure.*;
import org.springframework.stereotype.*;
import org.springframework.web.bind.annotation.*;
@Controller
@EnableAutoConfiguration
public class SampleController {
@RequestMapping("/")
@ResponseBody
String home() {
return "Hello World!";
}
public static void main(String[] args) throws Exception {
SpringApplication.run(SampleController.class, args);
}
}
pom文件内配置
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.0.2.RELEASE</version>
</parent>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
</dependencies>
3.配置完成后直接运行
4.浏览器查看
浏览器访问 http://localhost:8080/,能打印出hello word! 则表示配置成功!