intellij+springboot+springloaded 实现热部署

依赖:

dependencys目录下增加:


    org.springframework.boot
    spring-boot-starter-web

project 节点下添加:


    
        
            org.springframework.boot
            spring-boot-maven-plugin
            
                
                
                    org.springframework
                    springloaded
                    1.2.1.RELEASE
                
            
        
    


java图 :

Application.java

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;

import java.util.Arrays;

/**
 * Created by Administrator on 2015/2/10.
 */

@Configuration
@EnableAutoConfiguration
@ComponentScan
public class Application {
    public  static  void  main(String [] m){
        ApplicationContext ctx = SpringApplication.run(Application.class, m);

        System.out.println("Let's inspect the beans provided by Spring Boot:");

        String[] beanNames = ctx.getBeanDefinitionNames();
        Arrays.sort(beanNames);
        for (String beanName : beanNames) {
      //      System.out.println(beanName);
        }
    }
}

controller.java

package hello;

import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * Created by  on 2015/2/15.
 */
@RestController
public class MyController {

    @RequestMapping("/thing")
    public MyThing thing() {
        MyThing m =  new MyThing() ;
        m.setId("5");
        m.setName("姓名");
        return  m ;
    }

    @RequestMapping("/thing2")
    public MyThing thing2() {
        MyThing m =  new MyThing() ;
        m.setId("5");
        m.setName("姓名");
        return  m ;
    }

mything.java

package hello;

/**
 * Created by hongpf on 2015/2/15.
 */
public class MyThing {
    public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id;
    }

    /**
     *
     */
    String id ;

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    String name ;
}

当系统通过 mvn spring-boot:run启动或者 右键application debug 启动java文件时,系统会监视classes文件,当有classes文件被改动时,系统会重新加载类文件,不用重启启动服务

ps:需要重新编译文件 ctl+shift+f9

你可能感兴趣的:(java)