以下:java
<parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>1.4.0.RELEASE</version> </parent> <modelVersion>4.0.0</modelVersion> <artifactId>Springboot</artifactId> <packaging>war</packaging> <name>Springboot Maven Webapp</name> <url>http://maven.apache.org</url> <properties> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding> <java.version>1.8</java.version> </properties> <dependencies> <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <version>3.8.1</version> <scope>test</scope> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-test</artifactId> <scope>test</scope> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-thymeleaf</artifactId> </dependency> </dependencies> <build> <plugins> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> </plugin> </plugins> </build>
一、首先建立一個Application類,裏面添加一個main()方法,web
@SpringBootApplication public class Application { public static void main(String[] args) { SpringApplication.run(Application.class, args); } }
須要注意的是:這個類的上面須要添加SpringBoot的註解@SpringBootApplication,而後在主函數中開始啓動。spring
二、而後建立一個HelloWord類,用來測試SpringBootapache
以下:瀏覽器
@RestController @EnableAutoConfiguration public class HelloWord { @RequestMapping("/hello") public String hello() { return "hello,Spring boot!"; } //帶參數 @RequestMapping("/word/{name}") public String word(@PathVariable String name) { return "word--spring boot:" + name; } }
須要注意的是這上面的幾個註解:springboot
Ok,就這樣,一個簡單的SpringBoot小demo就寫出來了,咱們直接就能夠運行了,而後輸入:http://localhost:8080/hello 和 http://localhost:8080/word/canshu 瀏覽器上便可獲得輸出結果服務器