1、使用Eclipse 建立Maven项目(webapp OR quickstart)
2、配置Maven,如下:
12 7 8org.springframework.boot 3spring-boot-starter-parent 41.2.5.RELEASE 56 9 12 13UTF-8 101.8 1114 19 2015 18org.springframework.boot 16spring-boot-starter-web 1721 22 2723 26org.springframework.boot 24spring-boot-maven-plugin 25
3、建立启动Application
1 package demo.web.application; 2 import org.springframework.boot.SpringApplication; 3 import org.springframework.boot.autoconfigure.SpringBootApplication; 4 import org.springframework.context.annotation.ComponentScan; 5 6 @SpringBootApplication 7 @ComponentScan(basePackages={"demo.web.*"}) 8 public class Application { 9 public static void main(String[] args) { 10 SpringApplication.run(Application.class, args); 11 } 12 13 }
4、编辑Controller
1 package demo.web.controller; 2 import org.springframework.boot.autoconfigure.EnableAutoConfiguration; 3 import org.springframework.web.bind.annotation.PathVariable; 4 import org.springframework.web.bind.annotation.RequestMapping; 5 import org.springframework.web.bind.annotation.RestController; 6 7 @RestController 8 @EnableAutoConfiguration 9 public class HelloController {10 11 @RequestMapping("/") 12 String home() { 13 System.out.println("ee");14 return "Hello World!"; 15 } 16 17 @RequestMapping("/hello/{myName}") 18 String index(@PathVariable String myName) { 19 return "Hello "+myName+"!!!"; 20 } 21 22 }
5、通过application.properties对项目进行配置
server.port=9000
项目文件布局如下:
启动Application程序,即可访问网站。