SpringBoot-核心依赖说明
spring-boot-dependencies
一般用来放在父项目中,来声明依赖,子项目引入相关依赖而不需要指定版本号,好处就是解决依赖冲突,统一管理依赖版本号
利用pom的继承,一处声明,处处使用。在最顶级的spring-boot-dependencies中,使用dependencyManagement让所有子项目引用一个依赖而不用显式的列出版本号,将结构信息,部署信息,共同的依赖信息放置在统一的位置。dependencyManagement只声明依赖,并不真正引入,因此子项目需要通过dependencies引入相关依赖。
maven依赖
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-dependencies</artifactId>
<version>1.5.6.RELEASE</version>
<type>pom</type>
<scope>import</scope>
</dependency>
spring-boot-devtools
devtools是spring boot提供的工具。运行打包的应用程序时,开发人员工具会自动禁用。如果你通过java -jar或者其他特殊的类加载器进行启动时,都会被认为是“生产环境的应用”。
将依赖标记为optional可选是一种最佳做法,可以防止将devtools依赖传递到其他模块中。
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<optional>true</optional>
</dependency>
spring-boot-devtools的作用
1、禁用默认缓存
Spring Boot支持的一些库中默认会使用缓存。虽然缓存在生产中非常有益,但是在开发过程中有可能产生反效果,devtools将默认禁用这些缓存选项
2、自动重启
类路径的文件发生更改时,会触发自动重启,某些资源修改不一定需要触发重启,例如Thymeleaf模板。默认情况下更改/META-INF/maven , /META-INF/resources , /resources , /static , /public或/templates中的资源不会触发重启,但会触发实时重新加载。 如果要自定义这些排除项,可以使用spring.devtools.restart.exclude属性,如果想保留上面的默认排除项,还想增加新的,可以使用spring.devtools.restart.additional-exclude属性
spring-boot-starter-actuator
Actuator提供了很多生产级的特性,比如监控和度量Spring Boot应用程序。这些特性可以通过REST端点、远程shell和JMX获得。
1、介绍
Maven引入依赖
<dependency>
<!-- It is in order to get app info -->
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
应用启动日志会有如下信息,表明获取一些信息的url

下面列出最常用的一些


2、Actuator定制化
解释一下上图配置
将端点整体禁用,然后autoconfig、shutdown、beans启用,将shutdown的路径由/shutdown改为/kill
3、保护 Actuator 端点
actuator就是为了查看应用的一些信息,其中不乏一些敏感信息,对这些端点进行保护还是很有必要。
使用Spring Security,下面以/shutdown,/metrics端点为例
① 权限认证
@Override
protected void configure(HttpSecurity http) throws Exception {
http
.authorizeRequests()
.antMatchers("/").access("hasRole('READER')")
.antMatchers("/shutdown","/metrics").access("hasRole('ADMIN')")
.antMatchers("/**").permitAll()
.and()
.formLogin()
.loginPage("/login")
.failureUrl("/login?error=true");
}
要能够访问/shutdown,必须用一个带有admin权限的用户
② 用户身份认证
@Override
protected void configure(AuthenticationManagerBuilder auth) throws Exception {
auth.userDetailsService(new UserDetailsService() {
@Override
public UserDetails loadUserByUsername(String username)
throws UsernameNotFoundException {
UserDetails user = readerRepository.findOne(username);
if (user != null) {
return user;
}
throw new UsernameNotFoundException(
"User '" + username + "' not found.");
}
})
.and()
.inMemoryAuthentication()
.withUser("admin").password("s3cr3t")
.roles("ADMIN", "READER");
}
userDetailsService是使用repository来操作数据库查询出对应的用户,inMemoryAuthentication()是往内存中添加一个用户,拥有角色ADMIN、READER。
spring-boot-starter-security
人如其名,是用来保证应用安全的,核心功能授权和认证
默认访问用户密码
如果没有进行额外配置,那么应用启动会生成一串默认密码。用户名为user,密码在日志文件或控制台寻找 Using default security password: 62ccf9ca-9fbe-4993-8566-8468cc33c28c
当然也可以自定义访问用户,在application.yml文件security.user.name,security.user.password制定
还可以通过自定义编写配置类继承WebSecurityConfigurerAdapter类,并在配置类上面加上@Configuration@EnableWebSecurity两个注解,重写 protected void configure(HttpSecurity http) protected void configure(AuthenticationManagerBuilder auth) 两个方法进行授权和认证,可以参考上面两段代码
SpringBoot-核心依赖说明的更多相关文章
- 浅谈SpringBoot核心注解原理
SpringBoot核心注解原理 今天跟大家来探讨下SpringBoot的核心注解@SpringBootApplication以及run方法,理解下springBoot为什么不需要XML,达到零配置 ...
- SpringBoot(二) SpringBoot核心配置文件application.yml/properties
我们都知道在Spring中有着application.xml文件对Spring进行相关配置,通过web.xml中的contextConfigLocation指定application.xml文件所在位 ...
- Springboot核心注解
运行文中的代码需要在项目构建中引入springboot 相关依赖. ① @configuration configuration,用来将bean加入到ioc容器.代替传统xml中的bean配置.代码示 ...
- 深入理解SpringBoot核心机制《spring-boot-starter》
深入理解SpringBoot核心机制<spring-boot-starter> 前言: 对于这几年java火爆天的springBoot我相信大家都有所使用过,在springBoot的项目中 ...
- 这一次搞懂SpringBoot核心原理(自动配置、事件驱动、Condition)
@ 目录 前言 正文 启动原理 事件驱动 自动配置原理 Condition注解原理 总结 前言 SpringBoot是Spring的包装,通过自动配置使得SpringBoot可以做到开箱即用,上手成本 ...
- IntelliJ IDEA中如何再次调出springboot的依赖窗口
原文链接:https://blog.csdn.net/qq_38138069/article/details/102528587 IDEA中如何再次调出springboot的依赖窗口,随时可以根据喜好 ...
- SpringBoot核心注解应用
1.今日大纲 了解Spring的发展 掌握Spring的java配置方式 学习Spring Boot 使用Spring Boot来改造购物车系统 2.Spring的发展 Spring1.x 时代 在S ...
- SpringBoot 核心配置
1. 入口类和 @SpringBootApplication Spring Boot的项目一般都会有*Application的入口类,入口类中会有main方法,这是一个标准的Java应用程序的入口方法 ...
- springboot深入学习(一)-----springboot核心、配置文件加载、日志配置
一.@SpringBootApplication @SpringBootApplication是spring boot的核心注解,源码如下: 相当于:@Configuration+@EnableAut ...
- SpringBoot核心
1.基本配置 1.1入口类和@SrpingBootApplication SpringBoot通常有一个名为*Application的入口类,入口类里有一个main方法,这个main方法就是一个标准的 ...
随机推荐
- SQL Server 时间戳与时间格式互相转换
时间戳(Unix timestamp) 是一种时间表示方式,定义为从格林威治时间1970年01月01日00时00分00秒起至现在的总秒数. Unix时间戳不仅被使用在Unix系统.类Unix系统中,也 ...
- Django:(05)类视图,装饰器和中间件
一.类视图的定义和使用 在Django中还可以通过类来定义一个视图,称为类视图. 定义一个类视图:定义一个类,需继承 Django 提供的 View 类 . from django.views.gen ...
- JMeter-- ThreadGroup原理分析
JMeterEngine会驱动JMeter ThreadGroup启动Test Threads 执行测试,其本身也是一个Runnable,这里把测试驱动(JUnit或者其他类似main之类的)看作主线 ...
- 使用zookeeper作为分布式锁以及设计一种通知监听模式
1.创建实例/** * 初始化单例的便捷方法 */ public static void init() { getInstance(); } /** * 获取单例 * @return */ publi ...
- Node数据库入门(登录注册功能)
1.安装 (1).mysql模块安装 npm i mysql -D (2).co-msql模块安装(该模块不是一个独立的模块,而是mysql的封装,他可以把普通接连封装成一个可以做异步调用的连接) n ...
- linux的route
参考: https://blog.csdn.net/u011857683/article/details/83795435 老男孩: https://blog.51cto.com/oldboy/974 ...
- Jenkins学习指南
jenkinshttps://www.cnblogs.com/jimmy-xuli/p/9020825.htmlhttps://www.cnblogs.com/along21/p/10172855.h ...
- Oracle系统权限与对象权限
oracle权限分为: 系统权限: 允许用户执行特定的数据库动作,如创建表.创建索引.连接实例等. 对象权限: 允许用户操纵一些特定的对象,如读取视图,可更新某些列.执行存储过程等. 系统权限 超过一 ...
- sqlserver bcp命令导出数据
原文:sqlserver bcp命令导出数据 版权声明:本文为博主原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明. 本文链接:https://blog.csdn.net ...
- Linux就该这么学——新手必须掌握的命令之常用的系统工作命令
echo命令 含义:echo命令用于在终端输出字符串或变量提取后的值,格式为 : echo [字符串|$变量] 示例: 将”Linuxprobe.com”输出到终端屏幕的命令为: [root@linu ...