views:

40

answers:

1

Hi,

I'm trying to load bean runtime configuration.

@Stateless
public class MyBean implements MyLocal{    
   @Resource String runtimeSetting1="default_value";
   //....
}

I cannot find out how to create custom resource on app server side (Glassfish) - I have no idea what I should enter in "Factory Class" field. Maybe there is a better way of loading configuration...

Thanks.

+1  A: 

To my knowledge, the standard way in Java EE is to declare env-entry for configuration data. This applies to all Java EE components like EJB 3 bean class, servlet, filters, interceptors, listener classes, etc. Here, declare something like this in your ejb-jar.xml:

<?xml version="1.0" encoding="UTF-8"?>
<ejb-jar xmlns="http://java.sun.com/xml/ns/javaee" 
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="3.0"
  xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/ejb-jar_3_0.xsd"&gt; 
  <enterprise-beans>
    <session>
      <ejb-name>FooBean</ejb-name>
      <env-entry>
        <description>foobar entry</description>
        <env-entry-name>foo</env-entry-name>
        <env-entry-type>java.lang.String</env-entry-type>
        <env-entry-value>bar</env-entry-value>
      </env-entry>
      ...
    </session>
    ...
  </enterprise-beans>
  ....
</ejb-jar>

Then look up the env-entry with JNDI or inject it by its name. For example, to inject it in your bean:

@Resource(name="foo")
private String myProperty; 
Pascal Thivent