简体   繁体   English

GlassFish中不同独立实例的JNDI参数值不同

[英]Different value of JNDI parameter for different standalone instances in GlassFish

I need to have the same application deployed in GlassFish several times, with different JNDI parameters, but I can't find a way to do that. 我需要使用不同的JNDI参数多次在GlassFish中部署相同的应用程序,但我找不到这样做的方法。

I know I can have different standalone instances and apply the different JNDI resources to one or several instances, but I can't have the same resource name with different values for the different instances. 我知道我可以拥有不同的独立实例,并将不同的JNDI资源应用于一个或多个实例,但是我不能为不同的实例使用不同的值具有相同的资源名称。 What is the way to achieve what I need? 实现我需要的方法是什么?

要实现此要求,可以在属性文件中使用不同的JNDI配置,并传递JVM参数中的值,以将每个配置应用于多个glassfish服务器实例。

So in the end what I did is to use this: 所以最后我做的是用这个:

   @Resource(lookup = "java:app/AppName")
   private String appName;

   private String myJndiParameter;

And then since I can't use a variable to get the custom jndi parameter in an annotation, I created a @PostConstruct method, where I get the jndi value that I want, something like this: 然后因为我不能使用变量来获取注释中的自定义jndi参数,所以我创建了一个@PostConstruct方法,在那里我得到了我想要的jndi值,如下所示:

   @PostConstruct
   public void initialize ()
   {
      try
      {
         myJndiParameter = (String) new javax.naming.InitialContext().lookup(appName + "/" + "my.jndi.parameter.name");
      } catch (NamingException e)
      {
         // Treat exception
      }
   }

In GlassFish, my custom resource name looks like: 在GlassFish中,我的自定义资源名称如下所示:

myapp/my.jndi.parameter.name

I'm open to suggestions to improve it :) 我愿意接受改进建议:)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM