Spring Boot 整合 Maven
今天尝试使用Spring Boot 整合 Maven
下面我们就以创建一个Hello World程序为例吧
1,创建一个普通的maven项目
2,添加spring boot依赖,pom.xml内容如下
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> <modelVersion>4.0.0</modelVersion> <groupId>net.myspringBoot</groupId> <artifactId>myBootDemo</artifactId> <packaging>war</packaging> <version>0.0.1-SNAPSHOT</version> <name>myBootDemo Maven Webapp</name> <url>http://maven.apache.org</url> <parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>1.5.9.RELEASE</version> </parent> <dependencies> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency> <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <version>3.8.1</version> <scope>test</scope> </dependency> </dependencies> <build> <finalName>myBootDemo</finalName> </build> </project>
3,编写测试类SampleController,代码如下
import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.EnableAutoConfiguration; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.ResponseBody; @Controller @EnableAutoConfiguration @RequestMapping("/page") public class SampleController { @RequestMapping("/{sss}") @ResponseBody String home(@PathVariable String sss) { return "Hello World!"+sss; } public static void main(String[] args) throws Exception { SpringApplication.run(SampleController.class, args); } }
最后运行这个类,在浏览器就可以查看到结果了
自此,一个简单的spring boot 整合maven的demo就成功了
爆款云服务器s6 2核4G 低至0.46/天,具体规则查看活动详情