How can I use an OAuth2RestTemplate in a scheduled task?

亡梦爱人 提交于 2019-12-04 05:08:58

It turned out to be pretty simple. I wanted a singleton bean, so I created a singleton bean:

@Primary
@Bean
public OAuth2ClientContext singletonClientContext() {
    return new DefaultOAuth2ClientContext();
}

With that in my @Configuration class, Spring wired it in to my OAuth2RestTemplate and my scheduled tasks were able to call out the Email service. For good measure, I added the @Primary annotation to make sure this bean was preferred over anything that Spring Boot created (not sure if that's required).

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!