intellij+springboot+springloaded 實現熱部署
阿新 • • 發佈:2019-01-13
依賴:
dependencys目錄下增加:
<dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency>
project 節點下新增:
<build> <plugins> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> <dependencies> <!-- spring熱部署--> <dependency> <groupId>org.springframework</groupId> <artifactId>springloaded</artifactId> <version>1.2.1.RELEASE</version> </dependency> </dependencies> </plugin> </plugins> </build>
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 {<span style="color:#bbb529;">@RequestMapping</span>(<span style="color:#6a8759;">"/thing"</span>) <span style="color:#cc7832;">public </span>MyThing <span style="color:#ffc66d;">thing</span>() { MyThing m = <span style="color:#cc7832;">new </span>MyThing() <span style="color:#cc7832;">;
m.setId(“5”);
m.setName(“姓名”);
return m ;
}
<span style="color:#bbb529;">@RequestMapping</span>(<span style="color:#6a8759;">"/thing2"</span>)
<span style="color:#cc7832;">public </span>MyThing <span style="color:#ffc66d;">thing2</span>() {
MyThing m = <span style="color:#cc7832;">new </span>MyThing() <span style="color:#cc7832;">;
m.setId(“5”);
m.setName(“姓名”);
return m ;
}
package hello; /** * Created by hongpf on 2015/2/15. */ public class MyThing { public String getId() { return id; }<span style="color:#cc7832;">public void </span><span style="color:#ffc66d;">setId</span>(String id) { <span style="color:#cc7832;">this</span>.<span style="color:#9876aa;">id </span>= id<span style="color:#cc7832;">;
}
<span style="color:#629755;">/**
*
*/
String id ;
public String getName() {
return name;
}
<span style="color:#cc7832;">public void </span><span style="color:#ffc66d;">setName</span>(String name) {
<span style="color:#cc7832;">this</span>.<span style="color:#9876aa;">name </span>= name<span style="color:#cc7832;">;
}
String <span style="color:#9876aa;">name </span><span style="color:#cc7832;">;
}
當系統通過 mvn spring-boot:run啟動或者 右鍵application debug 啟動java檔案時,系統會監視classes檔案,當有classes檔案被改動時,系統會重新載入類檔案,不用重啟啟動服務
ps:需要重新編譯檔案 ctl+shift+f9