Skip to Content
0

Access Cloud Connector data from Spring Boot

Apr 13, 2017 at 11:41 AM

241

avatar image
Former Member

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?

10 |10000 characters needed characters left characters exceeded
* Please Login or Register to Answer, Follow or Comment.

2 Answers

avatar image
Former Member
May 08, 2017 at 08:43 AM
1

I also have similar requirement but without springboot.

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

Regards

Shirjan

Show 2 Share
10 |10000 characters needed characters left characters exceeded

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

0

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.

0
Tobias Trapp Jun 02, 2017 at 07:53 PM
0

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...

Share
10 |10000 characters needed characters left characters exceeded