1.下载maven并解压
http://maven.apache.org/
2.配置eclipse中要使用maven,将maven解压好的路径配置进来
Window->Preferences->Maven->Installations->add
3.配置要使用的maven的setting配置文件(在maven的conf目录下),local Repository本地仓库没有的话就默认就行
如果需要指定jdk版本需要在setting中添加
<profiles>
<profile>
<id>jdk-1.8</id>
<activation>
<activeByDefault>true</activeByDefault>
<jdk>1.8</jdk>
</activation>
<properties>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
<maven.compiler.compilerVersion>1.8</maven.compiler.compilerVersion>
</properties>
</profile>
</profiles>
4.在eclipse中新建maven工程
(1).new maven Project
(2).选择默认
(3).选择quickstart
(4)设置工程名
(5)工程创建成功
如果程序中不出现src/main/java,src/test/java等,需要为工程设置正确的jre(建议是选装好的jdk路径,因为spring boot打包成jar包需要jdk)
即右键工程->properties->java Build Path
5.在pom.xml中添加Spring boot依赖,更多spring boot使用手册可参考它的用户手册
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.0.3.RELEASE</version>
<relativePath />
</parent>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
</dependencies>
6.创建hello world测试
(1)创建两文件,HelloSpringboot.java和MainApplication.java(主函数)
HelloSpringboot.java
package com.haha.SpringbootTest.controller;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
@Controller
public class HelloSpringboot {
@RequestMapping("/hello")
@ResponseBody
public String hello()
{
return "hellow world";
}
}
MainApplication.java
package com.haha.SpringbootTest;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
public class MainApplication {
public static void main(String[] args) {
SpringApplication.run(MainApplication.class, args);
}
}
2.在MainApplication.java中运行工程,然后在浏览器输入http://localhost:8080/hello