第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機(jī)立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

我可以使用系統(tǒng)屬性設(shè)置 jetty 類加載語義嗎?

我可以使用系統(tǒng)屬性設(shè)置 jetty 類加載語義嗎?

哈士奇WWW 2023-08-16 10:02:32
在我們的項(xiàng)目中,我們僅使用Java API(沒有外部xml等)啟動嵌入式Jetty,然后向其部署war包?,F(xiàn)在我遇到一種情況,ClassCastException由于從實(shí)際類路徑加載的 jar 與實(shí)際類路徑中加載的 jar 不同,所以我得到了 s .war。閱讀關(guān)于類加載的 Jetty 頁面(https://www.eclipse.org/jetty/documentation/current/jetty-classloading.html)我想看看是否可以配置WebAppClassLoader以增強(qiáng)被視為“系統(tǒng)”的類集類。有一個 Java API 可以執(zhí)行此操作 ( WebAppContext.setServerClasses()),如果您使用的是 xml 配置文件,也有一種方法可以執(zhí)行此操作:<Configure class="org.eclipse.jetty.webapp.WebAppContext">  <Set name="serverClasses">foo.bar.,com.acme.</Set>  ...但我想知道是否可以僅使用 Java 系統(tǒng)屬性來完成此操作。
查看完整描述

1 回答

?
慕斯王

TA貢獻(xiàn)1864條經(jīng)驗(yàn) 獲得超2個贊

沒有系統(tǒng)屬性可用于在 WebAppContext 上配置服務(wù)器或系統(tǒng)類。

這是因?yàn)檫@種更改被認(rèn)為屬于特定的 WebApp,而不是所有 WebApp。

但是,您還有另一種選擇,如果您在嵌入式碼頭中使用DeploymentManager,那么您很幸運(yùn),您可以選擇代碼。

您需要創(chuàng)建一個自定義項(xiàng)AppLifeCycle.Binding,在任何已部署的項(xiàng)上設(shè)置這些屬性WebAppContext(我建議綁定到deploying)。

下面是一個強(qiáng)制 WebAppContext 始終使用服務(wù)器/系統(tǒng)類加載器中的日志庫的示例。

import org.eclipse.jetty.deploy.App;

import org.eclipse.jetty.deploy.AppLifeCycle;

import org.eclipse.jetty.deploy.graph.Node;

import org.eclipse.jetty.server.handler.ContextHandler;

import org.eclipse.jetty.webapp.WebAppContext;


public class CentralizedWebAppLoggingBinding implements AppLifeCycle.Binding

{

? ? public String[] getBindingTargets()

? ? {

? ? ? ? return new String[]

? ? ? ? { "deploying" };

? ? }


? ? public void processBinding(Node node, App app) throws Exception

? ? {

? ? ? ? ContextHandler handler = app.getContextHandler();

? ? ? ? if (handler == null)

? ? ? ? {

? ? ? ? ? ? throw new NullPointerException("No Handler created for App: " + app);

? ? ? ? }


? ? ? ? if (handler instanceof WebAppContext)

? ? ? ? {

? ? ? ? ? ? WebAppContext webapp = (WebAppContext)handler;

? ? ? ? ? ? webapp.addSystemClass("org.apache.log4j.");

? ? ? ? ? ? webapp.addSystemClass("org.slf4j.");

? ? ? ? ? ? webapp.addSystemClass("org.apache.commons.logging.");

? ? ? ? }

? ? }

}

這是一個從嵌入式碼頭使用 DeploymentManager 的示例(CentralizedWebAppLoggingBinding也包含上述內(nèi)容)。


ContextHandlerCollection contexts = new ContextHandlerCollection();


DeploymentManager deployer = new DeploymentManager();

if(debugIsEnabled)

{

? ? DebugListener debug = new DebugListener(System.err, true, true, true);

? ? server.addBean(debug);

? ? deployer.addLifeCycleBinding(new DebugListenerBinding(debug));

}

deployer.setContexts(contexts);

deployer.setContextAttribute(

? ? "org.eclipse.jetty.server.webapp.ContainerIncludeJarPattern",

? ? ".*/[^/]*servlet-api-[^/]*\\.jar$|.*/javax.servlet.jsp.jstl-.*\\.jar$|.*/[^/]*taglibs.*\\.jar$");


WebAppProvider webAppProvider = new WebAppProvider();

webAppProvider.setMonitoredDirName(jettyBase + "/webapps");

webAppProvider.setDefaultsDescriptor(jettyHome + "/etc/webdefault.xml");

webAppProvider.setScanInterval(1);

webAppProvider.setExtractWars(true);

webAppProvider.setConfigurationManager(new PropertiesConfigurationManager());

webAppProvider.addLifeCycleListener(new CentralizedWebAppLoggingBinding());


查看完整回答
反對 回復(fù) 2023-08-16
  • 1 回答
  • 0 關(guān)注
  • 125 瀏覽

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學(xué)習(xí)伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號