55import java .util .Arrays ;
66import java .util .List ;
77
8- import org .baeldung .persistence .service .RedditTokenService ;
8+ import javax .annotation .PostConstruct ;
9+
10+ import org .apache .commons .lang .StringUtils ;
11+ import org .baeldung .persistence .dao .PostRepository ;
912import org .baeldung .reddit .classifier .RedditClassifier ;
1013import org .baeldung .reddit .util .MyFeatures ;
1114import org .baeldung .reddit .util .UserAgentInterceptor ;
@@ -115,6 +118,9 @@ protected static class ResourceConfiguration {
115118 @ Value ("${clientSecret}" )
116119 private String clientSecret ;
117120
121+ @ Autowired
122+ private PostRepository repo ;
123+
118124 @ Bean
119125 public OAuth2ProtectedResourceDetails reddit () {
120126 final AuthorizationCodeResourceDetails details = new AuthorizationCodeResourceDetails ();
@@ -132,16 +138,24 @@ public OAuth2ProtectedResourceDetails reddit() {
132138 }
133139
134140 @ Bean
135- public OAuth2RestTemplate redditRestTemplate (OAuth2ClientContext clientContext , RedditTokenService redditTokenService ) {
141+ public OAuth2RestTemplate redditRestTemplate (OAuth2ClientContext clientContext ) {
136142 final OAuth2RestTemplate template = new OAuth2RestTemplate (reddit (), clientContext );
137143 final List <ClientHttpRequestInterceptor > list = new ArrayList <ClientHttpRequestInterceptor >();
138144 list .add (new UserAgentInterceptor ());
139145 template .setInterceptors (list );
140146 final AccessTokenProviderChain accessTokenProvider = new AccessTokenProviderChain (Arrays .<AccessTokenProvider > asList (new MyAuthorizationCodeAccessTokenProvider (), new ImplicitAccessTokenProvider (), new ResourceOwnerPasswordAccessTokenProvider (),
141147 new ClientCredentialsAccessTokenProvider ()));
142- accessTokenProvider .setClientTokenServices (redditTokenService );
143148 template .setAccessTokenProvider (accessTokenProvider );
144149 return template ;
145150 }
151+
152+ @ PostConstruct
153+ public void startupCheck () {
154+ if (StringUtils .isBlank (accessTokenUri ) || StringUtils .isBlank (userAuthorizationUri ) || StringUtils .isBlank (clientID ) || StringUtils .isBlank (clientSecret )) {
155+ throw new RuntimeException ("Incomplete reddit properties" );
156+ }
157+ repo .findAll ();
158+ }
159+
146160 }
147161}
0 commit comments