美文网首页
2、spring boot 入门

2、spring boot 入门

作者: 内酷啦啦 | 来源:发表于2017-07-14 10:08 被阅读0次

    参考网站:spring boot 官网

    下图为spring boot 官网提供的boot包信息,如图稳定版本为1.5.4,Reference为官方文档


    Spring Boot具有如下特性:

    • 为基于Spring的开发提供更快的入门体验
    • 开箱即用,没有代码生成,也无需XML配置。同时也可以修改默认值来满足特定的需求。
    • 提供了一些大型项目中常见的非功能性特性,如嵌入式服务器、安全、指标,健康检测、外部配置等。
    • Spring Boot并不是不对Spring功能上的增强,而是提供了一种快速使用Spring的方式。

    项目目录结构参考-之后所有的工程创建都将基于这个项目目录结构

    • 在flybiner-boot-all的pom中增加<parent>

    增加父pom比较简单,而且spring-boot-starter-parent包含了大量配置好的依赖管理,在自己项目添加这些依赖的时候不需要写<version>版本号。

        <!-- spring-boot -->
        <parent>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-parent</artifactId>
            <version>1.5.4.RELEASE</version>
        </parent>
    
    • 在flybiner-boot-web的pom中增加web功能和spring-boot-maven-plugin插件
        <!-- Spring通过添加spring-boot-starter-*这样的依赖就能支持具体的某个功能。
        我们这个示例最终是要实现web功能,所以添加的是这个依赖。 -->
        <dependency>
               <groupId>org.springframework.boot</groupId>
               <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
    
      <build>
            <plugins>
                <plugin>
                    <groupId>org.springframework.boot</groupId>
                    <artifactId>spring-boot-maven-plugin</artifactId>
                    <dependencies>
                        <!-- 支持热部署 -->
                        <dependency>
                            <groupId>org.springframework</groupId>
                            <artifactId>springloaded</artifactId>
                            <version>1.2.7.RELEASE</version>
                        </dependency>
                    </dependencies>
                </plugin>
            </plugins>
        </build>
    
    • 创建测试TestController类
        /**
         * 测试1
         * @return
         */
        @RequestMapping(value = "/testHello",method = RequestMethod.GET)
        public String testHello(){
            return "你好啊!帅哥!";
        }
    
    • 创建启动ApplicationBoot类
    @SpringBootApplication
    @EnableAutoConfiguration
    public class ApplicationBoot {
        public static void main(String[] args) throws Exception {
            SpringApplication app = new SpringApplication(ApplicationBoot.class);
            app.run(args);
        }
        
    }
    
    • 目录结构
    • 执行ApplicationBoot种main方法运行项目,运行结果见图

    相关文章

      网友评论

          本文标题:2、spring boot 入门

          本文链接:https://www.haomeiwen.com/subject/pbhnhxtx.html