Spring Boot初探

来源:互联网 发布:淘宝店铺怎么下架商品 编辑:程序博客网 时间:2024/05/12 05:35

Spring Boot 简介

本词条缺少名片图,补充相关内容使词条更完整,还能快速升级,赶紧来编辑吧!

Spring Boot是由Pivotal团队提供的全新框架,其设计目的是用来简化新Spring应用

的初始搭建以及开发过程。该框架使用了特定的方式来进行配置,从而使开发人员不

再需要定义样板化的配置。通过这种方式,Spring Boot致力于在蓬勃发展的快速应用

开发领域(rapid application development)成为领导者。


Spring Boot 特点

1. 创建独立的Spring应用程序

2. 嵌入的Tomcat,无需部署WAR文件

3. 简化Maven配置

4. 自动配置Spring

5. 提供生产就绪型功能,如指标,健康检查和外部配置

6. 绝对没有代码生成和对XML没有要求配置[1] 


Spring Boot 的hello world运行流程

创建一个简单的maven项目,修改JDK的支持,

创建类,运行main方法,在浏览器直接访问即可


Spring Boot 必需要有安装JDK1.7以上的支持

以下都要改到JDK1.6以上


以下都要改到JDK1.7以上








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>cn.et</groupId>  <artifactId>SpringBoot</artifactId>  <version>0.0.1-SNAPSHOT</version>    <parent>        <groupId>org.springframework.boot</groupId>        <artifactId>spring-boot-starter-parent</artifactId>        <version>1.5.4.RELEASE</version>  </parent>    <dependencies>    <dependency>        <groupId>org.springframework.boot</groupId>        <artifactId>spring-boot-starter-web</artifactId>    </dependency></dependencies>  </project>


application.properties

#修改端口号server.port=80


HelloController

package cn.et.boot.lesson01.hello;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/** * 自动增加spring.xml文件,并且配置自动扫描 * 自动增加web.xml 同时在web.xml过滤器、拦截器... */@EnableAutoConfigurationpublic class HelloController {@RequestMapping("/hello")public String hello(){return "hello world!";}public static void main(String[] args) {//发布程序的方法入口SpringApplication.run(HelloController.class, args);}}

浏览器访问Action

浏览器访问路径:http://localhost/hello


原创粉丝点击