【问题标题】:Discover Plugin-JARS in Classpath in Spring在 Spring 的 Classpath 中发现 Plugin-JARS
【发布时间】:2011-07-20 07:53:25
【问题描述】:

有没有办法在 Spring 中发现一个 来自类路径的“插件”-JAR, 并动态加载它的applicationContext.xml?

【问题讨论】:

    标签: java spring classpath


    【解决方案1】:

    我通过以下方法使用 Spring 实现了类似插件的系统:

    • 每个插件都必须包含一个带有特定名称和包前缀的 spring-context 文件(例如,com.example.myApp.whatever 包含 plugin.xml 或 applicationContext.xml,如果您愿意)。

    • 对于要在类路径中检测到的插件,宿主应用程序应该按照 previos 方案动态导入任何 jar 贡献的所有上下文文件。这是通过 spring 配置中基于通配符的导入来实现的:

       <import resource="classpath*:/com/example/myApp/**/plugin.xml" />
      
    • 前提是每个插件都定义了已知接口的 bean(例如,MyInterface)。宿主应用程序可以定义 List 类型的属性并将 bean 定义为 autowire="byType" 以便在列表中检索 MyInterfaceType 的所有 bean。

    【讨论】:

      猜你喜欢
      • 2012-06-11
      • 2013-08-14
      • 2011-06-18
      • 2017-07-05
      • 1970-01-01
      • 1970-01-01
      • 2015-08-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多