Environment properties

EJB 1.1 allows environment properties to be accessed using JNDI, and the EJBContext.getEnvironment method is now deprecated. Environment properties can also contain values of types other than String.

Environment properties used within a bean must be cataloged in the bean’s deployment descriptor. After deployment, you can edit the property values in the component properties—see Chapter 2, “Deploying and Configuring EJB Components.”

You must call the JNDI Context.lookup method to access environment properties. To locate the naming context, create a javax.naming.InitialContext object for java:comp/env. In this example, the application retrieves the value of the environment property maxExemptions and uses that value to determine an outcome:

Context initContext = new InitialCopntext();
Context myEnv = 
   (Context)initContext.lookup(“java:comp/env”);

// Get the maximum number of tax exemptions
Integer max=(Integer)myEnv.lookup(“maxExemptions”);

// Get the minimum number of tax exemptions 
Integer min = (Integer)myEnv.lookup(“minExemptions”);

// Use these properties to customize the business logic
if (numberOfExemptions > max.intValue() ||
   (numberOfExemptions < min.intValue())
    throw new InvalidNumberOfExemptionsException();

.