我正在谷歌搜索,但在查找要转换的字符串以在接下来的两行中传递给config.getServletContext()。getAttribute()方法时遇到了困难。这些行来自部署在WAS 8.5上的应用程序。
String applicationName = (String)config.getServletContext().getAttribute("com.ibm.websphere.servlet.enterprise.application.name");
String serverName = (String)config.getServletContext().getAttribute("com.ibm.websphere.servlet.application.host");
我正在研究/研究WAS Liberty。
也许对于自由的所有可能属性的引用的链接可能会更好(如果存在...)
在JavaEE应用程序中获取应用程序名称的简单/标准方法是使用此内置的JNDI名称:
import javax.naming.InitialContext;
// ...
String appName = InitialContext.doLookup("java:app/AppName");
要获取主机名,您可以为此使用JavaSE API:
InetAddress.getLocalHost().getHostName()
您还可以在server.xml中定义和查找任意变量,然后使用MicroProfile config进行查找,如下所示:
@Inject
@ConfigProperty(name = "foo", defaultValue = "bar")
String fooProperty;
此外,这是MicroProfile Config for Liberty的指南:https://openliberty.io/guides/microprofile-config-intro.html