简体   繁体   中英

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.

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. 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:

   @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:

myapp/my.jndi.parameter.name

I'm open to suggestions to improve it :)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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