1.入口类和@SpringBootApplication注解:

SpringBoot通常有一个名为*Application的入口类,入口类里面有main方法,我们可以通过启动main方法启动springboot应用

@SpringBootApplication是SpringBoot的核心注解,他是一个组合注解,源码如下:

 @Target({ ElementType.TYPE })
@Retention(RetentionPolicy.RUNTIME)
@Documented
@Inherited
@SpringBootConfiguration
@EnableAutoConfiguration
@ComponentScan(excludeFilters = { @Filter(type = FilterType.CUSTOM, classes = { TypeExcludeFilter.class }) })
public @interface SpringBootApplication {
Class<?>[] exclude() default {}; String[] excludeName() default {}; @AliasFor(annotation = ComponentScan.class, attribute = "basePackages")
String[] scanBasePackages() default {}; @AliasFor(annotation = ComponentScan.class, attribute = "basePackageClasses")
Class<?>[] scanBasePackageClasses() default {};
}

如果我们不使用@SpringBootApplication,我们可以直接在入口类上使用

@SpringBootConfiguration
@EnableAutoConfiguration
@ComponentScan

其中@EnableAutoConfiguration 是让Springboot根据类路劲中的jar包依赖为当前项目进行自动配置

例如:我们添加了spring-boot-starter-web依赖后,会自动添加Tomcat和SpeingMVC的依赖,那么Spring Boot会对Tomcat和SpringMVC进行自动配置

2.使用xml配置Springboot

我们可以通过@ImportResource来加载xml配置

例如:

@ImportResource("classpath:some-context.xml")

3.基于安全的配置类型

Springboot可以通过@ConfigurationProperties将properties和一个Bean及其属性关联,从而实现安全的配置

例如:

 @Component
@ConfigurationProperties(prefix="author")//通过@ConfigurationProperties加载指定的properties文件内容
//通过prefix属性指定properties的配置前缀,通过location指定properties文件的位置,例如:
//@ConfigurationProperties(prefix="author",locations="classpath:config/author.properties") 本例不需要配置location
public class AuthorSettings {
private String name;
private Long age;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public Long getAge() {
return age;
}
public void setAge(Long age) {
this.age = age;
}
}

配置文件如下

author.name=xmz
author.age=23

SpringBoot基础梳理的更多相关文章

  1. (二)SpringBoot基础篇- 静态资源的访问及Thymeleaf模板引擎的使用

    一.描述 在应用系统开发的过程中,不可避免的需要使用静态资源(浏览器看的懂,他可以有变量,例:HTML页面,css样式文件,文本,属性文件,图片等): 并且SpringBoot内置了Thymeleaf ...

  2. SpringBoot基础系列一

    SpringBoot基础知识概览 特性 核心理念:约定优于配置 特点: 1. 开箱即用,根据项目依赖自动配置 2. 功能强大的服务体系,如嵌入式服务.安全 3. 绝无代码生成,不用写.xml配置,用注 ...

  3. SpringBoot基础系列-SpringCache使用

    原创文章,转载请标注出处:<SpringBoot基础系列-SpringCache使用> 一.概述 SpringCache本身是一个缓存体系的抽象实现,并没有具体的缓存能力,要使用Sprin ...

  4. SpringBoot基础系列-使用日志

    原创作品,可以转载,但是请标注出处地址:https://www.cnblogs.com/V1haoge/p/9996897.html SpringBoot基础系列-使用日志 概述 SpringBoot ...

  5. SpringBoot基础系列-使用Profiles

    原创作品,可以转载,但是请标注出处地址:https://www.cnblogs.com/V1haoge/p/9996884.html SpringBoot基础系列-使用Profile 概述 Profi ...

  6. SpringBoot基础系列-SpringBoot配置

    原创作品,可以转载,但是请标注出处地址:https://www.cnblogs.com/V1haoge/p/9990680.html SpringBoot基础系列-SpringBoot配置 概述 属性 ...

  7. java面试总躲不过的并发(一): 线程池ThreadPoolExecutor基础梳理

    本文核心:线程池ThreadPoolExecutor基础梳理 一.实现多线程的方式 1.继承Thread类,重写其run方法 2.实现Runnable接口,实现run方法 3.实现Callable接口 ...

  8. SpringBoot 基础01

    SpringBoot 基础 pom.xml <!-- Spring Boot 依赖版本控制 --> <parent> <groupId>org.springfram ...

  9. java基础梳理--朝花夕拾(三)

    1.了解面向对象的编程思想以及面向对象的特性: 对象: EveryThing is Object: 万物皆是对象,在程序中,我们可以将类.接口.方法.属性等都认为是对象: 面向对象: 是一种程序设计方 ...

随机推荐

  1. 梳理spring的层次结构的神器

    今天发现一个快速搞定spring层次结构的神器:效果如下 这是用idea编辑器直接生成的.还可以显示方法属性等等.简直神器.谁用谁知道... 操作如下:

  2. Notepad++中过滤掉的正则方式

    2 => 'ashadv'3 => 'aogro'4 => 'aogs'5 => 'ashamw'6 => 'arc'8 => 'gtsatq'9 => 'b ...

  3. js中数学运算的处理

    connum = Number(connum) + Number($(this).parents('.123').find(".views_core_hidden").val()) ...

  4. shell中source与sh区别

    shell中使用source conf.sh,是直接运行conf.sh的命令,不创建子shell,类似与html中include,而sh是则创建子shell, 子shell里面 的变量父shell无法 ...

  5. 使用kindlegen实现自主文件发送

    最近入手一部kindle,本着努力学习的想法,想通过它来提高自己的英文阅读水平,不过,入手之后,发现用来看杂文的时间远大于看英文文章的时间,时间罪过,为了减轻自己的负罪感,决定要用它来实现最初的作用, ...

  6. php生成Excel表格

    //引用新建对象<br>require "../phpexcel/Classes/PHPExcel.php"; $excel = new PHPExcel(); 建表格 ...

  7. 今天get到的两个angular知识点

    angular 控制器$scope依赖注入的正确写法 <div ng-controller="ctrl"> {{name}} {{age}} <div ng-co ...

  8. Web自动化之Headless Chrome编码实战

    API 概览 && 编码Tips 文档地址 github Chrome DevTools Protocol 协议本身的仓库 有问题可以在这里提issue github debugger ...

  9. 在ubuntu14.04上安装mono4.4 + jexus + mvc6

    0.准备工作 在/usr下建立一个文件夹,方便管理源码 cd /usr mkdir opensource cd opensource 安装vim(文本编辑器,不习惯用vim可以换成其他的) apt-g ...

  10. [基础架构]PeopleSoft工作原理(从浏览器发送请求开始)

    PeopleSoft体系结构是由几大组成部分构成,之前文章已经详细讲过,了解这几大组成部分是怎么协同工作的更为重要.在本文中将帮助您了解PeopleSoft的工作原理以及用户发送的请求是如何被解析以及 ...