项目是用Maven创建的
Pom.xml文件
-
<?xml version="1.0" encoding="UTF-8"?> <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/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <groupId>com.ycb.spring_boot_demo01</groupId> <artifactId>spring_boot_demo01</artifactId> <version>0.0.1-SNAPSHOT</version> <properties> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> </properties> <!-- spring boot 基本环境 --> <parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>1.3.1.RELEASE</version> </parent> <!--web应用基本环境配置 --> <dependencies> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency> </dependencies> <!-- 打包spring boot应用 --> <build> <plugins> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> </plugin> </plugins> </build> </project>
-
创建一个Application启动类
-
package com.springboot; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; /** * springboot 已经启动内嵌的是tomcat 默认的端口是8080 * * * @author summer * */ //@SpringBootApplication相当于@Configuration、@EnableAutoConfiguration和 @ComponentScan @SpringBootApplication public class Application { public static void main( String[] args ) { SpringApplication.run(Application.class, args); } }
-
运行 此类main方法
spring boot 就启动了 ,spring boot 内嵌了tomcat 默认是8080 端口
访问路径是根路径信息
创建一个简单的controller
-
@RestController public class HelloWorldController { @RequestMapping("/index/{name}") @ResponseBody public String index(@PathVariable String name){ if(null==name){ name="boy"; } return "hello world" +name; } }
-
重新运行Application的main方法 在浏览器访问 http://localhost/index/张三