Page 1 of 1

About Question com.enthuware.ets.scbcd.v5.2.34 : what will happen to when the dependecy injectionfails

Posted: Sun Jan 02, 2011 12:42 am
by ETS User
Consider the following stateless session bean code:

@Stateless
public class TellerBean implements
com.enthu.ejbplus.TellerRemote{

@Resource
SessionContext sctx;

@Resource(name="location")
String loc = "default";
public double getBalance(int acctid) throws NoAccountException{

try {
Context ic = new InitialContext();
loc = (String) ic.lookup("java:comp/env/location");
System.out.println(loc);
} catch (Exception ex) {
System.out.println("Exception in looking up = " +ex);
}
System.out.println(loc);
return 2.0;
}
}

This bean is deployed without any deployment descriptor.

the given answer is "default" will be printed.


My question is what will happen in the dependency Injection fails in @Resource(name="location")
?

Re: About Question com.enthuware.ets.scbcd.v5.2.34 : what will happen to when the dependecy injectionfails

Posted: Thu Feb 24, 2011 6:53 am
by admin
If the dependency injects fails, depending on the application server, either the application will fail to deploy or that particular component will not be available.

Re: About Question com.enthuware.ets.scbcd.v5.2.34 : what will happen to when the dependecy injectionfails

Posted: Wed Jan 23, 2013 7:28 pm
by Guest
Actually, the correct answer should be: "Exception in looking up = (stack trace) and after that 'default' will be printed."

Such as it is, the supposedly correct answer is misleading.

Re: About Question com.enthuware.ets.scbcd.v5.2.34 : what will happen to when the dependecy injectionfails

Posted: Wed Jan 23, 2013 7:34 pm
by admin
It is possible for a question to not specify all the output. If an option does not claim that it is showing all the output, it may specify partial output.
Yes, it could be termed misleading but the actual exam may also have such answers.

HTH,
Paul.