-
springboot2整合oauth2
2018-06-15 14:10:091.背景 项目由springboot1.5.X升级到...完整项目demo:https://gitee.com/zkane/springboot2-oauth2.git 2.spring security Spring Security 从入门到进阶系列教程网址:http://www.spring4all.com/ar...1.背景
项目由springboot1.5.X升级到springboot2.0.0后,导致各组件API以及依赖包发生了变化。
完整项目demo:码云
2.spring security
Spring Security 从入门到进阶系列教程网址:http://www.spring4all.com/article/428
- spring security架构图
- 认证过程
3.OAuth2
- OAuth2基础概念网址:http://www.ruanyifeng.com/blog/2014/05/oauth_2_0.html
- OAuth2分为3个部分:1认证服务器2资源服务器3第三方应用
- OAuth2有4种授权模式:1授权码模式2简化模式3密码模式4客户端模式
4.使用springboot2+oauth2注意事项
- 项目搭建参考网址:
https://blog.csdn.net/qq_19671173/article/details/79748422
http://wiselyman.iteye.com/blog/2411813
4.1.在pom.xml文件中导入依赖包发生变化
<!-- springboot2.0已经将oauth2.0与security整合在一起 --> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-security</artifactId> </dependency> <!-- 由于一些注解和API从spring security5.0中移除,所以需要导入下面的依赖包 --> <dependency> <groupId>org.springframework.security.oauth.boot</groupId> <artifactId>spring-security-oauth2-autoconfigure</artifactId> <version>2.0.0.RELEASE</version> </dependency> <!-- redis相关依赖包 --> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-data-redis</artifactId> </dependency> <dependency> <groupId>org.apache.commons</groupId> <artifactId>commons-pool2</artifactId> </dependency>
4.2.直接使用RedisTokenStore存储token会出现NoSuchMethodError RedisConnection.set([B[B)V错误
解决方案:自己编写一个MyRedisTokenStore,复制RedisTokenStore类中代码,并将代码中conn.set(accessKey, serializedAccessToken)修改为conn.stringCommands().set(accessKey, serializedAccessToken);
4.3.前后端分离时,存在跨域问题
解决方案:
- 方案一在后端注册corsFilter
import org.springframework.boot.web.servlet.FilterRegistrationBean; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.core.Ordered; import org.springframework.web.cors.CorsConfiguration; import org.springframework.web.cors.UrlBasedCorsConfigurationSource; import org.springframework.web.filter.CorsFilter; @Configuration public class CorsConfig { private CorsConfiguration buildConfig() { CorsConfiguration corsConfiguration = new CorsConfiguration(); // 1 corsConfiguration.addAllowedOrigin("*"); // 2 corsConfiguration.addAllowedHeader("*"); // 3 corsConfiguration.addAllowedMethod("*"); corsConfiguration.setAllowCredentials(true); return corsConfiguration; } @Bean public FilterRegistrationBean corsFilter() { UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource(); // step 4 source.registerCorsConfiguration("/**", buildConfig()); FilterRegistrationBean bean = new FilterRegistrationBean(new CorsFilter(source)); bean.setOrder(Ordered.HIGHEST_PRECEDENCE); return bean; } }
- 方案二,在启动类添加bean到IOC容器中
@SpringBootApplication public class ZuulServerApplication { public static void main(String[] args) { SpringApplication.run(ZuulServerApplication.class, args); } /** * 解决前后端分离跨域问题 * * @return */ @Bean public CorsFilter corsFilter() { final UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource(); final CorsConfiguration config = new CorsConfiguration(); config.setAllowCredentials(true); config.addAllowedOrigin("*"); config.addAllowedHeader("*"); config.addAllowedMethod("*"); source.registerCorsConfiguration("/**", config); return new CorsFilter(source); } }
4.4.前后端分离,登录页面放在前端时登录的问题
解决方案:授权模式使用password的方式
- 使用post请求访问http://localhost:20000/auth/oauth/token
- 在请求的headers中新增一个header:key=Authorization,value=Basic Y2xpZW50OnNlY3JldA==
(Y2xpZW50OnNlY3JldA==为64编码,格式:client:secret)
- 在form-data中传递参数:username(用户账号)、password(用户密码)、grant_type(固定值:password)、scope(作用域)
4.5.访问资源服务器的方式
- 当通过在认证服务器获取到token后,有三种方式访问资源服务器
- 在Headers中携带:key=Authorization,value=bearer 797c4200-8b10-4a2b-8764-33397749a8f7
- 拼接在URL中:http://localhost:8088/user?access_token=797c4200-8b10-4a2b-8764-33397749a8f7
- 在form表单中:name=access_token,value=797c4200-8b10-4a2b-8764-33397749a8f7
4.6.spring security密码配置问题
- secret密码配置从 Spring Security 5.0开始必须以 {加密方式}+加密后的密码 这种格式填写
- 当前版本5新增支持加密方式:
bcrypt - BCryptPasswordEncoder (Also used for encoding)
ldap - LdapShaPasswordEncoder
MD4 - Md4PasswordEncoder
MD5 - new MessageDigestPasswordEncoder(“MD5”)
noop - NoOpPasswordEncoder
pbkdf2 - Pbkdf2PasswordEncoder
scrypt - SCryptPasswordEncoder
SHA-1 - new MessageDigestPasswordEncoder(“SHA-1”)
SHA-256 - new MessageDigestPasswordEncoder(“SHA-256”)
sha256 - StandardPasswordEncoder
4.7.通过spring security的角色限制访问受保护的接口
- 在配置类或启动类上添加注解 @EnableGlobalMethodSecurity(securedEnabled = true)
@EnableOAuth2Sso @Configuration @EnableGlobalMethodSecurity(securedEnabled = true) public class SecurityConfig extends WebSecurityConfigurerAdapter{ @Override protected void configure(HttpSecurity http) throws Exception { http.authorizeRequests() .antMatchers("/index") .permitAll() .anyRequest() .authenticated(); } }
- 在controller的类或方法上添加注解 @Secured(“ROLE_ADMIN”)
package com.bici.controller; import org.springframework.security.access.annotation.Secured; import org.springframework.security.core.Authentication; import org.springframework.security.core.context.SecurityContextHolder; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.CrossOrigin; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpSession; /** * @author: keluosi@bicitech.cn * @date: 2018/4/17 */ @RestController @RequestMapping("/client") @Secured("ROLE_ADMIN") public class ClientController { @GetMapping("/user") public Authentication getUser() { Authentication authentication = SecurityContextHolder.getContext().getAuthentication(); return authentication; } @GetMapping("/index") @Secured("ROLE_USER") public String index() { return "index"; } }
4.8.使用自定义的加密方式校验数据库中保存的加密后的密文
- 在@EnableWebSecurity注解的方法中编写代码
import com.bici.encrypt.EncryptUtil; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Qualifier; import org.springframework.context.annotation.Bean; import org.springframework.security.authentication.AuthenticationManager; import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder; import org.springframework.security.config.annotation.method.configuration.EnableGlobalMethodSecurity; import org.springframework.security.config.annotation.web.builders.HttpSecurity; import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity; import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter; import org.springframework.security.core.userdetails.UserDetailsService; import org.springframework.security.crypto.password.PasswordEncoder; @EnableWebSecurity public class SecurityConfig extends WebSecurityConfigurerAdapter { @Bean @Override public AuthenticationManager authenticationManagerBean() throws Exception { return super.authenticationManagerBean(); } @Qualifier("userDetailsService") @Autowired private UserDetailsService userDetailsService; @Override protected UserDetailsService userDetailsService() { // 自定义用户信息类 return this.userDetailsService; } @Override protected void configure(AuthenticationManagerBuilder auth) throws Exception { auth.userDetailsService(userDetailsService).passwordEncoder(new PasswordEncoder(){ @Override public String encode(CharSequence charSequence) { // 加密 return EncryptUtil.hashPasswordAddingSalt(charSequence.toString()); } @Override public boolean matches(CharSequence charSequence, String s) { // 密码校验 return EncryptUtil.isValidPassword(charSequence.toString(), s); } }) ; } }
4.9.通过配置返回通知获取token
可以在这个地方将token和username存入到缓存中,然后如果需要强制某个用户下线时,通过username从缓存中找到token,调用
ConsumerTokenServices
的revokeToken(token)
方法。package com.zkane.aspect; import org.aspectj.lang.annotation.AfterReturning; import org.aspectj.lang.annotation.Aspect; import org.aspectj.lang.annotation.Pointcut; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.HttpRequest; import org.springframework.http.ResponseEntity; import org.springframework.security.core.Authentication; import org.springframework.security.core.context.SecurityContextHolder; import org.springframework.security.oauth2.common.OAuth2AccessToken; import org.springframework.stereotype.Component; import org.springframework.web.context.request.RequestContextHolder; import org.springframework.web.context.request.ServletRequestAttributes; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; /** * @author: 594781919@qq.com * @review: * @date: 2018/8/24 */ @Aspect @Component public class TokenAspect { @Pointcut("execution(* org.springframework.security.oauth2.provider.endpoint.TokenEndpoint.postAccessToken(..))") private void token() { } @AfterReturning(returning = "obj", pointcut = "token()") public void doAfterReturning(ResponseEntity<OAuth2AccessToken> obj) throws Exception { HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest(); // 打印用户名 System.out.println(request.getParameter("username")); // 打印token System.out.println(obj.getBody().getValue()); } }
5.不足或后续改进
5.1.客户端信息保存到数据中
- 创建sql语句
CREATE TABLE `oauth_client_details` ( `client_id` varchar(256) NOT NULL, `resource_ids` varchar(256) DEFAULT NULL, `client_secret` varchar(256) DEFAULT NULL, `scope` varchar(256) DEFAULT NULL, `authorized_grant_types` varchar(256) DEFAULT NULL, `web_server_redirect_uri` varchar(256) DEFAULT NULL, `authorities` varchar(256) DEFAULT NULL, `access_token_validity` int(11) DEFAULT NULL, `refresh_token_validity` int(11) DEFAULT NULL, `additional_information` varchar(4096) DEFAULT NULL, `autoapprove` varchar(256) DEFAULT NULL, PRIMARY KEY (`client_id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8; INSERT INTO oauth_client_details ( client_id, resource_ids, client_secret, scope, authorized_grant_types, web_server_redirect_uri, authorities, access_token_validity, refresh_token_validity, additional_information, autoapprove ) VALUES ( 'client', NULL, '{noop}secret', 'all', 'password,authorization_code,refresh_token,implicit,client_credentials', NULL, NULL, NULL, NULL, NULL, 'true' );
- 以jdbc方式配置客户端信息
@Configuration @EnableAuthorizationServer public class ServerConfig extends AuthorizationServerConfigurerAdapter { @Override public void configure(ClientDetailsServiceConfigurer clients) throws Exception { clients.jdbc(dataSource); } }
5.2.前后端分离,导致单点登录问题
- 目前通过网上下载的demo,还没有查找到第三方应用前后端分离,怎么去登录的问题。
- 第三方应用一般都是通过请求转发页面时,到认证中心去登录。也就是前后端未分离的情况,使用注解@EnableOAuth2Sso
- 建议解决方案:通过前端进行跳转到唯一的登录页面,登录成功后再返回到原来系统并带上token
5.3.密码错误时,返回前端的json未实现自定义返回内容
{ "error": "invalid_grant", "error_description": "Bad credentials" }
update 2018-04-28
自定义返回前端的登录错误信息
- 将spring-security-core\5.0.3.RELEASE\org\springframework\security\messages_zh_CN.properties拷贝到resources目录下
- 在启动类中编写代码
@SpringBootApplication public class Application { public static void main(String[] args) { SpringApplication.run(Application.class, args); } @Bean public ReloadableResourceBundleMessageSource messageSource() { ReloadableResourceBundleMessageSource messageSource = new ReloadableResourceBundleMessageSource(); messageSource.setBasename("classpath:messages"); return messageSource; } }
- 显示效果,error_description是在messages_zh_CN.properties中自己根据需要编写的
{ "error": "invalid_grant", "error_description": "账号未注册,请联系管理员" }
- spring security架构图
-
SpringBoot2.X (十四): @SpringBootTest单元测试
2018-06-08 08:33:22那么先简单说一下为什么要写测试用例 : ...好了,说道这里,应该明白测试的一个重要性了,,,接下来,我们正式进入SpringBoot2.X 的 测试实践中吧。。。 1、引入相关依赖 <!--springboot程序测试依...那么先简单说一下为什么要写测试用例 :
-
可以避免测试点的遗漏,为了更好的进行测试,可以提高测试效率
-
可以自动测试,可以在项目打包前进行测试校验
-
可以及时发现因为修改代码导致新的问题的出现,并及时解决
好了,说道这里,应该明白测试的一个重要性了,,,接下来,我们正式进入SpringBoot2.X 的 测试实践中吧。。。
1、引入相关依赖
<!--springboot程序测试依赖,如果是自动创建项目默认添加--> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-test</artifactId> <scope>test</scope> </dependency>
2、使用
我们发现
SpringRunner
底层使用的是JUnit
Junit这种老技术,相信很多人都相当的熟悉了,SpringBoot 2.X 默认使用Junit4
接下来我们简单说一下在SpringBoot 中的使用吧@RunWith(SpringRunner.class)
@SpringBootTest(classes={Application.class})// 指定启动类
//@SpringApplicationConfiguration(classes = Application.class)// 1.4.0 前版本
public class ApplicationTests {
@Test
public void testOne(){
System.out.println(“test hello 1”);
}@Test public void testTwo(){ System.out.println("test hello 2"); TestCase.assertEquals(1, 1); } @Before public void testBefore(){ System.out.println("before"); } @After public void testAfter(){ System.out.println("after"); }
}
ok, 以上就是我们编写的几个简单的测试用例,现在我们查看下测试结果  **Junit基本注解介绍** *`@BeforeClass`* 在所有测试方法前执行一次,一般在其中写上整体初始化的代码 *`@AfterClass`* 在所有测试方法后执行一次,一般在其中写上销毁和释放资源的代码 *`@Before`* 在每个测试方法前执行,一般用来初始化方法(比如我们在测试别的方法时,类中与其他测试方法共享的值已经被改变,为了保证测试结果的有效性,我们会在@Before注解的方法中重置数据) *`@After`* 在每个测试方法后执行,在方法执行完成后要做的事情 *`@Test(timeout = 1000)`* 测试方法执行超过1000毫秒后算超时,测试将失败 *`@Test(expected = Exception.class)`* 测试方法期望得到的异常类,如果方法执行没有抛出指定的异常,则测试失败 *`@Ignore(“not ready yet”)`* 执行测试时将忽略掉此方法,如果用于修饰类,则忽略整个类 *`@Test `* 编写一般测试用例 *`@RunWith`* 在JUnit中有很多个Runner,他们负责调用你的测试代码,每一个Runner都有各自的特殊功能,你要根据需要选择不同的Runner来运行你的测试代码。 如果我们只是简单的做普通Java测试,不涉及Spring Web项目,你可以省略@RunWith注解,这样系统会自动使用默认Runner来运行你的代码。 以上就是我们再SpringBoot2.X 中的测试过程示例( 当然也是用 SpringBoot 1.X ),是不是可以说 *`so easy`*? `欢迎关注博主公众号`: 
-
-
SpringBoot2 | SpringBoot2 Hikari数据源配置
2018-10-11 13:16:09SpringBoot2中默认的数据已经更改为hikari,据说性能很高,有兴趣的可以进行测试。 配置 之前在做springBoot1.5升级到springBoot2.0时,发现数据源出错,看了下官方文档,才发现,默认数据源已修改。 使用...概述
SpringBoot2中默认的数据已经更改为
hikari
,据说性能很高,有兴趣的可以进行测试。
目前使用最广泛的druid
基础数组实现,而hikari
则是基于threadlocal
+CopyOnWriteArrayList
实现。
配置
之前在做
springBoot1.5
升级到springBoot2.0
时,发现数据源出错,看了下官方文档,才发现,默认数据源已修改。使用方式
在
pom.xml
中引入依赖:<dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-jdbc</artifactId> </dependency>
然后配置文件中添加配置:
#datasource spring.datasource.driver-class-name=com.mysql.jdbc.Driver spring.datasource.url=jdbc:mysql://localhost:3306/ak_blog?autoReconnect=true&useUnicode=true&characterEncoding=utf-8&allowMultiQueries=true spring.datasource.username=root spring.datasource.password= spring.datasource.type=com.zaxxer.hikari.HikariDataSource spring.datasource.hikari.minimum-idle=5 spring.datasource.hikari.maximum-pool-size=15 spring.datasource.hikari.auto-commit=true spring.datasource.hikari.idle-timeout=30000 spring.datasource.hikari.pool-name=DatebookHikariCP spring.datasource.hikari.max-lifetime=1800000 spring.datasource.hikari.connection-timeout=30000 spring.datasource.hikari.connection-test-query=SELECT 1
理论上只需要以上配置即可,但是有些时候整合一些
orm
框架或者事务,不够灵活。所以以下是自定义配置。
自定义配置
自定义数据源官网给出了两种方式:
先看官网给的配置文件:
app.datasource.jdbc-url=jdbc:mysql://localhost/test app.datasource.username=dbuser app.datasource.password=dbpass app.datasource.maximum-pool-size=30
1)第一种是使用
DataSourceBuilder
来构造数据源:@Bean @ConfigurationProperties("app.datasource") public HikariDataSource dataSource() { return DataSourceBuilder.create().type(HikariDataSource.class).build(); }
2)第二种是使用
DataSourceProperties
来构造数据源:@Bean @Primary @ConfigurationProperties("app.datasource") public DataSourceProperties dataSourceProperties() { return new DataSourceProperties(); } @Bean @ConfigurationProperties("app.datasource") public HikariDataSource dataSource(DataSourceProperties properties) { return properties.initializeDataSourceBuilder().type(HikariDataSource.class) .build(); }
双数据源配置
app.datasource.first.type=com.zaxxer.hikari.HikariDataSource app.datasource.first.maximum-pool-size=30 app.datasource.second.url=jdbc:mysql://localhost/test app.datasource.second.username=dbuser app.datasource.second.password=dbpass app.datasource.second.max-total=30
采用
DataSourceProperties
构造:@Bean @Primary @ConfigurationProperties("app.datasource.first") public DataSourceProperties firstDataSourceProperties() { return new DataSourceProperties(); } @Bean @Primary @ConfigurationProperties("app.datasource.first") public DataSource firstDataSource() { return firstDataSourceProperties().initializeDataSourceBuilder().build(); } @Bean @ConfigurationProperties("app.datasource.second") public DataSourceProperties secondDataSourceProperties() { return new DataSourceProperties(); } @Bean @ConfigurationProperties("app.datasource.second") public DataSource secondDataSource() { return secondDataSourceProperties().initializeDataSourceBuilder().build(); }
-
springboot2整合OAuth2.0认证实例
2018-06-24 22:48:48springboot2整合OAuth2.0实例 代码实例放到:https://github.com/haoxiaoyong1014/springboot-examples springboot-oauth2 包括: springboot-oauth2-authorization-server(认证服务)和springboot-oauth2-...springboot2整合OAuth2.0实例
代码实例放到:https://github.com/haoxiaoyong1014/springboot-examples
springboot-oauth2 包括: springboot-oauth2-authorization-server(认证服务)和springboot-oauth2-resource-server(资源服务)
springBoot版本:2.0.1.RELEASE授权码模式:
-
访问认证服务器
-
http://localhost:8888/oauth/authorize?response_type=code&client_id=merryyou&redirect_uri=https://github.com/haoxiaoyong1014?tab=repositories&scope=all
-
是否同意并授权
- 假设用户给予授权,认证服务器将用户导向客户端事先指定的"重定向URI"(redirection URI),同时附上一个授权码(code)。
- 拿到这个授权码(code)去交换 access_token
- 认证服务器核对了授权码和重定向URI,确认无误后,向客户端发送访问令牌(access token)和更新令牌(refresh token)。
- 还有一点需要说明 在请求头中处理了加入 Content-Type : application/x-www-form-urlencoded 还要加入:Authorization:Basic bWVycnl5b3U6bWVycnl5b3U=
其中 Authorization的值是 CLIENT_ID 和 CLIENT_SECRET Base64加密得到 详细内容在 springboot-examples/springboot-oauth2-authorization-server/src/test/java/cn/merryyou/security/SpringBoot2Oauth2Test.java 中
写在最后加wx,获得更多关于Spring Security OAuth2.0视频
-
-
SpringBoot2 | SpringBoot启动流程源码分析(一)
2018-08-31 15:29:58概述: 前阵子看到了SpringCloud社区的一个...另外在现有的springboot专栏中,大多数博文旨在应用,对一些中间件的整合之类,源码分析的博客数量有限。鉴于以上两方面,该系列应运而生。 该系列主要还是Spri... -
Springboot2.x使用JPA整合Redis
2020-06-08 13:18:55SpringBoot2.3,使用MySQL数据库,通过JPA实现ORM,再用Redis实现数据库的缓存。 代码实现: pom.xml <!-- 集成redis --> <dependency> <groupId>org.springframework.boot</groupId>... -
【SpringBoot 2学习笔记】《十五》SpringBoot2 学习后记
2020-03-26 17:11:16SpringBoot2学习文章目录 经过两个月的学习,SpringBoot2基本上学了一轮,也都整理了资料。接下来开始,考虑以一个小系统来讲前面整理的内容串联起来,同时可以学习前端Vue的开发。具体的内容还没有想好,这几天一直... -
springboot2系列技术教程目录
2018-12-25 22:08:26Springboot2(1)日志配置和动态日志等级设置 Springboot2(2)属性配置&amp;amp;amp;amp;amp;amp;amp;自定义属性配置 Springboot2(3)静态资源处理 Springboot2(4)Controller控制层讲解 Spri... -
springboot2整合disconf
2018-10-22 20:42:30springboot2整合disconf -
SpringBoot2 | SpringBoot Environment源码分析(四)
2018-09-17 15:32:32SpringBoot2 | SpringBoot启动流程源码分析(一) SpringBoot2 | SpringBoot启动流程源码分析(二) SpringBoot2 | @SpringBootApplication注解 自动化配置流程源码分析(三) 一、概述 Environment... -
SpringBoot2+RabbitMQ详细教程
2019-12-06 17:54:27SpringBoot2+RabbitMq的整合无论是点对点还是topic均能搞定。 【RabbitMQ是什么?】 我们在双11的夜晚购物和12306抢票,当我们凌晨大量的秒杀和抢购商品或者火车票,然后去结算的时候,就会发现,界面会提醒我们... -
SpringBoot2 | SpringBoot启动流程源码分析(二)
2018-09-03 16:01:43在上一篇SpringBoot | SpringBoot2 | SpringBoot2启动流程源码分析(一)中我们提到springBoot启动流程大致有以下7点: 第一步:获取并启动监听器 第二步:构造容器环境 第三步:创建容器 第四步:实例化... -
Springboot2整合Redis
2019-06-13 23:21:36Springboot2整合RedisSpringboot2整合Redis新的改变01:导入依赖02:配置03:查看源码:RedisAutoConfiguration自动配置类04:直接使用05:修改默认的序列化方法06:测试使用后的END Springboot2整合Redis 新的改变 ... -
SpringBoot2.X和SpringBoot1.X的区别
2019-07-24 09:53:00SpringBoot2.X和SpringBoot1.X的区别 SpringBoot2.X与1.X的区别 拦截器 在SpringBoot1.X中,定义拦截器可继承抽象类WebMvcConfigurerAdapter,并重写其中的addInterceptors()方法,但在SpringBoot2.X中... -
SpringBoot2.X最佳实践《一》 之 SpringBoot2.x初体验
2018-07-16 09:02:09SpringBoot2.X最佳实践 前言本系列文章,从零基础接触 SpringBoot2.x新版本,基础入门使用,热部署,到整合各个主流框架Redis4.x,消息队列AciveMQ, RocketMQ等,搜索框架ElasticSearch5.6版本,到web-flux反应式... -
springboot2读取配置文件
2018-09-05 10:19:30关键词:springboot2、配置文件 springboot读取配置文件,无外乎就两种情况:1)读取默认的application.yml;2)读取自定义的配置文件xxx.yml。由于版本升级,springboot2和springboot1读取自定义配置文件稍微有些... -
springboot2 springboot-admin - 服务管理与监控
2019-09-24 10:34:47最近公司的Springboot2.x项目中需要做一个服务监控工具,网上找到了springboot-admin。通过根据对官方文档和各位大佬的文章学习和分析,最终得以完成任务。 鉴于差点被网上各种文章绕晕,特此开篇写一个自认为靠谱... -
SpringBoot2.x 整合SpringBoot-Admin监控 — QS11
2018-12-06 10:46:00SpringBoot2.x 整合 SpringBoot-Admin 监控 -
SpringBoot2.X (十六): SpringBoot 全局异常配置
2018-07-05 19:34:16前言 1、 默认异常机制 2、自定义json格式异常... 接下来我们介绍一下SpringBoot2.X 的异常处理机制 1、 默认异常机制 默认异常处理(SpringBoot 默认提供了两种机制,一种是针对于web浏览器访问的错误页面响应,... -
SpringBoot2集成redis,使用lettuce客户端
2019-05-05 16:12:19可能很多人并没有注意,在Springboot2以后,底层访问redis已经不再是jedis了,而是lettuce。 至于jedis和lettuce有什么区别呢,对我们的使用有什么影响呢? jedis采用的是直连redis server,在多个线程之间共用一... -
互联网架构系列全套SpringBoot2.x初级入门到实战
2018-05-09 18:29:522018年 SpringBoot2.x视频教程 70多节课,18年5月份新录制,采用Springboot2.x版本 新版本新特性,包含基础框架讲解、热部署等 到使用。 整合多个主流框架,后到阿里云部署项目等知识。 学习笔记-源代码-答疑... -
【SpringBoot学习三】springboot2+hibernate5
2019-08-14 11:37:37springboot2集成hibernate5,先准备一个数据库及java驱动,我用的是mysql。 集成步骤如下 1.pom配置 需要的包如下,hibernate、spring事务、连接池、ORM、数据库驱动 <dependency> <groupId>org.... -
springboot2.X整合prometheus监控
2019-04-24 10:52:41springboot2.X整合prometheus监控springboot2.x暴露健康状况通过prometheus监控prometheus-operator监控java应用整合构建springboot项目的时候需要注意的点:部署prometheus需要注意的点参考 springboot2.x暴露健康... -
【SpringBoot】SpringBoot 2.x.x 版本 与 旧版本的区别
2019-06-21 16:43:19SpringBoot 2.x.x 版本 与 旧版本的区别 学习SpringBoot时,跟视频上的版本不一致,有几处地方不一样,特此记录 1、WebMvcConfigurerAdapter已过时 在新版本的SpringBoot中,WebMvcConfigurerAdapter这个抽象类已经... -
springboot2.x使用Actuator
2019-03-10 13:22:26Springboot2(16)运行状态监控使用Actuator springboot 2.0 运行状态监控使用 Actuator springboot2中使用actuator进行监控 纯洁的微笑springboot(十九):使用Spring Boot Actuator监控应用 SpringBoot | 第二... -
springboot2整合thymeleaf3
2018-10-10 11:13:53当你进来时,说明,你也被springboot2坑了, springboot2,实际上已经集成了thymeleaf3,就是说你不用在pom中配置什么了, 你只需要配置一个springboot的thymeleaf的pom 也就是 <dependency> &... -
SpringBoot 2.x 整合 redis 做缓存
2018-06-17 16:18:15SpringBoot 2.x 整合 redis 做缓存 SpringBoot 2.0在今年3月份正式发布,公司新起的项目中就使用了SpringBoot 2.0,相比1.0还是有比较多的改动。SpringBoot 自2.0起不再支持jdk1.8以下的版本,jdk1.8中引入的... -
Springboot2(53)整合oauth2
2019-06-28 15:53:48springboot2教程系列 OAuth 概念 OAuth 是一个开放标准,允许用户让第三方应用访问该用户在某一网站上存储的私密的资源(如照片,视频,联系人列表),而不需要将用户名和密码提供给第三方应用。OAuth允许用户... -
SpringBoot 1.x与SpringBoot 2.x的区别
2020-02-27 10:37:35首先需要说明的是,有差别,但差别不大。 基本上基于SpringBoot的代码不需要改动,但有些配置属性和配置类,可能要改动,改动原因是配置已经不存在或者...SpringBoot 2基于Spring5和JDK8,而Spring 1x则用的是降低版... -
SpringBoot1.5.X升级SpringBoot2.X填坑纪录
2019-06-05 16:01:48SpringBoot1.5.9使用了近两年,最近有个新项目,开始着手将框架升级为SpringBoot2.X。 坑1:SpringData JPA API变更 这点还好,因为做了基类封装,只需对将基类进行少许修改。这部分的新特性请参考官网或网上其他...
-
【数据分析-随到随学】Spark理论及实战
-
4.事务+利用pymysql更删改查+初始化
-
Python——web.py模块错误【UnicodeDecodeError: ‘gbk‘ codec can‘t decode byte 0xab in position 285】解决方案
-
关于MySQL数据库的管理及进阶用法,Level up!
-
UE4游戏逆向与安全+FPS游戏逆向与安全
-
Python如何设置指定窗口为前台活动窗口
-
day1_26
-
RhinoVault2_v1.1.6.exe
-
Appium自动化测试套餐
-
安畅星T3安卓导航语音助手你好魔方辅助程序
-
android笔试面试和实战课程
-
亿度云盘~Java小白入门实战
-
每日一题:第五题
-
自绘窗体 仿windows计算器calc 源代码
-
IDEA提交作业(gitee)
-
天津大学《编译原理》(07-11年)期末试卷真题(含答案).pdf
-
浙江大学《复变函数与积分变换》期末卷(含答案).pdf
-
All In One Toolbox Cleaner Speed Widget_vv8.1.6.1.3_apkpure.com.apk
-
ProBuilder快速原型开发技术
-
转行做IT-第9章 常用类-Scanner、Random等