【问题标题】:Error beanFactory/ApplicationContext - JAVA错误 beanFactory/ApplicationContext - JAVA
【发布时间】:2015-11-21 21:07:02
【问题描述】:

我正在关注tutorial 以使用 JAVA 在 Alfresco 上操作 nodeRef 和内容。但是当我尝试定义serviceRegistry时,

 ServiceRegistry serviceRegistry = (ServiceRegistry) beanFactory.getBean(ServiceRegistry.SERVICE_REGISTRY);
   

beanFactory 未初始化。而且我已经尝试了很多声明,但我无法正确初始化/声明它。谁能帮帮我?

我试试:

ApplicationContext appContext = new ClassPathXmlApplicationContext("alfresco/web-client-application-context.xml");

ServiceRegistry serviceRegistry = (ServiceRegistry) appContext.getBean(ServiceRegistry.SERVICE_REGISTRY);

web-client-application-context.xmlhttps://github.com/Alfresco/community-edition/blob/master/projects/web-client/config/alfresco/web-client-application-context.xml

错误:

org.springframework.beans.factory.BeanCreationException: 错误 创建类中定义的名称为“GlobalAuthenticationFilter”的bean 路径资源 [alfresco/web-client-application-context.xml]:不能 在设置 bean 属性时解析对 bean 'Authentication' 的引用 '应用程序上下文管理器';嵌套异常是 org.springframework.beans.factory.NoSuchBeanDefinitionException: 否 定义了名为 'Authentication' 的 bean

另一种方式?我该如何解决这个问题?

【问题讨论】:

  • This page 建议您应该使用 alfresco/application-context.xml 作为应用上下文配置,或者更好的是,使用 Spring 依赖注入来获取所有必需的服务 bean。

标签: java spring spring-mvc javabeans alfresco


【解决方案1】:

我解决了这个问题:ServiceRegistry serviceRegistry = (ServiceRegistry) beanFactory.getBean(ServiceRegistry.SERVICE_REGISTRY);

为此:

protected ServiceRegistry getServiceRegistry() {
        ProcessEngineConfigurationImpl config = Context.getProcessEngineConfiguration();
        if (config != null) {
            // Fetch the registry that is injected in the activiti spring-configuration
            ServiceRegistry registry = (ServiceRegistry) config.getBeans().get(ActivitiConstants.SERVICE_REGISTRY_BEAN_KEY);

            if (registry == null) {
                throw new RuntimeException("Service-registry not present in ProcessEngineConfiguration beans, expected ServiceRegistry with key" + ActivitiConstants.SERVICE_REGISTRY_BEAN_KEY);
            }

            return registry;
        }
        throw new IllegalStateException("No ProcessEngineCOnfiguration found in active context");
    }

【讨论】:

    猜你喜欢
    • 2010-09-19
    • 1970-01-01
    • 1970-01-01
    • 2014-03-26
    • 2012-03-23
    • 1970-01-01
    • 2020-03-23
    • 1970-01-01
    相关资源
    最近更新 更多