Spring Authorized Proxy and JAXB

JAXBContext is thread safe, but Unmarshaller is not. I would like to make unmarshaller a bean request scope, and I do this:

<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 that I get the following error:

The type of target cannot be determined during proxy creation.

I read a problem in the Spring scope of the bean session with AOP , which suggests that I should tell Spring more about the type I need, but the type to create is the interface. Should I track down the actual type that will be created based on the JAXB implementation, and point the unmarshaller bean class attribute to this? Seems strange. The evidence?

EDIT:

Ok, my mistake. This really works, it just fails in my unit test. querying beans in Spring was helpful.

+4
source share
1 answer

Try using 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> 
+3
source

Source: https://habr.com/ru/post/1341189/


All Articles