2011-09-08 67 views
4

是否存在@Configurable註釋的任何XML等價物?Spring中@Configurable註釋的XML等價物

例如,對於豆:

<bean class="org.obliquid.sherd.domain.SalesDocument" scope ="prototype"> 
    <property name="docType" ref="documentTypeProto"/> 
</bean> 

我怎麼能告訴SalesDocument應該是@Configurable?

+0

不是你的問題的答案,但如果你需要在春季增強配置支持,請看看Constretto:https://github.com/constretto/constretto-core – ebaxt

回答

4

否 - @Configurable將屬性注入非Spring bean對象的目的。在您的示例中,SalesDocument已經是Spring bean,並且docType將被注入。

+0

不是如果我用DAO裏面的新創建它,但是。 – stivlo

+0

在這種情況下,請勿使用new,請使用applicationContext.getBean(「salesDocument」) – sourcedelica

0

沒有辦法簡單地做到這一點,我意識到這一點。

實現您想要的一種方法是使用基於Spring AspectJ的AOP擴展。這將是很多工作,但如果你知道你的DAO需要有限的配置(可能只是EntityManager?)它可能是可行的。

查看at the spring reference docs瞭解詳情。