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

Moderator: admin

Post Reply
ETS User

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

Post 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")
?

admin
Site Admin
Posts: 10384
Joined: Fri Sep 10, 2010 9:26 pm
Contact:

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

Post 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.

Guest

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

Post 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.

admin
Site Admin
Posts: 10384
Joined: Fri Sep 10, 2010 9:26 pm
Contact:

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

Post 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.

Post Reply

Who is online

Users browsing this forum: No registered users and 13 guests