我有定义
<context:property-placeholder location="classpath:/mule-sw.properties"/>
而且我在 Java 中还有一个自定义组件类,它在我的一个字段上使用 @Lookup 注释
@Lookup("file-path")
private String path;
考虑到我的“mule-sw.properties”是这样的
file-path=C:/hello.txt
启动 Mule 应用程序后,总是出现部署异常
org.mule.api.expression.RequiredValueException: "Required object not found in registry of Type "class java.lang.String" with name "file-path" on object "class component.CustomComponent"
我还尝试用 @Lookup("${file-path}") 更改 @Lookup("file-path") 但没有成功。
谁能给我一个更好的解决方案? 非常感谢任何帮助。
谢谢
最佳答案
@Lookup 注释旨在检索 objects from the registry ,而您要做的是为自定义组件的属性分配一个值。
有两种方法:
1) 通过属性注入(inject),即你像下面这样声明你的组件:
<custom-component class="org.myCompany.CustomComponent">
<property name="file-path" value="${file-path}" />
</custom-component>
2) 通过 Spring EL 支持和@Value 注解,即你用下面的方式注解你的属性
@Value("${file-path}")
private String path;
我推荐第一种方法,因为从流程的角度来看它更容易维护
https://stackoverflow.com/questions/12492547/