jeudi 19 février 2015

Replacing Spring bean injection via XML with annotation injection

I want to declare and inject a bean through annotations. It was previously done through XML, but I need to apply on a Spring Boot project.


Here is the source xml



<oauth:resource-details-service id="rds">
<oauth:resource
id="oauth1"
key="${key}"
secret="${secret}"
request-token-url="${token}"
user-authorization-url="${user-auth}"
access-token-url="${accesstokenurl}">
</oauth:resource>
</oauth:resource-details-service>


The bean was later used like this



<bean class="org.springframework.security.oauth.consumer.client.OAuthRestTemplate">
<constructor-arg ref="oauth1"/>
</bean>


The only way I found is through direct instantiation



BaseProtectedResourceDetails resourceDetails = new BaseProtectedResourceDetails();
resourceDetails.set...
resourceDetails.set...
OAuthRestTemplate restTemplate = new OAuthRestTemplate(resourceDetails);


What would be the proper way to do this?


Aucun commentaire:

Enregistrer un commentaire