【问题标题】:spring scoped proxy and JAXBspring 范围代理和 JAXB
【发布时间】:2011-07-03 19:07:33
【问题描述】:

JAXBContext 是线程安全的,但 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>

但问题是我收到以下错误:

在创建代理时无法确定目标类型

我读过problem in Spring session scope bean with AOP,这表明我应该告诉spring 更多关于我想要创建的类型,但是要创建的类型是一个接口。我是否应该寻找将基于 JAXB 实现实例化的实际类型,并使 unmarshaller bean 的类属性指向它?似乎有点奇怪。线索?

编辑:

好吧,我错了。这实际上有效,只是在我的单元测试中失败了。 request scoped beans in spring testing 很有帮助。

【问题讨论】:

    标签: java spring jaxb dynamic-proxy


    【解决方案1】:

    尝试使用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>
    

    【讨论】:

      猜你喜欢
      • 2014-10-28
      • 1970-01-01
      • 1970-01-01
      • 2016-11-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多