Environment:
GlassFish Server Open Source Edition 4.1
disable-nonportable-jndi-names: true
The problem:
When I Deploy or Redeploy my application - everything works ok. But after Reload or Disable/Enable following exception arises during connection from a standalone client:
Exception in thread "main" javax.naming.NamingException: Lookup failed for 'java:global/SynisBackendEAR/SynisBackend/UnitronicsDriver'...
...
Caused by: javax.naming.NameNotFoundException: UnitronicsDriver not found...
...
Caused by: java.lang.IllegalStateException: Exception attempting to inject Local ejb-ref name=com.protechnologia.synis.drivers.unitronics.UnitronicsDriver/configurationProvider,Local 3.x interface =com.protechnologia.synis.settings.ConfigurationProvider,ejb-link=null,lookup=java:app/SynisBackend/ConfigurationProviderXML,mappedName=,jndi-name=,refType=Session into class com.protechnologia.synis.drivers.unitronics.UnitronicsDriver: object is not an instance of declaring class
...
The code of a standalone client:
InitialContext ctx = new InitialContext();
Driver bean = (Driver) ctx.lookup("java:global/SynisBackendEAR/SynisBackend/UnitronicsDriver");
bean.test();
I want to mention, that after Deployment or Redeployment everything works ok.
The clue:
I've found taht the problem is in following lookup taht is working on Deplyment and not working otherwise:
@Singleton
@Startup
public class UnitronicsDriver implements Driver {
@EJB(lookup = "java:app/SynisBackend/ConfigurationProviderXML")
protected ConfigurationProvider conf;
Next clue:
Replacing @EJB with manual lookup solves the problem but why?
conf = (ConfigurationProvider) ctx.lookup("java:app/SynisBackend/ConfigurationProviderXML");