Page 1 of 1
About Question enthuware.oce-ejbd.v6.2.555 :
Posted: Sat May 09, 2015 9:13 pm
by himaiMinh
What happens if loading the data involves the using of resource managers, such as QueueConnectionFactory?
In stateless bean, accessing the resource managers are not allowed in @PostConstruct method.
Re: About Question enthuware.oce-ejbd.v6.2.555 :
Posted: Sat May 09, 2015 9:36 pm
by admin
The question explicitly says web service. But as you said you can't use resource managers in @PostContruct.
Re: About Question enthuware.oce-ejbd.v6.2.555 :
Posted: Sun May 10, 2015 5:57 pm
by himaiMinh
Hi, admin.
Thanks for your previous reply.
In explanation 1,
Bean environment is not set in the constructor. Therefore, the bean will not be able to get the connection parameters in the constructor.
But I can do this:
Suppose the LoadDataBean is packaged in a .war file with some other beans. The bean environment is shared among other beans in the .war file.
Code: Select all
@Stateless
public class LoadDataBean{
private String connectionDetail;
public LoadDataBean(){
try{
InitalContext context = new InitialContext();
//Suppose there is an environment variable connectionDetail set by other beans in the same .war
String detail= context.lookup("java:comp/env/connectionDetail");
connectionDetail = loadData(detail); //where loadData connects to a web service which gets the configuration in the bean's environment.
}
catch (NamingException e ) {....}
}
}
Re: About Question enthuware.oce-ejbd.v6.2.555 :
Posted: Sun May 10, 2015 7:48 pm
by admin
The container may prohibit the bean from using InitialContext itself in the constructor. So what you are saying may or may not work. Regardless, it is not as per the specification.