简体   繁体   English

spring scoped proxy和JAXB

[英]spring scoped proxy and JAXB

JAXBContext is thread-safe but the Unmarshaller is not. JAXBContext是线程安全的,但Unmarshaller不是。 I'd like to make the unmarshaller a request scope bean, and I'm doing this: 我想让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>

But the problem is I'm getting the following error: 但问题是我收到以下错误:

Target type could not be determined at the time of proxy creation 在创建代理时无法确定目标类型

I've read problem in Spring session scope bean with AOP which suggests that I should tell spring more about the type I'd like created, but the type to create is an interface. 我已经在Spring会话bean中看到了AOP的问题,这表明我应该告诉spring更多关于我想创建的类型,但是要创建的类型是一个接口。 Am I supposed to hunt down the actual type that will get instantiated based on the JAXB implementation, and make the unmarshaller bean's class attribute point to that? 我是否应该寻找将基于JAXB实现实例化的实际类型,并使unmarshaller bean的class属性指向它? Seems kind of weird. 看起来有点奇怪。 Clues? 线索?

EDIT: 编辑:

Ok my mistake. 好吧,我的错误。 This actually works, it just fails in my unit test. 这实际上有效,它在单元测试中失败了。 request scoped beans in spring testing was helpful. 在春季测试请求范围豆是有帮助的。

Try using lazy-init="true" :- 尝试使用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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM