Myeclipse创建spring boot项目
- 创建项目
new—project—-maven project—-next
点击next
填写group id artifact id 点击finish - 引用spring boot
项目建好后,检查jdk版本是否匹配
注:如果maven的版本过高而jdk的版本低了,就会报错,可以去maven官网看maven对应的jdk版本
如果pom.xml报错,就右键项目—Maven4Myeclipse—-UpdateProject
pom.xml的基础配置
<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.zzj</groupId>
<artifactId>demo</artifactId>
<version>0.0.1-SNAPSHOT</version>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.5.9.RELEASE</version>
</parent>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
</dependency>
</dependencies>
<build>
<finalName>demo</finalName>
</build>
</project>
- 启动项目
在src/mian/java下建一个包
包里创建启动类
@SpringBootApplication
@RestController
public class bootMain {
@RequestMapping("/hello")
public String hello(){
return "hello springboot";
}
public static void main(String[] args) {
SpringApplication.run(bootMain.class, args);
}
}
右键—-Run as—-java Application
打开浏览器访问http://localhost:8080/hello应该就可以了