About Question enthuware.oce-ejbd.v6.2.380 :
Posted: Thu Apr 21, 2011 5:11 am
Typo:
onsider --> Consider
onsider --> Consider
Java Certification Resources and Java Discussion Forum
http://enthuware.com/forum/
inside statful localbean, test() called from a servletAn <env-entry> needs to be defined in the ejb-jar.xml for this bean but it should not contain <env-entry-value> element.
Code: Select all
@Resource(name="none")
private String s = "default";
public void test() {
System.out.println(s);
}
The specification gives an example further:The Bean Provider must declare all the simple environment entries accessed from the enterprise bean’s code.
HTH,It is often convenient to declare a field as an injection target, but to specify a default value in the code, as illustrated in the following example.
// The maximum number of tax exemptions, configured by the Deployer.
@Resource int maxExemptions = 4; // defaults to 4
To support this case, the container must only inject a value for the environment entry if the application assembler or deployer has specified a value to override the default value. The env-entry-valueelement in the deployment descriptor is optional when an injection target is specified. If the element is not specified, no value will be injected.
Code: Select all
package com.test;
import javax.annotation.Resource;
import javax.ejb.Stateless;
import javax.ejb.LocalBean;
@Stateless
@LocalBean
public class EnvTest
{
@Resource(name="ds_value")
private String ds = "HARDCODED";
public void saveData(){
System.out.println(ds);
}
}
What do you think about this?The env-entry-value element in the deployment descriptor is optional when an injection target is specified. If the element is not specified, no value will be injected. In addition, if the element is not specified, the named resource is not initialized in the naming context, and explicit lookups of the named resource will fail.
Not sure why deployment is failing on Glassfish without this entry.The Bean Provider must declare all the simple environment entries accessed from the enterprise bean’s code. The simple environment entries are declared either using annotations in the bean class code or using the env-entry elements in the deployment descriptor.
Cheers!13:06:14,802 INFO [org.jboss.as.server.deployment] (MSC service thread 1-6) Starting deployment of "EnvTest.jar"
13:06:14,819 INFO [org.jboss.as.ejb3.deployment.processors.EjbJndiBindingsDeploymentUnitProcessor] (MSC service thread 1-8) JNDI bindings for session bean named EnvTest in deployment unit deployment "EnvTest.jar" are as follows:
java:global/EnvTest/EnvTest!com.test.EnvTest
java:app/EnvTest/EnvTest!com.test.EnvTest
java:module/EnvTest!com.test.EnvTest
java:global/EnvTest/EnvTest
java:app/EnvTest/EnvTest
java:module/EnvTest
13:06:14,884 INFO [stdout] (MSC service thread 1-2) HARDCODED
13:06:14,891 INFO [org.jboss.as.server.controller] (HttpManagementService-threads - 4) Deployed "EnvTest.jar"
Maybe better make two separate questions with JNDI and without?Guest wrote:"Nothing is required. No <env-entry> needs to be defined in ejb-jar.xml for this bean."
and therefore is answer
"An <env-entry> needs to be defined in the ejb-jar.xml for this bean if the value is to be accessed using JNDI but it should not contain <env-entry-value> element."
wrong.
Hello,Guest wrote:"Nothing is required. No <env-entry> needs to be defined in ejb-jar.xml for this bean."
and therefore is answer
"An <env-entry> needs to be defined in the ejb-jar.xml for this bean if the value is to be accessed using JNDI but it should not contain <env-entry-value> element."
wrong.
Therefore, any JNDI lookup will fail. How can "An <env-entry> needs to be defined in the ejb-jar.xml for this bean if the value is to be accessed using JNDI but it should not contain <env-entry-value> element." answer be correct?The env-entry-value element in the deployment descriptor is optional when an injection target is specified. If the element is not specified, no value will be injected. In addition, if the element is not specified, the named resource is not initialized in the naming context, and explicit lookups of the named resource will fail.