Java spring作用域代理和JAXB
JAXBContext是线程安全的,但解组器不是。我想使解组器成为一个请求范围bean,我正在这样做:Java spring作用域代理和JAXB,java,spring,jaxb,dynamic-proxy,Java,Spring,Jaxb,Dynamic Proxy,JAXBContext是线程安全的,但解组器不是。我想使解组器成为一个请求范围bean,我正在这样做: <bean id="jaxbContext" class="javax.xml.bind.JAXBContext" factory-method="newInstance"> <constructor-arg> <list> <value type="java.lang.Class">MyT
<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>
MyType
这意味着我应该告诉spring更多我想要创建的类型,但是要创建的类型是一个接口。我是否应该查找将基于JAXB实现实例化的实际类型,并使解组器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>