2

Using spring-boot I want to access a resource that is used to be in the web.xml but due to the fact I'm using spring-boot I tried to add it this way:

Application.java

@Bean
public TomcatEmbeddedServletContainerFactory tomcatFactory() {
    return new TomcatEmbeddedServletContainerFactory() {

        @Override
        protected TomcatEmbeddedServletContainer getTomcatEmbeddedServletContainer(Tomcat tomcat) {
            tomcat.enableNaming();
            return super.getTomcatEmbeddedServletContainer(tomcat);
        }

        @Override
        protected void postProcessContext(Context context) {
            ContextResource resource = new ContextResource();
            resource.setName("connectivityConfiguration");
            resource.setType(com.sap.core.connectivity.api.configuration.ConnectivityConfiguration.class.getName());

            context.getNamingResources().addResource(resource);
        }
    };
}

In my Service I want to access this resource with:

Context context = new InitialContext();

Object conObj = context.lookup("java:comp/env/connectivityConfiguration");

ConnectivityConfiguration configuration = (ConnectivityConfiguration) conObj;

But this does not work, I get an exception:

javax.naming.NamingException: Cannot create resource instance

When I look at the list content:

NamingEnumeration<NameClassPair> list = context.list("java:comp/env");

I see the first iterator node has the key "connectivityConfiguration".

What am I doing wrong, why can't I access it?

Zumarta
  • 145
  • 3
  • 18

0 Answers0