如何在springboot嵌入式tomcat上配置CICS适配器

时间:2019-05-22 10:48:00

标签: spring-boot tomcat cics

此刻,我正在尝试将springboot应用程序连接到cics资源,但是我在配置方面遇到了问题

我正在使用spring-boot 2.1.3.RELEASE,该版本与嵌入式tomcat版本9.x.x一起运行

我已在tomcat上启用了名称解析,并尝试使用application.properties将cics适配器配置为数据源,但没有执行任何操作。

我能够使用postProcessContext方法配置jndi名称,但是我无法创建连接实例。

我尝试在web.xml上配置连接器,但没有区别。

应用程序类:

@SpringBootApplication
public class Application {
    public static void main(String[] args) {
        SpringApplication.run(Application.class, args);
    }

    @Bean
    public TomcatServletWebServerFactory tomcatFactory() {
        return new TomcatServletWebServerFactory() {
            @Override
            protected TomcatWebServer getTomcatWebServer(org.apache.catalina.startup.Tomcat tomcat) {
                tomcat.enableNaming();
                return super.getTomcatWebServer(tomcat);
            }

            @Override
            protected void postProcessContext(Context context) {
                ContextResource resource = new ContextResource();           
                resource.setName("j2c/CICS");
                resource.setType(ConnectionFactory.class.getName());
                resource.setProperty("url", "[HOST]:[PORT]");
                resource.setProperty("username", "*****");
                resource.setProperty("password", "*****");
                context.getNamingResources().addResource(resource);
            }
        };
    }
}

试图获得连接的代码片段:

InitialContext ctx = new InitialContext();
Context envCtx = (Context) ctx.lookup("java:comp/env/");
ConnectionFactory cnf = (javax.resource.cci.ConnectionFactory) envCtx.lookup("j2c/CICS");   

目前无法与cics连接,尝试查找资源时出现此错误:

javax.naming.NamingException: Cannot create resource instance
    at org.apache.naming.factory.FactoryBase.getObjectInstance(FactoryBase.java:96) ~[tomcat-embed-core-9.0.16.jar:9.0.16]
    at javax.naming.spi.NamingManager.getObjectInstance(NamingManager.java:321) ~[na:1.8.0_212]
    at org.apache.naming.NamingContext.lookup(NamingContext.java:840) ~[tomcat-embed-core-9.0.16.jar:9.0.16]
    at org.apache.naming.NamingContext.lookup(NamingContext.java:159) ~[tomcat-embed-core-9.0.16.jar:9.0.16]
    at org.apache.naming.NamingContext.lookup(NamingContext.java:827) ~[tomcat-embed-core-9.0.16.jar:9.0.16]
    at org.apache.naming.NamingContext.lookup(NamingContext.java:173) ~[tomcat-embed-core-9.0.16.jar:9.0.16]
...

0 个答案:

没有答案
相关问题