SpringBoot入门

来源:互联网 发布:智能建筑系统集成软件 编辑:程序博客网 时间:2024/04/29 08:40

前言:SSH等开源框架在现今开发web项目中成了主流,但搭建一个这样的框架,需要开发人员对各种技术有一个深入的了解,以及框架之间整合的时候也带来很大麻烦。假如,现在需要开发一个小型的web项目,对于一个初级程序员来说,选用SpringBoot最好不过了

特点:

    1,一个独立的jar程序,可以直接运行

·   2,继承tomcat,jetty等服务器,不需要打包成war项目

    3,提供'starter' POMs 简化你的maven配置

    4,自动配置spring容器

    5,提供可扩展的配置

    6,不需要代码集 成不需要xml配置

两分钟搭建springBoot

1,创建maven项目



2,添加maven依赖 

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

3,简单的hello world

package hello;


import org.springframework.boot.*;

import org.springframework.boot.autoconfigure.*;

import org.springframework.stereotype.*;

import org.springframework.web.bind.annotation.*;


@Controller

@EnableAutoConfiguration

public class SampleController {


    @RequestMapping("/")

    @ResponseBody

    String home() {

        return "Hello World!";

    }


    public static void main(String[] args) throws Exception {

        SpringApplication.run(SampleController.class, args);

    }

}

4,运行SampleController


0 0
原创粉丝点击