依赖:
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