• Post Reply Bookmark Topic Watch Topic
  • New Topic

[CDI] Inject a DataSource based on a Runtime JNDI name variable

 
Gerb Stralko
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Not sure if the title makes sense. But I need to inject a DataSource, but the catch is the JNDI isn't known until Runtime. I was hoping the EJB could get a System Property of the JNDI name and use that to Inject the DataSource.

For example:

@Resource(name=myRuntimeJNDIName)
DataSource myDataSource;

And I could either @Inject or on postContstruct() set the myRuntimeJNDI variable to the JNDI name that is configured on the App Server via System Properties or some other mechanism. But the JNDI may be different depending on what environment the application is deployed to.

Is this possible? I would like to have the same EAR deployed in all our environments and not have to create a different version of the application for each environment.

Thanks,

Gerb
 
Gerb Stralko
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm trying to inject the String variable using a Producer method but the variables is always null.



InjectableDataSource is:



Is this the correct way to inject a string variable at runtime?

Thanks,
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!