我正在关注 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/