Simple-JNDI
Simple-JNDI copied to clipboard
Is it possible to bind the BeanManager using the properties file?
Hello!
At the moment my project looks like this:
<dependencies>
<dependency>
<groupId>com.github.h-thurow</groupId>
<artifactId>simple-jndi</artifactId>
<version>0.23.0</version>
</dependency>
<dependency>
<groupId>org.jboss.weld.se</groupId>
<artifactId>weld-se-core</artifactId>
<version>3.1.5.Final</version>
</dependency>
<dependency>
<groupId>javax.enterprise</groupId>
<artifactId>cdi-api</artifactId>
<version>1.2</version>
</dependency>
</dependencies>
java.naming.factory.initial = org.osjava.sj.SimpleContextFactory
org.osjava.sj.jndi.shared = true
org.osjava.sj.root = config
@ApplicationScoped
public class Main
{
@Inject
private BeanManager beanManager;
public void init(@Observes ContainerInitialized event) throws NamingException
{
InitialContext ic = new InitialContext();
ic.bind("java:comp/env/BeanManager", beanManager);
BeanManager beanManager = (BeanManager) ic.lookup("java:comp/env/BeanManager");
System.out.println(beanManager.toString());
}
}
And it works as expected.
Now, instead of binding the beanManager in the Main class with ic.bind("java:comp/env/BeanManager", beanManager); I would like to do that in an according properties file. Is this possible? I found the examples for DataSources objects and the other Java types, but I'm a bit at loss at the moment. This is what I tried:
Using the following jndi.properties:
java.naming.factory.initial = org.osjava.sj.SimpleContextFactory
org.osjava.sj.jndi.shared = true
org.osjava.sj.root = config
org.osjava.sj.space = java:comp/env
org.osjava.sj.delimiter=/
Should the env.properties file be created unter the config or under the config/java/comp folder?
What should the env.properties file look like?
BeanManager=? // I'm not sure how to get the injected object from above here - do I have to search for some kind of factory method within the weld library which I can state here?
BeanManager/type=javax.enterprise.inject.spi.BeanManager // If I understand correctly this is not supported
It would be great if you could give me some hints!