0
我一直試圖在我的註釋中設置logTime
屬性在spring xml中。我看到這並不像我第一次想到的那麼容易。春季設置註釋屬性xml
@Component
@Retention(RetentionPolicy.RUNTIME)
public @interface LogExecTime {
public boolean logTime() default true;
}
我都試過,沒有運氣的接口使用@Value
註釋:
I)
@Component
@Retention(RetentionPolicy.RUNTIME)
public @interface LogExecTime {
@Value("#{ConfigureAnnotation.doLogging}")
public boolean logTime() default true;
}
也
II)
@LogExecTime([email protected]("#{ConfigureAnnotation.doLogging}"))
任何想法如何,我可以在XML層次做到這一點或者是這不可能與註釋依賴注入?
嗨Iscoughlin。
@Value("#{ConfigureAnnotation.doLogging}") boolean logTime = true;
不適用於我的註釋,但logTime = "#{ConfigureAnnotation.doLogging}"
看起來可以。我的Aspect讀取它,但只打印「#{ConfigureAnnotation.doLogging}」,而不是我在xml中設置的值「true」。你能告訴我你將如何實現這一目標嗎? – MWright您需要對分配給註釋的值執行一些操作。在這種情況下,值爲 #{ConfigureAnnotation.doLogging} 因此,您需要實例化一個彈簧EL解析器來解析該值或解析出您的自身的鍵以及它的某些內容,如System.getProperty(annotation .value()。substring(2,annotation.value()。size()-3) – lscoughlin