Spring Boot 之Hello Word

Spring Boot官网:http://projects.spring.io/spring-boot/

环境准备:maven 3.3.5、jdk8、Idea

1.创建maven项目工程

2.引入starters

 <parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.5.11.RELEASE</version>
</parent>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
</dependencies>

3.创建主程序

 @SpringBootApplication
public class HelloWorldMainApplication { public static void main(String[] args){
//Spring 应用启动起来
SpringApplication.run(HelloWorldMainApplication.class, args);
}
}

4.创建一个Controller

 @Controller
public class HelloController { @RequestMapping("/hello")
@ResponseBody
public String hello(){
return "Hello Word!";
}
}

5.运行主方法,并在浏览器输入:localhost:8080/hello ,就会出现Hello Word!

6.也可以打包成jar包 进行部署

url:https://docs.spring.io/spring-boot/docs/1.5.11.RELEASE/reference/htmlsingle/#getting-started-first-application-executable-jar

Spring Boot 之Hello Word

这个插件,可以将应用打包成一个jar包 
 <build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
上一篇:response.addCookie(cookie)添加cookie失败.


下一篇:bash操作小结