创建一个maven工程,添加SpringBoot起步依赖。
new --> Module --> Maven --> Next
1.pom.xml
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.0.1.RELEASE</version>
</parent>
<groupId>com.wyy</groupId>
<artifactId>springboot_quick</artifactId>
<version>1.0-SNAPSHOT</version>
<dependencies>
<!--web功能的起步依赖-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<!--热部署配置 -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
</dependency>
<!--@ConfigurationProperties的执行器的配置 -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-configuration-processor</artifactId>
<optional>true</optional>
</dependency>
</dependencies>
2.配置启动项
在包下创建 MySpringBootApplication.java
package com.wyy;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
public class MySpringBootApplication {
public static void main(String[] args){
SpringApplication.run(MySpringBootApplication.class);
}
}
3. 创建Controller测试是否成功
package com.wyy.controller;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
@Controller
public class QuickController {
@RequestMapping("/quick")
@ResponseBody
public String quick(){
return "Hello asa";
}
}
在页面访问 http://localhost:8081/quick 成功SpringBoot环境就搭好了