SpringBoot基础梳理
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基础梳理的更多相关文章
- (二)SpringBoot基础篇- 静态资源的访问及Thymeleaf模板引擎的使用
一.描述 在应用系统开发的过程中,不可避免的需要使用静态资源(浏览器看的懂,他可以有变量,例:HTML页面,css样式文件,文本,属性文件,图片等): 并且SpringBoot内置了Thymeleaf ...
- SpringBoot基础系列一
SpringBoot基础知识概览 特性 核心理念:约定优于配置 特点: 1. 开箱即用,根据项目依赖自动配置 2. 功能强大的服务体系,如嵌入式服务.安全 3. 绝无代码生成,不用写.xml配置,用注 ...
- SpringBoot基础系列-SpringCache使用
原创文章,转载请标注出处:<SpringBoot基础系列-SpringCache使用> 一.概述 SpringCache本身是一个缓存体系的抽象实现,并没有具体的缓存能力,要使用Sprin ...
- SpringBoot基础系列-使用日志
原创作品,可以转载,但是请标注出处地址:https://www.cnblogs.com/V1haoge/p/9996897.html SpringBoot基础系列-使用日志 概述 SpringBoot ...
- SpringBoot基础系列-使用Profiles
原创作品,可以转载,但是请标注出处地址:https://www.cnblogs.com/V1haoge/p/9996884.html SpringBoot基础系列-使用Profile 概述 Profi ...
- SpringBoot基础系列-SpringBoot配置
原创作品,可以转载,但是请标注出处地址:https://www.cnblogs.com/V1haoge/p/9990680.html SpringBoot基础系列-SpringBoot配置 概述 属性 ...
- java面试总躲不过的并发(一): 线程池ThreadPoolExecutor基础梳理
本文核心:线程池ThreadPoolExecutor基础梳理 一.实现多线程的方式 1.继承Thread类,重写其run方法 2.实现Runnable接口,实现run方法 3.实现Callable接口 ...
- SpringBoot 基础01
SpringBoot 基础 pom.xml <!-- Spring Boot 依赖版本控制 --> <parent> <groupId>org.springfram ...
- java基础梳理--朝花夕拾(三)
1.了解面向对象的编程思想以及面向对象的特性: 对象: EveryThing is Object: 万物皆是对象,在程序中,我们可以将类.接口.方法.属性等都认为是对象: 面向对象: 是一种程序设计方 ...
随机推荐
- LODOP之票据连续套打笔记<一>
之前项目中需要使用套打,费了半天劲,最后找到LODOP,整体感觉还是不错,简单,满足大多数web套打 这是我项目中需要打印的票据 该票据每张做多显示6条数据,数据超过6条的时候需要进行分页打印,当时做 ...
- [LeetCode] Friend Circles 朋友圈
There are N students in a class. Some of them are friends, while some are not. Their friendship is t ...
- Example016实现下拉框
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- 解决ubuntu不能安装g++的问题
下面提供一种解决方法,解决方法不唯一 首先贴出错误原因: 上文是g++-4.8不能下载,所以退而求其次,指定版本4.7,不下载最新的 解决方法如下: 安装成功后而已查看版本信息确认 使用g++-4.7 ...
- java excel导出
下面是jsp代码: <li class="btns"><input id="btnExport" class="btn btn-pr ...
- MySQL--当mysqldump --single-transaction遇到alter table
部分生产环境采用mysqldump --single-transaction的方式在夜间进行数据库备份,而同事恰好在备份期间执行了alter table操作,操作部分成功部分失败,为啥呢? 在mysq ...
- DOCKER 从入门到放弃(三)
使用docker create [image-name] 创建一个容器 创建一个nginx镜像的容器,由于没有指定各项参数,容器实用默认参数,创建后并不会启动,并将容器的ID输出到终端,如果本地没有镜 ...
- (转载)Java自带的GUI性能监控工具Jconsole以及JisualVM简介
原文链接:http://blog.csdn.net/chendc201/article/details/22905503 1 Jconsole 1.1 简介以及连接 JConsole是一个基于JMX的 ...
- ReadAndWriteData
/** * 读取和写入不同基本类型数据 * * @throws IOException */ public static void main(String[] args) throws IOExcep ...
- 包装类、数组、string类浅析及练习
String s1 = "abc"; String s2 = "abc"; System.out.println(s1==s2); //返回true Strin ...