创建maven项目,springboot启动,热部署配置(保存java项目即重新编译重启)

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类保存,项目自动编译重启

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值