【问题标题】:Refreshing OSGI Bundle context, Unable to locate Spring NamespaceHandler刷新 OSGI Bundle 上下文,找不到 Spring NamespaceHandler
【发布时间】:2019-01-03 04:56:18
【问题描述】:

我需要在运行时刷新我的应用程序上下文。为此,我正在执行以下步骤:
1. 在我的 OSGI 包之外创建新的 application-context.xml
2. 将旧应用 ctx 复制到新应用中,使用
InputStream inputStream = new BufferedInputStream(this.getClass().getClassLoader().getResourceAsStream("/META-INF/spring/application-context.xml"));
3. 刷新app ctx,即切换到新的,在bundle外创建 ApplicationContext ctx = new FileSystemXmlApplicationContext(newCtxPath); ((ConfigurableApplicationContext)ctx).refresh();

但我得到了

找不到 XML 模式命名空间的 Spring NamespaceHandler [http://www.springframework.org/schema/data/mongo]

 http://www.springframework.org/schema/data/mongo

在我的 application-context.xml 中,我认为这不是问题,因为在编译期间,一切正常,当我在运行时尝试刷新 ctx 时会出现问题。

编辑# 当然,将旧的 ctx 文件复制到新文件是成功的,两个文件看起来完全一样。

【问题讨论】:

    标签: spring mongodb osgi applicationcontext


    【解决方案1】:

    我找到了更简单的解决方案。

    public class CtxRefresher implements ApplicationContextAware {
    
        private ApplicationContext context;
    
        public void refreshApplicationCtx(){
            ((ConfigurableApplicationContext)context).refresh();        
        }
    
        @Override
        public void setApplicationContext(ApplicationContext ctx) throws BeansException {
            context = ctx;      
        }
    }
    

    【讨论】:

      猜你喜欢
      • 2013-01-08
      • 2015-07-20
      • 2015-12-01
      • 1970-01-01
      • 2015-12-23
      • 2011-06-18
      • 2020-01-02
      • 2015-11-17
      • 1970-01-01
      相关资源
      最近更新 更多