SpringBoot(一) 入门,快速开始


Spring4.0出来后, 推出的,

     优点, 快速创建独立运行的Spring项目以及主流框架继承

-- 使用嵌入式的Servlet容器, 应用无需打包成WAR包

-- Starters自动依赖与 版本控制

 -- 大量的自动配置,简化开发, 也可以修改默认值

 -- 无需配置XML,无代码生成,开箱即用

 -- 准生产环境的运行时应用监控

 -- 与云计算天然集成

1.      SpringBoot简介

扫描二维码关注公众号,回复: 1169760 查看本文章

a)        简化Spring应用开发的一个框架

b)        整个Spring技术栈的一个大整合

c)        J2EE 开发的一站式解决方案

2.      微服务

a)        架构风格

b)        一个应用,应该是一组小型服务,通过http的方式进行互通(单体应用,都是全部写在一个里面)

c)        每个功能元素最终都是一个可独立替换和独立升级的软件单元

d)        环境约束

                        i.             Jdk1.8

                      ii.             IDEA

                     iii.             Maven 3以上

                     iv.             SpringBoot版本1.5.9

3.      SpringBoot的HelloWorld

a)        创建maven项目

b)        导入springBoot相关依赖到pom文件(访问springBoot官方网站)

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


c)        写个springBoot主方法类上标注@SpringBootApplication

d)        写个controller层

 
 
packagehello;
 
importorg.springframework.boot.*;
importorg.springframework.boot.autoconfigure.*;
importorg.springframework.stereotype.*;
importorg.springframework.web.bind.annotation.*;
 
@Controller
@EnableAutoConfiguration
publicclassSampleController{
 
    
@RequestMapping("/")
    
@ResponseBody
    
Stringhome(){
        
return"Hello World!";
    
}
 
    
publicstaticvoidmain(String[]args)throwsException{
        
SpringApplication.run(SampleController.class,args);
    
}
}

e)        执行main方法

4.      简化部署

a)        导入插件

<build>
  <plugins>
          <plugin>
                  <groupId>org.springframework.boot</groupId>
                  <artifactId>spring-boot-maven-plugin</artifactId>
          </plugin>
  </plugins>
</build>

5.      Pom文件解析

a)   spring-boot-starter-parent父依赖

b)   spring-boot-starter-web  场景启动器(在官网通过starts关键字搜)

c)        主程序类,@SpringBootApplication 用于程序的启动

                        i.             这个注解属于组合注解,

                      ii.             @SpringBootConfiguration 配置类上标注这个注解--- 配置文件,底层是@Configuration,他的底层也是个@component

                     iii.             @EnableAutoConfiguration 自动配置功能,

6.      使用SpringInitializer创建SpringBoot.(IDEA创建),

a)        选择自己要的模块

b)        没用的删掉


c)        Pom文件自动就会导入了jar文件

d)        主程序生成好了, 只需要编写自己的逻辑

e)        配置文件夹中, resources文件夹中, 目录结构

       

g)        其中static:js,css,images都放在这

h)        Templates:保存所有模板页面(SpringBoot,使用嵌入tomcat,不支持jsp页面),可以使用模板引擎,thymeleaf

i)          Application.propertiesSpringBoot,默认配置文件;例如server.port=8081 端口号改变



猜你喜欢

转载自blog.csdn.net/weixin_38399962/article/details/80433993