[英]How to convert spring bean Oauth integration From XML to Java annotation based Config
[英]How to convert an xml config bean to java annotation bean ( spring boot )
我是java AOP的新手。 我應該在我的spring啟動應用程序中將以下xml配置轉換為java annotation配置。 我可以知道如何將此xml配置轉換為java注釋配置:
我認為我在stackoverflow中看到的所有示例都與我嘗試轉換的模式不匹配。
<bean id="xyzRestTemplate"
class="org.springframework.web.client.RestTemplate">
<constructor-arg ref="xyzClientHttpRequestFactory" />
<property name="messageConverters">
<list>
<bean class="org.springframework.http.converter.xml.MarshallingHttpMessageConverter">
<property name="marshaller" ref="jaxbDataMarshaller" />
<property name="unmarshaller" ref="jaxbDataMarshaller" />
</bean>
</list>
</property>
<property name="interceptors">
<list>
<bean class="com.example.XYZHeaderRequestInterceptor" />
</list>
</property>
</bean>
<bean id="jaxbDataMarshaller" class="org.springframework.oxm.jaxb.Jaxb2Marshaller">
<property name="contextPaths">
<list>
<value>com.a.b.c.d.v2</value>
</list>
</property> </bean>
當人們談論從XML轉換時,他們並不意味着必須完全相同。 Spring Boot的吸引力不僅在於配置是一個java類。
您應該將其轉換為使用RestTemplate https://docs.spring.io/spring-boot/docs/current/reference/html/boot-features-resttemplate.html
然后,您只需使用構建器構建RestTemplate,即可獲得所需的JaxB編組器和攔截器。
一個很好的測試用例傳遞XML並傳遞@Configuration類將證明你做對了。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.