我想从Share webapp中的Java bean访问share-config-custom.xml数据。
在Java上下文中,与以下javascript语法(访问配置根对象)等效的是什么:
config.scoped['RepositoryLibrary']['root-node']是否将share-config-custom转换为bean本身?或者有API可以从Java中读取它吗?
发布于 2013-01-05 01:41:05
首先,没有“合理”的方法来使用这个API“查看”一个XML配置文件。在一般情况下,ConfigService创建一个从各种来源合并的配置。但是,无论如何都不需要直接查看XML。
也就是说,Javascript对象config实际上是一个org.springframework.extensions.webscripts.ScriptConfigModel。
要获得Java语言中的等价物,请引用ConfigService。要获得引用,让spring将其注入到您的自定义bean中:
<property name="configService" ref="web.config" /> 调用configService.getGlobalConfig()应该会得到config.scoped的等价物。
发布于 2013-05-17 23:00:52
我知道这已经被回答了,但Andreas的回答只让我走了一半。configuration类现在实际上是XMLConfigService。
这是一段适用于Enterprise 4.1的代码片段。
Java类
import org.springframework.extensions.config.xml.XMLConfigService;
public class PDFValidate extends BaseJavaDelegate implements ExecutionListener
{
protected XMLConfigService configService;
public void setConfigService( XMLConfigService scriptConfigModel )
{
this.configService = scriptConfigModel;
}Bean注册:
<bean id="AbstractWorkflowDelegate" parent="baseJavaDelegate" abstract="true" depends-on="activitiBeanRegistry" />
<bean id="PDFValidate" parent="AbstractWorkflowDelegate" class="com.epnet.alfresco.metadata.listener.PDFValidate">
<property name="repository" ref="repositoryHelper" />
<property name="configService" ref="web.config" />
</bean>然后,您可以在java代码中使用configService来获取配置值。我的spring-surf-core-configservice-1.2.0-SNAPSHOT.jar版本的XMLConfigService位于我的Alfresco版本中。
https://stackoverflow.com/questions/14161113
复制相似问题