[英]spring scoped proxy and JAXB
JAXBContext是線程安全的,但Unmarshaller不是。 我想讓unmarshaller成為一個請求范圍bean,我這樣做:
<bean id="jaxbContext" class="javax.xml.bind.JAXBContext"
factory-method="newInstance">
<constructor-arg>
<list>
<value type="java.lang.Class">MyType</value>
</list>
</constructor-arg>
</bean>
<bean id="unmarshaller" class="javax.xml.bind.Unmarshaller"
factory-bean="jaxbContext" factory-method="createUnmarshaller"
scope="request">
<aop:scoped-proxy />
</bean>
但問題是我收到以下錯誤:
在創建代理時無法確定目標類型
我已經在Spring會話bean中看到了AOP的問題,這表明我應該告訴spring更多關於我想創建的類型,但是要創建的類型是一個接口。 我是否應該尋找將基於JAXB實現實例化的實際類型,並使unmarshaller bean的class屬性指向它? 看起來有點奇怪。 線索?
編輯:
好吧,我的錯誤。 這實際上有效,它在單元測試中失敗了。 在春季測試請求范圍豆是有幫助的。
嘗試使用lazy-init="true"
: -
<bean id="unmarshaller"
class="javax.xml.bind.Unmarshaller"
factory-bean="jaxbContext"
factory-method="createUnmarshaller"
scope="request"
lazy-init="true">
<aop:scoped-proxy />
</bean>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.