一、准备工作
1.下载安装eclipse
2.下载tomcat,配置到eclipse
3.下载maven, 配置到eclipse
二、创建maven项目
1.打开Eclipse,点击File->New->Other,在弹出对话框中,选中Maven Project。(如下图)
2.编写pom.xml,添加springboot依赖(见下方代码,添加后保存)
更新项目依赖:右键项目选择Maven->Update Project(如项目无报错,则不需要)
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
</dependencies>
<!-- 继承父包 -->
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.0.0.RELEASE</version>
</parent>
3.调整编译环境,在项目上右键选择properties,然后点击java build path,在Librarys下,编辑JRE System Library,选择workspace default jre就可以了。(如下图)
4.在src/mian/java下创建class文件,TestApplicariontion.class内容如下:
package com.liu.demo20190304;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
@RestController
@EnableAutoConfiguration
public class TestApplicariontion{
@RequestMapping("/")
String home() {
return "hello word!";
}
public static void main(String[] args) {
SpringApplication.run(TestApplicariontion.class, args);
}
}
5 测试,右键点击TestApplicariontion → run as javaApplication/run on Server,亲测,都可以运行,运行效果如下:
打开:http://localhost:8088/,端口8088是我配置的tomcat端口,
效果:页面中仅显示hello word