2 Replies Latest reply on Nov 4, 2011 10:24 AM by pi4630

    EJB application properties loading - best practice

    pi4630

      Hi,

       

      what's the best practice to load application specific properties? For instance, in my SLSB I have a

       

      {code}@PostConstruct{code}

       

      section, where I'd like to load the properties from file. I know I shouldn't access file system: is it possible for some forum member to post some demo code how to do it with ClassLoader?

       

      thx,

      ~pasquale

        • 1. Re: EJB application properties loading - best practice
          wolfc

          You can do it via resource-env-ref entries instead. Those you can inject using @Resource. Either put the value in ejb-jar.xml or let it refer to a globally configured JNDI entry.

          1 of 1 people found this helpful
          • 2. Re: EJB application properties loading - best practice
            pi4630

            I did this (from the @PostConstruct event):

             

            {code}

            ResourceBundle rb = ResourceBundle.getBundle("it.bz.prov.mercurius.util.mercurius");

             

                    Properties p = new Properties();

             

                    for (Enumeration<String> e = rb.getKeys(); e.hasMoreElements();) {

                        String key = (String) e.nextElement();

                        String value = p.getProperty(key);

                        System.setProperty(key, value);

                    }

            {code}

            I shall try your suggestion, because the @Resource makes a lot more sense to me.

             

            thx