首页 > 解决方案 > 动态访问 alfresco-global.properties

问题描述

尽管我阅读了这篇文章,但我无法动态访问 alfresco-global.properties 值: Accessing values from Alfresco's alfresco-global.properties file

这是我的conf:

服务上下文.xml

<bean id="AccesGlobalPropertiesService" class="com.package.ksc.services.AccesGlobalPropertiesService">
     <property name="properties">
        <ref bean="global-properties"/>
    </property>
</bean>

AccesGlobalPropertiesService.java

import org.springframework.stereotype.Service;
import java.util.Properties;

@Service
public class AccesGlobalPropertiesService {

    public Properties properties;

    public void setProperties(Properties properties) {
        this.properties = properties;
    }
    public Properties getProperties() {
        return properties;
    }
}

工人.java

public abstract class ClassifierServiceCommon {

   private AccesGlobalProperties accesGlobalProperties;
   private Properties properties;    

   /* Constructor */
   protected Worker(accesGlobalProperties) {
     this.accesGlobalProperties= accesGlobalProperties;
   }

   ...

   protected Boolean propAcces() {
      accesGlobalProperties.properties.getProperty("myPropKey");
      ...
   }
}

当我调用 getProperty("myPropKey") ...

请问怎么了?谢谢

标签: javaspringalfrescospring-annotations

解决方案


似乎您错误地定义了两个具有不同 ID-s 的 bean:

  1. 一个 bean 来自 XML,它的 ID 明确指定为“AccesGlobalPropertiesService”。它的properties字段设置正确。
  2. 另一个 bean 来自 Spring 组件扫描(感谢@Service注解),其 ID 隐式设置为“accesGlobalPropertiesService”。它的properties字段未设置,因为该字段缺少@Resourceor@Autowired注释(参见例如this question on how to use them)。

然后你很可能会使用你ClassifierServiceCommon班上的第二个(不完整的)。(您没有指定如何在此处获取 bean。)


推荐阅读