zoukankan      html  css  js  c++  java
  • spring boot简介及第一个hello world

    Spring Boot 简介
    Spring Boot 简化了基于Spring的应用开发,只需要“run”就能创建一个独立的、生产级别的Spring应用。Spring Boot为Spring平台及第三方库提供开箱即用的设置(提供默认设置),这样我们就可以简单的开始。多数Spring Boot应用只需要很少的Spring配置。
    我们可以使用SpringBoot创建java应用,并使用java –jar 启动它,或者采用传统的war部署方式。

    Spring Boot 主要目标是:
    为所有 Spring 的开发提供一个从根本上更快的入门体验
    开箱即用,但通过自己设置参数,即可快速摆脱这种方式。
    提供了一些大型项目中常见的非功能性特性,如内嵌服务器、安全、指标,健康检测、外部化配置等
    绝对没有代码生成,也无需 XML 配置。

    hello world—第一个spring boot项目

    第一步:建立一个spring boot项目

    点击file->new->other->选择建立Maven project->next

      

    选择你的工作路径第二个打勾(创建一个简单的项目可同时选择第一个和第二个)

    填写Group Id ,Artifact Id,Version,Packaging:打包类型,jar/war/rar/ear/pom等,选择jar

    Compiler Level : 选择jdk版本;完成。                                    显示目录结构如下:

    配置pom.xml文件

    1、设置spring boot的parent(继承父包):在pom.xml中引入spring-boot-starter-parent,spring官方的叫stater poms,它可以提供dependency management,也就是依赖管理,引入以后在声明其它dependency的时候就不需要version了。

        <!-- 1、设置Spring boot的parent -->  
        <parent>  
            <groupId>org.springframework.boot</groupId>  
            <artifactId>spring-boot-starter-parent</artifactId>  
            <version>1.5.6.RELEASE</version>  
        </parent>  

    2、导入spring boot的web支持:需要在pom.xml中引入spring-boot-starter-web,spring官方解释spring-boot-starter-web包含了spring webmvc和tomcat等web开发的特性。

        <!-- 2、导入Spring boot的web支持 -->  
        <dependencies>  
            <dependency>  
                <groupId>org.springframework.boot</groupId>  
                <artifactId>spring-boot-starter-web</artifactId>  
            </dependency>  
        </dependencies>  

    3、添加Spring boot的插件:如果我们要直接Main启动spring,那么以下plugin必须要添加,否则是无法启动的。如果使用maven的spring-boot:run的话就不需要此配置。

     

    <!-- 3、添加Spring boot的插件 -->  
    <plugin>  
          <groupId>org.springframework.boot</groupId>  
          <artifactId>spring-boot-maven-plugin</artifactId>  
    </plugin> 

     

    编写启动类:在controller层创建一个包和项目名称

    import org.springframework.boot.SpringApplication;
    import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
    import org.springframework.stereotype.Controller;
    import org.springframework.web.bind.annotation.RequestMapping;
    import org.springframework.web.bind.annotation.ResponseBody;
    
    @Controller
    @EnableAutoConfiguration
    public class Hello {
    
        @RequestMapping("/hello")
        @ResponseBody
        String home() {
            return "Hello ,spring boot!";
          
        }
        
        public static void main(String[] args) throws Exception {
            SpringApplication.run(Hello.class, args);
            //运行之后在浏览器中访问:http://localhost:8080/hello
        }
        
    }

     结果如下:


    原文:https://blog.csdn.net/m0_37106742/article/details/64438892 超级详细!

  • 相关阅读:
    FZU 2150 Fire Game
    POJ 3414 Pots
    POJ 3087 Shuffle'm Up
    POJ 3126 Prime Path
    POJ 1426 Find The Multiple
    POJ 3278 Catch That Cow
    字符数组
    HDU 1238 Substing
    欧几里德和扩展欧几里德详解 以及例题CodeForces 7C
    Codeforces 591B Rebranding
  • 原文地址:https://www.cnblogs.com/lj520fj/p/10956864.html
Copyright © 2011-2022 走看看