java - 错误 beanFactory/ApplicationContext - JAVA

标签 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);

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

错误:

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'GlobalAuthenticationFilter' defined in class path resource [alfresco/web-client-application-context.xml]: Cannot resolve reference to bean 'Authentication' while setting bean property 'applicationContextManager'; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'Authentication' is defined

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

最佳答案

我通过替换以下内容解决了这个问题: 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");
    }

关于java - 错误 beanFactory/ApplicationContext - JAVA,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33837637/

相关文章:

java - 使用 Java EE 和 primefaces 从 MySQL 下载文件

java - 使用 Jython 在 Java 中运行 Python 程序

java - 循环 View 路径错误,Spring MVC

java - Spring boot security oauth2 从 cookie 中获取 access_token

java - EBean增强专家

java - 从 ArrayList Java 处理 Boid 示例中删除元素

Java在synchronized block 中调用其他方法

java - 从操作重定向到同一页面

java - Spring 安全 : 404 on logout

java - 根据 Spring Boot 中的角色获取用户列表