spring boot可以快速創建基於spring mvc的web應該用,幾乎不需要任何的配置即可構建成功,下面直接看步驟
1:創建一個MAVEN工程,如果不會創建,可以看我博客前面有一篇有講
2:在pom文件中加入以下配置
<parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>1.3.6.RELEASE</version> </parent> <dependencies> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency> </dependencies> <build> <plugins> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin </artifactId> </plugin> </plugins> </build>3:創建一個類
import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.EnableAutoConfiguration; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; @RestController @EnableAutoConfiguration public class TestClass { @RequestMapping("/") String home() { return "hi..."; } public static void main(String[] args) { SpringApplication.run(TestClass.class, args); } }4:編譯工程,啓動main方法,然後訪問:http://localhost:8080
5:部署的話,可將應用打成JAR包,然後啓動