错误beanFactory / ApplicationContext - JAVA

时间:2015-11-20 23:15:55

标签: java spring spring-mvc javabeans alfresco

我跟随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);

网络的客户端的应用程序-context.xml中https://github.com/Alfresco/community-edition/blob/master/projects/web-client/config/alfresco/web-client-application-context.xml

ERROR:

  

org.springframework.beans.factory.BeanCreationException:错误   使用名称' GlobalAuthenticationFilter'创建bean在课堂上定义   路径资源[alfresco / web-client-application-context.xml]:不能   解析对bean' Authentication'的引用设置bean属性时   ' applicationContextManager&#39 ;;嵌套异常是   org.springframework.beans.factory.NoSuchBeanDefinitionException:没有   bean名为' Authentication'已定义

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

1 个答案:

答案 0 :(得分: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");
    }