lundi 23 février 2015

Using request scoped bean within hystrix command

I have a request scoped bean declared like so:



<bean id="testOptionDao" class="com.something.TestOptionDao" scope="request">
<aop:scoped-proxy/>
</bean>


And then injected into 2 aspects:



<bean id="testOptionCapturerAspect" class="TestOptionCapturerAspect">
<constructor-arg ref="testOptionDao"/>
</bean>

<bean id="targetUriReplacerAspect" class="TargetUriReplacerAspect">
<constructor-arg ref="testOptionDao" />
</bean>

<aop:config>
<!-- Capture testOption from incoming request -->
<aop:aspect ref="testOptionCapturerAspect">
<aop:before method="captureTestOptionFromIncomingRequest"
pointcut="@annotation(org.springframework.web.bind.annotation.RequestMapping)" />
</aop:aspect>
</aop:config>

<aop:config>
<!-- Turn outgoing requests into canned feed URLs -->
<aop:aspect ref="targetUriReplacerAspect">
<aop:around method="replaceUri" pointcut="execution(* org.springframework.web.client.RestOperations.exchange(..)) and args(targetUri, ..)"/>
</aop:aspect>
</aop:config>


The whole purpose of this is to capture requests on test environment coming with specific argument, and replacing real calls to API with calls to canned data. Don't ask me why that specific solution, I did not do it and I would like to change it, but I can't and have to work with that.

The problem is now that I need to wrap calls to external API (RestOperations.exchange()) in a HystrixCommand, and it seems like the testOptionDao bean even though it is request scoped, it is not visible from the thread that Hystrix is spinning up for the HystrixCommand.

Has anyone came across that? And how can I make sure that this bean is visible within Hystrix thread? I am running out of ideas... Thanks a lot for any help!


Aucun commentaire:

Enregistrer un commentaire