国产片侵犯亲女视频播放_亚洲精品二区_在线免费国产视频_欧美精品一区二区三区在线_少妇久久久_在线观看av不卡

服務器之家:專注于服務器技術及軟件下載分享
分類導航

PHP教程|ASP.NET教程|Java教程|ASP教程|編程技術|正則表達式|C/C++|IOS|C#|Swift|Android|VB|R語言|JavaScript|易語言|vb.net|

服務器之家 - 編程語言 - Java教程 - 詳解Spring Boot Oauth2緩存UserDetails到Ehcache

詳解Spring Boot Oauth2緩存UserDetails到Ehcache

2021-05-24 13:39五毛程序員 Java教程

這篇文章主要介紹了詳解Spring Boot Oauth2緩存UserDetails到Ehcache,小編覺得挺不錯的,現在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧

在spring中有一個類cachinguserdetailsservice實現了userdetailsservice接口,該類使用靜態代理模式為userdetailsservice提供緩存功能。該類源碼如下:

cachinguserdetailsservice.java

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
public class cachinguserdetailsservice implements userdetailsservice {
  private usercache usercache = new nullusercache();
  private final userdetailsservice delegate;
 
  cachinguserdetailsservice(userdetailsservice delegate) {
    this.delegate = delegate;
  }
 
  public usercache getusercache() {
    return this.usercache;
  }
 
  public void setusercache(usercache usercache) {
    this.usercache = usercache;
  }
 
  public userdetails loaduserbyusername(string username) {
    userdetails user = this.usercache.getuserfromcache(username);
    if (user == null) {
      user = this.delegate.loaduserbyusername(username);
    }
 
    assert.notnull(user, "userdetailsservice " + this.delegate + " returned null for username " + username + ". this is an interface contract violation");
    this.usercache.putuserincache(user);
    return user;
  }
}

cachinguserdetailsservice默認的usercache屬性值為new nullusercache(),該對象并未實現緩存。因為我打算使用ehcache來緩存userdetails,所以需要使用spring的ehcachebasedusercache類,該類是usercache接口的實現類,主要是緩存操作。

緩存userdetails到ehcache的具體實現如下:

ehcache.xml

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
<?xml version="1.0" encoding="utf-8"?>
<ehcache xmlns:xsi="http://www.w3.org/2001/xmlschema-instance"
     xsi:nonamespaceschemalocation="http://ehcache.org/ehcache.xsd">
  <!-- 磁盤緩存位置 -->
  <diskstore path="java.io.tmpdir" />
 
  <cache name="usercache"
      maxelementsinmemory="0"
      eternal="true"
      overflowtodisk="true"
      diskpersistent="true"
      memorystoreevictionpolicy="lru">
  </cache>
</ehcache>

userdetailscacheconfig.java

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
@slf4j
@configuration
public class userdetailscacheconfig {
  @autowired
  private customuserdetailsservice customuserdetailsservice;
 
  @bean
  public usercache usercache(){
    try {
      ehcachebasedusercache usercache = new ehcachebasedusercache();
      val cachemanager = cachemanager.getinstance();
      val cache = cachemanager.getcache("usercache");
      usercache.setcache(cache);
      return usercache;
    } catch (exception e) {
      e.printstacktrace();
      log.error(e.getmessage());
    }
    return null;
  }
 
  @bean
  public userdetailsservice userdetailsservice(){
    constructor<cachinguserdetailsservice> ctor = null;
    try {
      ctor = cachinguserdetailsservice.class.getdeclaredconstructor(userdetailsservice.class);
    } catch (nosuchmethodexception e) {
      e.printstacktrace();
    }
    assert.notnull(ctor, "cachinguserdetailsservice constructor is null");
    ctor.setaccessible(true);
 
    cachinguserdetailsservice cachinguserdetailsservice = beanutils.instantiateclass(ctor, customuserdetailsservice);
    cachinguserdetailsservice.setusercache(usercache());
    return cachinguserdetailsservice;
  }
}

使用

?
1
2
@autowired
private userdetailsservice userdetailsservice;

歡迎關注我的oauthserver項目,僅僅需要運行建表sql,修改數據庫的連接配置,即可得到一個spring boot oauth2 server微服務。項目地址 https://github.com/jeesun/oauthserver

以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支持服務器之家。

原文鏈接:http://www.cnblogs.com/rainmer/p/9417108.html

延伸 · 閱讀

精彩推薦
Weibo Article 1 Weibo Article 2 Weibo Article 3 Weibo Article 4 Weibo Article 5 Weibo Article 6 Weibo Article 7 Weibo Article 8 Weibo Article 9 Weibo Article 10 Weibo Article 11 Weibo Article 12 Weibo Article 13 Weibo Article 14 Weibo Article 15 Weibo Article 16 Weibo Article 17 Weibo Article 18 Weibo Article 19 Weibo Article 20 Weibo Article 21 Weibo Article 22 Weibo Article 23 Weibo Article 24 Weibo Article 25 Weibo Article 26 Weibo Article 27 Weibo Article 28 Weibo Article 29 Weibo Article 30 Weibo Article 31 Weibo Article 32 Weibo Article 33 Weibo Article 34 Weibo Article 35 Weibo Article 36 Weibo Article 37 Weibo Article 38 Weibo Article 39 Weibo Article 40
主站蜘蛛池模板: 91久久综合亚洲鲁鲁五月天 | 亚洲天天在线观看 | 久久都是精品 | 大胆裸体gogo毛片免费看 | 日韩精品在线免费观看 | 日韩福利视频 | 久久久久久久av | 亚洲va欧美va人人爽成人影院 | 亚洲精品一区 | 欧美在线综合 | 久久综合一区 | 直接看av的网站 | 亚洲一二三| 亚洲精品久久久久久一区二区 | 国外精品视频在线观看 | 爱爱网址 | 色视频网 | 51ⅴ精品国产91久久久久久 | 秋霞特色aa大片 | 亚洲国产激情 | 欧美成人免费在线观看 | 亚洲精品一区 | 日韩精品 | 国内精品视频一区 | 伊人一区二区三区 | 国产成人在线视频 | 久久久久久国产一级毛片高清版 | 亚洲天堂av影院 | 欧美黑人一级爽快片淫片高清 | 久久久久久免费毛片精品 | 欧美一区永久视频免费观看 | 亚洲视频在线观看免费 | 精品久久久久久久人人人人传媒 | 成人黄色在线观看 | 黄色成人影视 | 国产精品日本一区二区不卡视频 | 成人免费毛片在线观看 | 国产精品久久久久久久久久久久冷 | 久久这里有精品视频 | 中国黄色免费网站 | 免费黄网站在线观看 |