spring boot基础

spring boot 的简单搭建

spring boot 的基本用法

spring boot 基本用法
自动配置
技术集成
性能监控
源码解析

工程的构建

创建一个maven项目

    <parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.2.4.RELEASE</version>
</parent> <properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties> <dependencies> <dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
</dependencies> <build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>

将这个代码添加到pom.xml中

创建 Application.Java

package com.lkl.springboot;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication; @SpringBootApplication
public class Application {
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}
}

运行main方法 ,访问你的http://localhost:8080/hello 就可以访问你的Tomcat了。是不是很简单,以前要配置的很多的spring文件,现在不需要了。 就是那么的简洁

**@SpringBootApplication 注解 **

SpringBootApplication注解源码
@Target(ElementType.TYPE)
@Retention(RetentionPolicy.RUNTIME)
@Documented
@Inherited
@Configuration 表示Application作为sprig配置文件存在
@EnableAutoConfiguration启动spring boot内置的自动配置
@ComponentScan扫描bean,路径为Application类所在package以及package下的子路径,这里为 com.lkl.springboot,在spring boot中bean都放置在该路径已经子路径下。
public @interface SpringBootApplication { /**
* Exclude specific auto-configuration classes such that they will never be applied.
* @return the classes to exclude
*/
Class<?>[] exclude() default {}; }

2 spring boot 属性配置和使用

  • Spring Boot 支持多种外部配置方式
  • 命令行参数
  • Java系统属性
  • 操作系统环境变量
  • RandomValuePropertySource
  • 应用配置文件(.properties或.yml)
    • 普通配置文件中可以这样写

      1. name=Isea533
      2. server.port=8080
    • .yml格式的配置文件如
      1. name: Isea533
      2. server:
      3.   port: 8080

注意:使用.yml时,属性名的值和冒号中间必须有空格,如name: Isea533正确,name:Isea533就是错的。

属性配置文件的位置

spring会从classpath下的/config目录或者classpath的根目录查找application.properties或application.yml。

  • @PropertySource

  • SpringApplication.setDefaultProperties

  • 应用(使用)属性

  • @Value(“${xxx}”)

  • @ConfigurationProperties

  • 在@Bean方法上使用@ConfigurationProperties

  • 属性占位符

  • 通过属性占位符还能缩短命令参数

  • 属性名匹配规则

  • 属性验证

Spring Boot 集成MyBatis

下次介绍

spring boot基础 入门的更多相关文章

  1. spring boot入门教程——Spring Boot快速入门指南

    Spring Boot已成为当今最流行的微服务开发框架,本文是如何使用Spring Boot快速开始Web微服务开发的指南,我们将使创建一个可运行的包含内嵌Web容器(默认使用的是Tomcat)的可运 ...

  2. spring boot基础学习教程

    Spring boot 标签(空格分隔): springboot HelloWorld 什么是spring boot Spring Boot是由Pivotal团队提供的全新框架,其设计目的是用来简化新 ...

  3. 快速开发架构Spring Boot 从入门到精通 附源码

    导读 篇幅较长,干货十足,阅读需花费点时间.珍惜原创,转载请注明出处,谢谢! Spring Boot基础 Spring Boot简介 Spring Boot是由Pivotal团队提供的全新框架,其设计 ...

  4. Spring Boot从入门到精通(五)多数据源配置实现及源码分析

    多数据源配置在项目软件中是比较常见的开发需求,Spring和Spring Boot中对此都有相应的解决方案可供大家参考.在Spring Boot中,如MyBatis.JdbcTemplate以及Jpa ...

  5. Spring Boot从入门到精通(六)集成Redis实现缓存机制

    Redis(Remote Dictionary Server ),即远程字典服务,是一个开源的使用ANSI C语言编写.支持网络.可基于内存亦可持久化的日志型.Key-Value数据库,并提供多种语言 ...

  6. Spring Boot从入门到精通(七)集成Redis实现Session共享

    单点登录(SSO)是指在多个应用系统中,登录用户只需要登录验证一次就可以访问所有相互信任的应用系统,Redis Session共享是实现单点登录的一种方式.本文是通过Spring Boot框架集成Re ...

  7. Spring Boot从入门到精通(八)日志管理实现和配置信息分析

    Spring Boot对日志的处理,与平时我们处理日志的方式完全一致,它为Java Util Logging.Log4J2和Logback提供了默认配置.对于每种日志都预先配置使用控制台输出和可选的文 ...

  8. Spring Boot从入门到精通(九)整合Spring Data JPA应用框架

    JPA是什么? JPA全称Java Persistence API,是Sun官方提出的Java持久化规范.是JDK 5.0注解或XML描述对象-关系表的映射关系,并将运行期的实体对象持久化到数据库中. ...

  9. [Spring框架]Spring AOP基础入门总结二:Spring基于AspectJ的AOP的开发.

    前言: 在上一篇中: [Spring框架]Spring AOP基础入门总结一. 中 我们已经知道了一个Spring AOP程序是如何开发的, 在这里呢我们将基于AspectJ来进行AOP 的总结和学习 ...

随机推荐

  1. Leetcode - Letter Combination Of A Phone Number

    Given a digit string, return all possible letter combinations that the number could represent. A map ...

  2. iOS 主题/皮肤之 SakuraKit

    前言 目前市场上很多 App 都有主题变更.皮肤切换的功能.随着项目代码量的不断增长,业务不断完善,功能性代码逐渐趋于模块化,尤其是在多人协作开发同一个项目时,模块解耦尤为重要,同时,公共基础库的功能 ...

  3. linux shell 之终端读写文件数据流和重定向>,<,<<,>>

    终端实现文件中数据流的读写: 重定向命令列表如下: 命令 说明 command > file 将输出重定向到 file.将终端数据写到文件file中 command < file 将输入重 ...

  4. vue.js基础知识篇(5):过渡、Method和Vue实例方法

    第8章:过渡 1.CSS过渡 2.JavaScript过渡 3.渐进过渡 第9章:method Vue.js的事件一般通过v-on指令配置在HTML中,虽然也可以在js的代码中使用原生的addEven ...

  5. LeetCode Weekly Contest 47

    闲着无聊参加了这个比赛,我刚加入战场的时候时间已经过了三分多钟,这个时候已经有20多个大佬做出了4分题,我一脸懵逼地打开第一道题 665. Non-decreasing Array My Submis ...

  6. Servlet的执行流程、生命周期

    下面这幅图的Request和Response的箭头方向反了,应该是客户端发出请求,然后web服务器返回响应. servlet生命周期阶段包括初始化.加载.实例化.服务和销毁.  编写Servlet的d ...

  7. [2013-01-15]The Little Schemer 学习笔记

    <The Little Schemer> FP编程.lisp入门必备 这书貌似没中文版: 有英文pdf版:完整版下载链接 英文不好的,被前几页噎住的,可以先到这里看翻译好的前言部分 看完人 ...

  8. python利用urllib实现的爬取京东网站商品图片的爬虫

    本例程使用urlib实现的,基于python2.7版本,采用beautifulsoup进行网页分析,没有第三方库的应该安装上之后才能运行,我用的IDE是pycharm,闲话少说,直接上代码! # -* ...

  9. Docker - Failed to connect to localhost port 4000: Connection refused

    转载.翻译自 https://stackoverflow.com/questions/44014698/docker-failed-to-connect-to-localhost-port-4000- ...

  10. Motion control encoder extrapolation

    Flying Saw debug Part1 Encoder extrapolation Machine introduction A tube cutting saw, is working for ...