2

I have Mule Configuration that defines

<context:property-placeholder location="classpath:/mule-sw.properties"/>

And I also have a custom component class in Java which use @Lookup annotation on one of my field

@Lookup("file-path")
private String path;

Considering my "mule-sw.properties" is like this

file-path=C:/hello.txt

After I start up the Mule App, I always get Deploy Exception

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"

I also tried to change the @Lookup("file-path") with @Lookup("${file-path}") with no success.

Anyone can give me a better solution ? Any help is kindly appreciated.

Thanks

2 Answers2

7

The @Lookup annotation is designed to retrieve objects from the registry , whereas what you are trying to do is to assign a value to an attribute of your custom component.

There are 2 way to do that:

1) Through property injection, i.e. you declare your component like the following:

<custom-component class="org.myCompany.CustomComponent">
    <property name="file-path" value="${file-path}" />
</custom-component>

2) Through Spring EL support and the @Value annotation, i.e. you annotate your attribute in the following way

@Value("${file-path}")
private String path;

I'd recommend the first approach since it is easier to maintain from a flow perspective

David Dossot
  • 33,403
  • 4
  • 38
  • 72
genjosanzo
  • 3,264
  • 2
  • 16
  • 21
  • 1
    Hi, Thanks for the answer. 1st approach works for me by adding setter method to the custom component. As for 2nd approach, it doesn't work, I think the @Value annotation doesn't get processed if I use Mule to instantiate the custom component. – Angga Muhammad Sep 20 '12 at 02:48
3
@Value("#{'${file-path}'}")
private String path;

Give this a shot. I think you need to wrap it in an EL block #{} for it to be properly recognized.

  • Hi Chronowraith .... even if i try this EL block thing , I am not able to access th property ... how do i achieve getting properties into my java class via propertiesplaceholder – Krithika Vittal Aug 14 '13 at 18:28