263.25. @PropertyInject 사용

Camel 2.12에서 사용 가능

Camel을 사용하면 필드 및 설정 방법에 설정할 수 있는 @PropertyInject 주석을 사용하여 POJO에 속성 자리 표시자를 삽입할 수 있습니다.

예를 들어 다음과 같은 RouteBuilder 클래스와 함께 이를 사용할 수 있습니다.

public class MyRouteBuilder extends RouteBuilder {

    @PropertyInject("hello")
    private String greeting;

    @Override
    public void configure() throws Exception {
        from("direct:start")
            .transform().constant(greeting)
            .to("{{result}}");
    }

}

인사말 필드에 @PropertyInject 에 주석을 추가하고 "hello" 키를 사용하도록 정의합니다. 그런 다음 Camel은 이 키를 사용하여 속성을 조회하고 해당 값을 String 유형으로 변환합니다.

키에서 여러 자리 표시자와 텍스트를 사용할 수도 있습니다(예: 수행할 수 있습니다.You can also use multiple placeholders and text in the key, for example we can do:

@PropertyInject("Hello {{name}} how are you?")
private String greeting;

그러면 해당 키 "name" 으로 자리 표시자가 조회됩니다.

키가 없는 경우 다음과 같이 기본값을 추가할 수도 있습니다.

@PropertyInject(value = "myTimeout", defaultValue = "5000")
private int timeout;