Spring Boot入门

一、Spring Boot背景

       Spring难免需要配置大量的xml配置文件,Spring Boot的出现就是为了解决这个问题。开发只需要简单的Spring配置,甚至是零xml配置,就可以达到快速的开发部署出web服务,让所有依赖spring的程序可以做到“just run”。

二、Spring Boot特点:

    1:创建独立的spring应用。

    2:嵌入Tomcat, Jetty Undertow 而且不需要部署他们。

    3:提供的“starters”poms来简化Maven配置

    4:尽可能自动配置spring应用。

    5:提供生产指标,健壮检查和外部化配置

    6:绝对没有代码生成和XML配置要求

三、工程入门

    1、 新建Maven工程,pom文件添加以下配置:

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

  2、JDK必须1.7以上,Maven必须3.2版本以上

  3、第一个例子Hello World

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 FirstController
{
 @RequestMapping("/hello")
 String home()
 {
  return "Hello World!!!";
 }
 
 public static void main(String[] args)
 {
  SpringApplication.run(FirstController.class, args);
 }
}

4、Run->Java Application运行即可

5、访问

     请求:http://localhost:8080/hello,响应:Hello World!!!

 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值