cancel
Showing results for 
Search instead for 
Did you mean: 

Access Cloud Connector data from Spring Boot

Former Member
0 Kudos

I want to access data which has been served by the Cloud Connector and which is successfully connected to my Cloud Platform account. Now I want to access this data within a Spring Boot application and display the data on a web page.

But I get an error when I try to access the connectivityConfiguration resource:

javax.naming.NamingException: Cannot create resource instance

In Spring Boot I have no web.xml, so I try to do it this way:

@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);
        }
    };
}

When I access the InitialContext, I see the connectivityConfiguration key in the list of resources, but when I try to access it like that:

Context context = new InitialContext();
Object conObj = context.lookup("java:comp/env/connectivityConfiguration");
ConnectivityConfiguration configuration = (ConnectivityConfiguration) conObj;

.. I get the exception I mentioned above.


Any idea?

Accepted Solutions (0)

Answers (2)

Answers (2)

I also have similar requirement but without springboot.

I have a web.xml filebut still I am facing same set of isues.

Regards

Shirjan

0 Kudos

I have the same issue (also without spring-boot, just spring framework). Any news on that?

0 Kudos

I have two applications deployed and I missed the resource-ref entry in the web.xml of one of the web applications, but I needed it in both. So it wasn't related to spring at all.

Hope that helps someone.

detrapto
Explorer
0 Kudos

Since you do not use the embedded Tomcat on SAP CP, you won't need the TomcatEmbeddedServletContainerFactory stuff.

I provided a context.xml including a <Resource> tag for the ConnectivityConfiguration and placed that file in "src/main/webapp/META-INF". Don't use "src/main/resources/..." also it is suggested for Spring Boot. Then you'll be able to lookup the JNDI resource...