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

服務(wù)器之家:專(zhuān)注于服務(wù)器技術(shù)及軟件下載分享
分類(lèi)導(dǎo)航

PHP教程|ASP.NET教程|Java教程|ASP教程|編程技術(shù)|正則表達(dá)式|C/C++|IOS|C#|Swift|Android|VB|R語(yǔ)言|JavaScript|易語(yǔ)言|vb.net|

服務(wù)器之家 - 編程語(yǔ)言 - Java教程 - 深入Spring Boot實(shí)現(xiàn)對(duì)Fat Jar jsp的支持

深入Spring Boot實(shí)現(xiàn)對(duì)Fat Jar jsp的支持

2021-05-07 11:26hengyunabc Java教程

這篇文章主要介紹了深入Spring Boot實(shí)現(xiàn)對(duì)Fat Jar jsp的支持,小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧

spring boot 對(duì)于jsp支持的限制

對(duì)于jsp的支持,Spring Boot官方只支持了war的打包方式,不支持fat jar。參考官方文檔: https://docs.spring.io/spring-boot/docs/current/reference/html/boot-features-developing-web-applications.html#boot-features-jsp-limitations

這里spring boot官方說(shuō)是tomcat的問(wèn)題,實(shí)際上是spring boot自己改變了打包格式引起的。參考之前的文章:http://www.jfrwli.cn/article/161572.html

原來(lái)的結(jié)構(gòu)之下,tomcat是可以?huà)呙璧絝at jar里的meta-inf/resources目錄下面的資源的。在增加了boot-inf/classes之后,則tomcat掃描不到了。

那么怎么解決這個(gè)問(wèn)題呢?下面給出一種方案,來(lái)實(shí)現(xiàn)對(duì)spring boot fat jar/exploded directory的jsp的支持。

個(gè)性化配置tomcat,把boot-inf/classes 加入tomcat的resourceset

在tomcat里,所有掃描到的資源都會(huì)放到所謂的resourceset里。比如servlet 3規(guī)范里的應(yīng)用jar包的meta-inf/resources就是一個(gè)resourceset

現(xiàn)在需要想辦法把spring boot打出來(lái)的fat jar的boot-inf/classes目錄加到resourceset里。

下面通過(guò)實(shí)現(xiàn)tomcat的 lifecyclelistener接口,在lifecycle.configure_start_event事件里,獲取到boot-inf/classes的url,再把這個(gè)url加入到webresourceset里。

?
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
/**
 * add main class fat jar/exploded directory into tomcat resourceset.
 *
 * @author hengyunabc 2017-07-29
 *
 */
public class staticresourceconfigurer implements lifecyclelistener {
 
 private final context context;
 
 staticresourceconfigurer(context context) {
  this.context = context;
 }
 
 @override
 public void lifecycleevent(lifecycleevent event) {
  if (event.gettype().equals(lifecycle.configure_start_event)) {
   url location = this.getclass().getprotectiondomain().getcodesource().getlocation();
 
   if (resourceutils.isfileurl(location)) {
    // when run as exploded directory
    string rootfile = location.getfile();
    if (rootfile.endswith("/boot-inf/classes/")) {
     rootfile = rootfile.substring(0, rootfile.length() - "/boot-inf/classes/".length() + 1);
    }
    if (!new file(rootfile, "meta-inf" + file.separator + "resources").isdirectory()) {
     return;
    }
 
    try {
     location = new file(rootfile).touri().tourl();
    } catch (malformedurlexception e) {
     throw new illegalstateexception("can not add tomcat resources", e);
    }
   }
 
   string locationstr = location.tostring();
   if (locationstr.endswith("/boot-inf/classes!/")) {
    // when run as fat jar
    locationstr = locationstr.substring(0, locationstr.length() - "/boot-inf/classes!/".length() + 1);
    try {
     location = new url(locationstr);
    } catch (malformedurlexception e) {
     throw new illegalstateexception("can not add tomcat resources", e);
    }
   }
   this.context.getresources().createwebresourceset(resourcesettype.resource_jar, "/", location,
     "/meta-inf/resources");
 
  }
 }
}

為了讓spring boot embedded tomcat加載這個(gè) staticresourceconfigurer,還需要一個(gè)embeddedservletcontainercustomizer的配置:

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
@configuration
@conditionalonproperty(name = "tomcat.staticresourcecustomizer.enabled", matchifmissing = true)
public class tomcatconfiguration {
 @bean
 public embeddedservletcontainercustomizer staticresourcecustomizer() {
  return new embeddedservletcontainercustomizer() {
   @override
   public void customize(configurableembeddedservletcontainer container) {
    if (container instanceof tomcatembeddedservletcontainerfactory) {
     ((tomcatembeddedservletcontainerfactory) container)
       .addcontextcustomizers(new tomcatcontextcustomizer() {
        @override
        public void customize(context context) {
         context.addlifecyclelistener(new staticresourceconfigurer(context));
        }
       });
    }
   }
 
  };
 }
}

 這樣子的話(huà),spring boot就可以支持fat jar里的jsp資源了。

demo地址:https://github.com/hengyunabc/spring-boot-fat-jar-jsp-sample

總結(jié)

  1. spring boot改變了打包結(jié)構(gòu),導(dǎo)致tomcat沒(méi)有辦法掃描到fat jar里的/boot-inf/classes
  2. 通過(guò)一個(gè)staticresourceconfigurer把fat jar里的/boot-inf/classes加到tomcat的resourceset來(lái)解決問(wèn)題

以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持服務(wù)器之家。

原文鏈接:https://blog.csdn.net/hengyunabc/article/details/80341946

延伸 · 閱讀

精彩推薦
主站蜘蛛池模板: 波多野结衣一二三四区 | 欧洲一级毛片 | 久久网站热最新地址 | 久国产精品韩国三级视频 | 国内自拍视频网 | av一区二区三区 | 日本中文字幕在线电影 | 亚洲午夜av | 91精品久久久久久久久久 | 狠狠干狠狠操 | 一二三区视频 | 国产成人小视频 | 中文字幕在线观看精品视频 | 日韩精品一区二区在线观看 | 日本全黄裸体片 | 亚洲精品专区 | 国产第一区在线 | 天天色av | 亚洲国内精品 | 久久久久久久久久一区二区 | 欧美色影院 | 黄色一级在线观看 | www午夜| 国产精品福利在线观看 | 奇米av在线 | 秋霞av电影| 君岛美绪一区二区三区 | 成年女人在线观看 | 亚洲蜜桃精久久久久久久 | 影音先锋男人网 | 在线免费日韩 | 99在线精品视频 | 特黄特黄aaaa级毛片免费看 | 日韩av视屏| 日本特黄特色aaa大片免费 | 欧美日韩精品免费观看 | 婷婷天堂| 国产精品一区二区久久 | 中文字幕在线视频观看 | 日韩三级电影免费观看 | 国产精品欧美久久久久一区二区 |