使用类加载器从接口中隔离jndi资源实现

时间:2019-01-18 16:16:44

标签: java tomcat classloader jndi

我有应用程序 myapp.war ,该应用程序根据来自tomcat的JNDI资源获得JMS连接。 Jms实现是activemq-client。但是 activemq-client 需要 slf4j 。我将activemq-client,slf4j和其他依赖项库放入${TOMCAT_HOME}/lib/ext

但是 myapp.war 与该slf4j版本不兼容。而且activemq-client与 myapp.war 中的slf4j版本不兼容。

我认为:

  • basic jms-intrefaces jars放入${TOMCAT_HOME}/lib/ext
  • activeqm-client 及其依赖项放入another/directiory
  • 创建自定义JNDI工厂以创建jms实现实例
  • 在此JNDI工厂中的类路径为another/directiory新Classloader 中隔离创建jms实现实例
  • 将结果返回到 myapp.war

即这个类加载器的层次结构看起来像:

         Bootstrap
             |
          System
             |                
    ---------------------         
   |      Common         |
   |                     |    pass connection parameters     --------------------------------------
   |  my-jndi-factory <--|--------------------------------->| Isolated class loader with classpath |
    ---------------------     return ConnectionFactory      | `another/directiory`                 |
         /      \                                            --------------------------------------
        /        \                
    myapp.war  otherApp.war 

我的问题:

  • 是否有任何具有此功能的库?
  • 这种方法有哪些弊端和陷阱?

0 个答案:

没有答案
相关问题