Simple-JNDI icon indicating copy to clipboard operation
Simple-JNDI copied to clipboard

Programmatical population of JNDI

Open HiranChaudhuri opened this issue 1 year ago • 4 comments

Since I wanted to create complex objects (DataSource) based on system properties (JDBC-URL, user, password with default values in case they are missing) I decided to populate SimpleJNDI programmatically, using this code:

    DataSource ds = new MyDataSource();

    InitialContext ictx = new InitialContext();
    Context ctx = ictx.createSubcontext("jdbc");
    ctx.bind("ds1", ds);
  
    ctx = ctx.createSubcontext("NonJTA");
    ctx.bind("ds2", ds);

On top of that I added Simple-JNDI to my test classpath and told Maven-Surefire to set the system property like so:

    <dependency>
        <groupId>com.github.h-thurow</groupId>
        <artifactId>simple-jndi</artifactId>
        <version>0.23.0</version>
        <scope>test</scope>
    </dependency>
        ...
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-surefire-plugin</artifactId>
            <version>3.1.0</version>
            <configuration>
                <systemPropertyVariables>
                    <java.naming.factory.initial>org.osjava.sj.SimpleContextFactory</java.naming.factory.initial>
                </systemPropertyVariables>
            </configuration>
        </plugin>

When running the application, I do get a warning message that no root is provided:

    WARN  org.osjava.sj.SimpleJndi - Mistakenly no root provided?

What should be provided, and why?

HiranChaudhuri avatar May 09 '23 15:05 HiranChaudhuri

It is a warning only. So everything should be fine. Just ignore it.

h-thurow avatar May 09 '23 15:05 h-thurow

It if is meant to be ignored, it would not have to pop up as warning. So what does it mean actually? What is Simple-JNDI trying to tell me?

HiranChaudhuri avatar May 09 '23 19:05 HiranChaudhuri

Read this section: https://github.com/h-thurow/Simple-JNDI#setting-up-simple-jndi

h-thurow avatar May 09 '23 21:05 h-thurow

I understand I was missing a required parameter. If that one is required, the error is corredt but stating to ignore it is a bit weird then. If it is an optional, recommended parameter the message could have been a warning or informational only.

So is it a required, recommended or optional parameter? Something is out of sync, and I am just letting you know.

HiranChaudhuri avatar May 19 '23 09:05 HiranChaudhuri