What is JNDI? What is its basic use? When is it used?

What is JNDI ? It stands for Java Naming and Directory Interface. What is its basic use? JNDI allows distributed applications to look up services in an abstract, resource-independent way. When it is used? The most common use case is to set up a database connection pool on a Java EE application server. Any application … Read more

How to create JNDI context in Spring Boot with Embedded Tomcat Container

By default, JNDI is disabled in embedded Tomcat which is causing the NoInitialContextException. You need to call Tomcat.enableNaming() to enable it. The easiest way to do that is with a TomcatEmbeddedServletContainer subclass: @Bean public TomcatEmbeddedServletContainerFactory tomcatFactory() { return new TomcatEmbeddedServletContainerFactory() { @Override protected TomcatEmbeddedServletContainer getTomcatEmbeddedServletContainer( Tomcat tomcat) { tomcat.enableNaming(); return super.getTomcatEmbeddedServletContainer(tomcat); } }; } If … Read more