Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Is it possible to bind the BeanManager using the properties file? #35

Open
seekM opened this issue Jul 9, 2023 · 0 comments
Open

Is it possible to bind the BeanManager using the properties file? #35

seekM opened this issue Jul 9, 2023 · 0 comments

Comments

@seekM
Copy link

seekM commented Jul 9, 2023

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!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant