gpt4 book ai didi

tomcat - 将设置 : in context. xml 从 Tomcat 9 迁移到 Wildfly 14.0.1 Final

转载 作者:行者123 更新时间:2023-11-28 22:47:32 26 4
gpt4 key购买 nike

如何将一些配置从 Tomcat 应用程序服务器的 context.xml 移动到 Wildfly?我真的需要来自环境元素的数据。

context.xml 包含如下内容:

<Context>

<WatchedResource>WEB-INF/web.xml</WatchedResource>
<WatchedResource>WEB-INF/tomcat-web.xml</WatchedResource>
<WatchedResource>${catalina.base}/conf/web.xml</WatchedResource>


<Environment name="some.very.important.config.path" value="C:\path\to\the\config\folder"

type="java.lang.String" />


</Context>

我如何在 Wildfly 应用服务器中实现这一点?

更新:

我必须使用 JNDI(目前),因为它是一个由其他人编写的应用程序。

到达可注入(inject)配置路径的代码看起来像这样。

        env = (Context) new InitialContext().lookup("java:comp/env");
configPath = (String) env.lookup("some.very.important.config.path");

最佳答案

  • <WatchedResource>WEB-INF/web.xml</WatchedResource>
    默认情况下,WildFly 会监视此文件中的更改

  • <WatchedResource>WEB-INF/tomcat-web.xml</WatchedResource>
    在 WildFly 中不相关。 WEB-INF/jboss-web.xml文件用于类似目的,也默认观看

  • <WatchedResource>${catalina.base}/conf/web.xml</WatchedResource>
    与 WildFly 无关

  • <Environment name="some.very.important.config.path" value="C:\path\to\the\config\folder" type="java.lang.String" />
    编写一个名为(例如)configure-wildfly.cli 的文本文件具有以下内容

    # Execute offline
    embed-server --server-config=standalone.xml

    # Add system properties
    /system-property=some.very.important.config.path:add(value=C:\path\to\the\config\folder)
    /system-property=some.other.important.config.value:add(value=foobar)

    # Bind an entry into the naming service
    /subsystem=naming/binding=java\:global\/config\/important\/path:add(binding-type=simple, type=java.lang.String, value="C:\path\to\the\config\folder")

    stop-embedded-server

    然后运行它:

    ${WILDFLY_HOME}/bin/jboss-cli.sh --file=configure-wildfly.cli

    像这样编写脚本可以很容易地从它的基本设置重建你的服务器。如果需要,您可以对该文件进行源代码控制。

访问系统属性:

 String configPath = System.getProperty("some.very.important.config.path");

在JNDI中查找值:

 Context ctx = new InitialContext();
String configPath = (String)ctx.lookup("java:global/config/important/path");

或者注入(inject)它

 @Resource(lookup="java:global/config/important/path")
private String configPath;

关于tomcat - 将设置 : in context. xml 从 Tomcat 9 迁移到 Wildfly 14.0.1 Final,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53546261/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com