title: spring scoped proxy and JAXB
body: <p>JAXBContext is thread-safe but the Unmarshaller is not. I'd like to make the unmarshaller a request scope bean, and I'm doing this:</p>
  
  <pre><code>&lt;bean id="jaxbContext" class="javax.xml.bind.JAXBContext"
      factory-method="newInstance"&gt;
      &lt;constructor-arg&gt;
          &lt;list&gt;
              &lt;value type="java.lang.Class"&gt;MyType&lt;/value&gt;
          &lt;/list&gt;
      &lt;/constructor-arg&gt;
  &lt;/bean&gt;
  &lt;bean id="unmarshaller" class="javax.xml.bind.Unmarshaller"
      factory-bean="jaxbContext" factory-method="createUnmarshaller"
      scope="request"&gt;
      &lt;aop:scoped-proxy /&gt;
  &lt;/bean&gt;
  </code></pre>
  
  <p>But the problem is I'm getting the following error:</p>
  
  <blockquote>
    <p>Target type could not be determined at the time of proxy creation</p>
  </blockquote>
  
  <p>I've read <a href="https://stackoverflow.com/questions/1951259/problem-in-spring-session-scope-bean-with-aop">problem in Spring session scope bean with AOP</a> which suggests that I should tell spring more about the type I'd like created, but the type to create is an interface. 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? Seems kind of weird. Clues?</p>
  
  <p>EDIT:</p>
  
  <p>Ok my mistake. This actually works, it just fails in my unit test. <a href="https://stackoverflow.com/questions/2411343/request-scoped-beans-in-spring-testing">request scoped beans in spring testing</a> was helpful.</p>