1.创建好的maven项目,在pom.xml中引入以下配置为配置springboot启动
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<version>1.5.4.RELEASE</version>
</dependency>
2.新建的启动类StartApplication.java(@SpringBootApplication标识这是一个springboot启动入口):
package com.stock;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
/**
* @Description 程序启动类
* @Date 2019年1月20日 下午4:39:59
*/
@SpringBootApplication
public class StartApplication {
public static void main( String[] args )
{
SpringApplication.run(StartApplication.class, args);
}
}
3.配置项目为热部署(修改Java文件保存后自动编译),修改pom.xml配置(父启动类中添加了版本后,子启动类不用添加版本号):
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.5.4.RELEASE</version>
</parent>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
<!-- 热部署方法spring boot devtools 依赖包. -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<optional>true</optional>
<scope>true</scope>
</dependency>
</dependencies>
4.测试类TestController.java中使用:
package com.stock.index.controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.ModelAndView;
/**
* @Description index的控制类
* @Date 2019年1月20日 下午5:04:27
*/
@RestController
public class IndexController {
@RequestMapping("/index")
public String index() {
return "hello world!";
}
}
6.浏览器中输入:http://localhost:8080/index访问系统
7.修改IndexController.java类保存,项目自动编译重启