本人的环境jdk1.7 myeclipse10 ,maven 3.5
首先配置maven(前提是maven已经配置好)
新建一个maven 项目。
注意上面的第三步骤,不知为什么我都安装了jdk1.7,那个还是1.6,后面会进行修改。
完成之后得到的结果为
在pom.xml中加入
<!-- Inherit defaults from Spring Boot -->
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.5.9.RELEASE</version>//这里写RELEASE,写别的例如BUILD-SNAPSHOT可能会出错
</parent>
<!-- Add typical dependencies for a web application -->
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
</dependencies>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>//这个需要在<plugins></plugins>插件中
在java文件夹中新建HelloWorld文件
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
@SpringBootApplication // Spring Boot项目的核心注解,主要目的是开启自动配置
@Controller // 标明这是一个SpringMVC的Controller控制器
public class HelloApplication {
@RequestMapping("/hello")
@ResponseBody
public String hello() {
return "hello world";
}
// 在main方法中启动一个应用,即:这个应用的入口
public static void main(String[] args) {
SpringApplication.run(HelloApplication.class, args);
}
}
运行启动或许会出错,这里需要改如下位置
右键点击HelloWorld项目进入properties
这样就好了,输入http://localhost:8080/hello