0

几周前,我开发了一个基于 Alfresco 3.4.14 的 AMP。在那个模块中,我创建了一些定制服务。其中一项服务用于管理用户,并提供了一种创建新用户的方法:

public NodeRef createUser(<my_parameters>) {
    ..........................
    ..........................
    HashMap<QName, Serializable> properties = new HashMap<QName, Serializable>();

    properties.put(ContentModel.PROP_USERNAME, username);
    properties.put(ContentModel.PROP_PASSWORD, password);
    ..........................
    ..........................
    NodeRef person = personService.createPerson(properties);
    return person;
}

所有服务都在露天上下文文件中定义:

<?xml version='1.0' encoding='UTF-8'?>
<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xsi:schemaLocation="http://www.springframework.org/schema/beans  http://www.springframework.org/schema/beans/spring-beans-3.0.xsd">

    <bean id="customUserService" class="com.mycustom.service.impl.CustomUsersServiceImpl">
        <property name="personService" ref="PersonService"/>
        <property name="nodeService" ref="NodeService"/>
    </bean>
    <bean id="customProjectsService" class="com.mycustom.service.impl.CustomProjectsServiceImpl">
        <property name="searchService" ref="SearchService"/>
        <property name="nodeService" ref="NodeService"/>
    </bean>
</beans>

一切正常。我能够创建用户,执行我的其他定制服务......直到这里完美!!!!!!!!!该应用程序运行正常。


几天前,我们决定开始使用spring注解,而不是定义上下文中的所有bean:

package com.mycustom.service.impl;

@Service("customUsersService")
public class CustomUsersServiceImpl implements CustomUsersService {

    @Override
    public NodeRef createUser(<my_parameters>) {
    }
}

在上下文文件中,使用 spring 组件扫描:

<?xml version='1.0' encoding='UTF-8'?>
<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns:context="http://www.springframework.org/schema/context"
       xsi:schemaLocation="
        http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
        http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd">

    <context:annotation-config/>
    <context:component-scan base-package="com.mycustom.service" />
</beans>

所有服务都正常工作,应用程序看起来也正常工作。我们很高兴,因为我们可以使用注释解耦我们的应用程序。

BUTTTTTTTTTTTT,当我尝试通过资源管理器或通过应用程序创建用户时,我得到了同样的错误:Failed to create Person due to error: xxxxxxx beforeCreateNode: use PersonService to create person

在此处输入图像描述

4

1 回答 1

0

调试 PersonServiceImpl 类,我检测到错误在 beforeCreateNodeValidationBehaviour.enable();

public NodeRef createPerson(Map<QName, Serializable> properties, Set<String> zones) {
    .....................
    .....................
    NodeRef personRef = null;
        try
        {
            beforeCreateNodeValidationBehaviour.disable();

            personRef = nodeService.createNode(
                    getPeopleContainer(),
                    ContentModel.ASSOC_CHILDREN,
                    getChildNameLower(userName), // Lowercase:
                    ContentModel.TYPE_PERSON, properties).getChildRef();
        }
        finally
        {
            //ERROR!!!!!!!!!!!!!!!!
            beforeCreateNodeValidationBehaviour.enable();
        }
    .....................
    .....................
}

经过一番调查,当我们恢复代码并删除 spring 组件扫描时,应用程序再次正常工作。

我们开了一张 Alfresco 支持的票,他们告诉我们,这个问题在 alfresco 4.1.4 中已修复

然后像我们这样使用先前版本的 Alfresco 的人,请注意这一点,并删除组件扫描并用手动 bean 接线替换它。

于 2014-07-25T21:40:06.727 回答