I have implemented some redis stuff in my spring boot 2.1.5 application. It works fine.
I also want the health check for redis. If I switch off the redis server the health check (actuator/health) hangs forever.
How can I configure a sensible timeout?
I have created a little demo of this problem here:
https://github.com/markuskruse/demo-redis-health-bug
Clone, run, stop redis, check health (wait forever), start redis (health returns).
This is my gradle for redis:
implementation 'org.springframework.boot:spring-boot-starter-data-redis'
This is my application.yaml:
spring:
redis:
timeout: 5000
host: localhost
This is my RedisConfig.java
#Configuration
#EnableConfigurationProperties(RedisProperties.class)
public class RedisConfig {
#Bean
public LettuceConnectionFactory redisConnectionFactory(
#Value("${spring.redis.host:localhost}") String redisHost) {
RedisStandaloneConfiguration redisStandaloneConfiguration =
new RedisStandaloneConfiguration(redisHost);
return new LettuceConnectionFactory(redisStandaloneConfiguration);
}
#Bean
public StringRedisTemplate redisTemplate(RedisConnectionFactory jedisConnectionFactory) {
final StringRedisTemplate template = new StringRedisTemplate();
template.setConnectionFactory(jedisConnectionFactory);
template.afterPropertiesSet();
return template;
}
}
According to this issue on github, it is a mere configuration issue:
https://github.com/spring-projects/spring-boot/issues/15542
According to this jira ticket, it should be fixed in spring boot 2.1.4 (I'm on 2.1.5).
https://jira.spring.io/browse/DATAREDIS-918
They mention a workaround that I have tried:
#Bean
public ClientOptions clientOptions() {
return ClientOptions.builder()
.timeoutOptions(TimeoutOptions.enabled())
.build();
}
By itself, it had no effect. I have to inject it somewhere. Googling gave this:
#Bean
LettucePoolingClientConfiguration lettucePoolConfig(ClientOptions options, ClientResources dcr){
return LettucePoolingClientConfiguration.builder()
.clientOptions(options)
.clientResources(dcr)
.build();
}
Then I get this:
Caused by: org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.data.redis.connection.lettuce.LettucePoolingClientConfiguration]: Factory method 'lettucePoolConfig' threw exception; nested exception is java.lang.NoClassDefFoundError: org/apache/commons/pool2/impl/GenericObjectPoolConfig
at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:185)
at org.springframework.beans.factory.support.ConstructorResolver.instantiate(ConstructorResolver.java:622)
... 50 more
Caused by: java.lang.NoClassDefFoundError: org/apache/commons/pool2/impl/GenericObjectPoolConfig
at org.springframework.data.redis.connection.lettuce.LettucePoolingClientConfiguration$LettucePoolingClientConfigurationBuilder.<init>(LettucePoolingClientConfiguration.java:91)
at org.springframework.data.redis.connection.lettuce.LettucePoolingClientConfiguration.builder(LettucePoolingClientConfiguration.java:50)
at com.ikea.cps.mhs.config.RedisConfig.lettucePoolConfig(RedisConfig.java:50)
at com.ikea.cps.mhs.config.RedisConfig$$EnhancerBySpringCGLIB$$3804d114.CGLIB$lettucePoolConfig$3(<generated>)
at com.ikea.cps.mhs.config.RedisConfig$$EnhancerBySpringCGLIB$$3804d114$$FastClassBySpringCGLIB$$ccabed80.invoke(<generated>)
at org.springframework.cglib.proxy.MethodProxy.invokeSuper(MethodProxy.java:244)
at org.springframework.context.annotation.ConfigurationClassEnhancer$BeanMethodInterceptor.intercept(ConfigurationClassEnhancer.java:363)
at com.ikea.cps.mhs.config.RedisConfig$$EnhancerBySpringCGLIB$$3804d114.lettucePoolConfig(<generated>)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:566)
at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:154)
... 51 more
Caused by: java.lang.ClassNotFoundException: org.apache.commons.pool2.impl.GenericObjectPoolConfig
at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:583)
at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:178)
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:521)
... 64 more
I can maybe work around this. But I am thinking that I am doing something (fundamentally) wrong. It should already be fixed.
Edit: I added the commons pool and the error goes away, but health check still hangs forever.
I also tried this below, to no effect.
#Component
public class RedisConfigurer implements LettuceClientConfigurationBuilderCustomizer {
#Override
public void customize(LettuceClientConfigurationBuilder builder) {
builder.clientOptions(ClientOptions.builder()
.timeoutOptions(TimeoutOptions.enabled(Duration.of(5, SECONDS))).build());
}
}
It seems that your problem is in your manual Connection factory configuration.
If you remove that part, everything should be fine as you expected.
Otherwise you need to provide a LettuceClientConfiguration for the second argument of the LettuceConnectionFactory constructor and there you can configure ClientOptions with enabled TimeoutOptions
Related
In a spring-boot project i am using the following code:
import org.springframework.integration.core.MessageSource;
#Configuration
public class Config
{
#Bean
#InboundChannelAdapter(channel = "channel1", autoStartup = "false",
poller = #Poller("poller"))
public MessageSource messages() throws Exception
{
...
to poll a mailaccount for incoming messages. This works fine so far.
The problem arises when i try to call some tests in a class that is annotated with #SpringBootTest. Then the initialisation of my testclass fails:
2023-01-12T16:43:03.846+01:00 ERROR 3625 --- [ main] o.s.test.context.TestContextManager : Caught exception while allowing TestExecutionListener [org.springframework.boot.test.autoconfigure.SpringBootDependencyInjectionTestExecutionListener#63648ee9] to prepare test instance [MyClass#b849fa6]
java.lang.IllegalStateException: Failed to load ApplicationContext
at org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContext(DefaultCacheAwareContextLoaderDelegate.java:131) ~[spring-test-6.0.0-M5.jar:6.0.0-M5]
<... stacktrace ...>
Caused by: java.lang.IllegalArgumentException: The 'interface org.springframework.integration.annotation.InboundChannelAdapter' on #Bean method level is allowed only for: org.springframework.integration.core.MessageSource, or java.util.function.Supplier, or kotlin.jvm.functions.Function0 beans
<... more stacktrace...>
I can't see the problem here, since the annotation is used together with MessageSource. Can someone help me on this one, please?
update in reply to the comment from Vitaly Chura:
in fact, that does not tell me much, unfortunately, but i will give it a try:
Caused by: java.lang.IllegalArgumentException: The 'interface org.springframework.integration.annotation.InboundChannelAdapter' on #Bean method level is allowed only for: org.springframework.integration.core.MessageSource, or java.util.function.Supplier, or kotlin.jvm.functions.Function0 beans
at org.springframework.util.Assert.isTrue(Assert.java:139) ~[spring-core-6.0.0-M5.jar:6.0.0-M5]
at org.springframework.integration.config.annotation.InboundChannelAdapterAnnotationPostProcessor.createMessageSource(InboundChannelAdapterAnnotationPostProcessor.java:100) ~[spring-integration-core-6.0.0-M4.jar:6.0.0-M4]
at org.springframework.integration.config.annotation.InboundChannelAdapterAnnotationPostProcessor.postProcess(InboundChannelAdapterAnnotationPostProcessor.java:72) ~[spring-integration-core-6.0.0-M4.jar:6.0.0-M4]
at org.springframework.integration.config.annotation.MessagingAnnotationPostProcessor.postProcessMethodAndRegisterEndpointIfAny(MessagingAnnotationPostProcessor.java:231) ~[spring-integration-core-6.0.0-M4.jar:6.0.0-M4]
at org.springframework.integration.config.annotation.MessagingAnnotationPostProcessor.lambda$processAnnotationTypeOnMethod$4(MessagingAnnotationPostProcessor.java:220) ~[spring-integration-core-6.0.0-M4.jar:6.0.0-M4]
at java.base/java.util.ArrayList.forEach(ArrayList.java:1511) ~[na:na]
at org.springframework.integration.config.annotation.MessagingAnnotationPostProcessor.afterSingletonsInstantiated(MessagingAnnotationPostProcessor.java:135) ~[spring-integration-core-6.0.0-M4.jar:6.0.0-M4]
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:941) ~[spring-beans-6.0.0-M5.jar:6.0.0-M5]
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:926) ~[spring-context-6.0.0-M5.jar:6.0.0-M5]
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:592) ~[spring-context-6.0.0-M5.jar:6.0.0-M5]
at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:731) ~[spring-boot-3.0.0-M4.jar:3.0.0-M4]
at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:430) ~[spring-boot-3.0.0-M4.jar:3.0.0-M4]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:312) ~[spring-boot-3.0.0-M4.jar:3.0.0-M4]
at org.springframework.boot.test.context.SpringBootContextLoader.loadContext(SpringBootContextLoader.java:132) ~[spring-boot-test-3.0.0-M4.jar:3.0.0-M4]
at org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContextInternal(DefaultCacheAwareContextLoaderDelegate.java:98) ~[spring-test-6.0.0-M5.jar:6.0.0-M5]
at org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContext(DefaultCacheAwareContextLoaderDelegate.java:123) ~[spring-test-6.0.0-M5.jar:6.0.0-M5]
... 72 common frames omitted
I know this does not explain the IllegalArgumentException, but for reasons of pragmatism i circumvented this problem by implementing a dummy configuration class inside the test-folder of the maven-project that provides the same beans as the original but does not use the #InboundChannelAdapter, as suggested by Matheus Santz in how-to-exclude-java-configuration-class-from-test-context. So for the tests this new dummy class is used.
Thanx to Vitaly Chura and all others reading.
I've written a simple Feign client, for calling an external API (running on a different server):
#FeignClient(
name = "test-service",
url = "https://some-test-server.com/api"
)
public interface TestClient {
#RequestMapping(method = RequestMethod.POST, value = "/test")
TestResponse test(TestRequest request);
}
I wrote some simple bean classes, TestRequest & TestResponse to model the request / response - I'm expecting them to be serialized & deserialized as json.
I want to just test that its able to make the HTTP call and receive a response, so I wrote a test:
#SpringBootTest
#EnableFeignClients(clients = TestClient.class)
class ClientApplicationTests {
#Autowired
private TestClient client;
#Test
void contextLoads() {
System.out.println(client.test(TestRequest.builder().foo("foo").build()));
}
But Intellij warns me that no Beans were found to autowire TestClient, and running this gives a similar exception:
java.lang.NoClassDefFoundError: org/springframework/cloud/context/named/NamedContextFactory$Specification
at java.base/java.lang.ClassLoader.defineClass1(Native Method) ~[na:na]
at java.base/java.lang.ClassLoader.defineClass(ClassLoader.java:1012) ~[na:na]
at java.base/java.security.SecureClassLoader.defineClass(SecureClassLoader.java:150) ~[na:na]
at java.base/jdk.internal.loader.BuiltinClassLoader.defineClass(BuiltinClassLoader.java:862) ~[na:na]
at java.base/jdk.internal.loader.BuiltinClassLoader.findClassOnClassPathOrNull(BuiltinClassLoader.java:760) ~[na:na]
at java.base/jdk.internal.loader.BuiltinClassLoader.loadClassOrNull(BuiltinClassLoader.java:681) ~[na:na]
at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:639) ~[na:na]
at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:188) ~[na:na]
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:520) ~[na:na]
at org.springframework.cloud.openfeign.FeignClientsRegistrar.registerClientConfiguration(FeignClientsRegistrar.java:410) ~[spring-cloud-openfeign-core-3.1.3.jar:3.1.3]
What am I doing wrong?
Try giving your Feign client class name in this format and check whether this works,
#EnableFeignClients(basePackageClasses=com.abc.xxx.client.TestClient.class)
This parameter accept single or multiple class name. You can also give the base package of the same,
#EnableFeignClients(basePackages = {"my.external.feign.client.package", "my.local.package"})
From the javadoc of #EnableFeignClients:
Scans for interfaces that declare they are feign clients (via FeignClient #FeignClient). Configures component scanning directives for use with org.springframework.context.annotation.Configuration #Configuration classes.
Generally this is placed on a #SpringBootApplication annotated class so that your Feign clients are available in production as well as your #SpringBootTest's.
If you really want to enable your Feign client only in your test, it should look something like this:
#SpringBootTest
class ClientApplicationTests {
#EnableFeignClients(clients = TestClient.class)
#Configuration
protected static class ClientApplicationTestsConfig {
}
#Autowired
private TestClient client;
#Test
void contextLoads() {
System.out.println(client.test(TestRequest.builder().foo("foo").build()));
}
}
This way your test will use the nested #Configuration instead of the automatically found #SpringBootConfiguration/#SpringBootApplication.
I have a spring boot application and I am trying to configure listeners to already existing queues. Following is what I configured in my application.yml file. I have also annotated my config class with #EnableRabbit and listener with #RabbitListener with appropriate configuration referring spring documentation.
Please note that every property has a valid default value, I have removed them before posting them here.
spring:
rabbitmq:
host: ${rmq_host}
port: ${rmq_port}
virtualHost: ${rmq_virtual_host}
requestedHeartbeat: ${rmq_requested_heartbeat_seconds}
listener:
simple:
concurrency: ${rmq_listener_config_concurrent_users}
autoStartup: ${rmq_listener_config_auto_startup}
acknowledge-mode: ${rmq_listener_config_ack_mode}
ssl:
enabled: ${rmq_ssl_enabled:true}
keyStore: ${rmq_ssl_keystore}
keyStorePassword: ${rmq_ssl_keystore_password}
trustStore: ${rmq_ssl_truststore}
trustStorePassword: ${rmq_ssl_truststore_password}
With this configuration when I try to start the application it throws below exception.
org.springframework.amqp.rabbit.listener.exception.FatalListenerStartupException: Authentication failure
at org.springframework.amqp.rabbit.listener.BlockingQueueConsumer.start(BlockingQueueConsumer.java:532)
at org.springframework.amqp.rabbit.listener.SimpleMessageListenerContainer$AsyncMessageProcessingConsumer.run(SimpleMessageListenerContainer.java:1389)
at java.lang.Thread.run(Thread.java:745)
Caused by: org.springframework.amqp.AmqpAuthenticationException: com.rabbitmq.client.AuthenticationFailureException: ACCESS_REFUSED - Login was refused using authentication mechanism PLAIN. For details see the broker logfile.
at org.springframework.amqp.rabbit.support.RabbitExceptionTranslator.convertRabbitAccessException(RabbitExceptionTranslator.java:65)
at org.springframework.amqp.rabbit.connection.AbstractConnectionFactory.createBareConnection(AbstractConnectionFactory.java:368)
at org.springframework.amqp.rabbit.connection.CachingConnectionFactory.createConnection(CachingConnectionFactory.java:565)
at org.springframework.amqp.rabbit.connection.ConnectionFactoryUtils$1.createConnection(ConnectionFactoryUtils.java:90)
at org.springframework.amqp.rabbit.connection.ConnectionFactoryUtils.doGetTransactionalResourceHolder(ConnectionFactoryUtils.java:140)
at org.springframework.amqp.rabbit.connection.ConnectionFactoryUtils.getTransactionalResourceHolder(ConnectionFactoryUtils.java:76)
at org.springframework.amqp.rabbit.listener.BlockingQueueConsumer.start(BlockingQueueConsumer.java:527)
... 2 common frames omitted
Caused by: com.rabbitmq.client.AuthenticationFailureException: ACCESS_REFUSED - Login was refused using authentication mechanism PLAIN. For details see the broker logfile.
at com.rabbitmq.client.impl.AMQConnection.start(AMQConnection.java:342)
at com.rabbitmq.client.ConnectionFactory.newConnection(ConnectionFactory.java:909)
at com.rabbitmq.client.ConnectionFactory.newConnection(ConnectionFactory.java:859)
at com.rabbitmq.client.ConnectionFactory.newConnection(ConnectionFactory.java:799)
at org.springframework.amqp.rabbit.connection.AbstractConnectionFactory.createBareConnection(AbstractConnectionFactory.java:352)
... 7 common frames omitted
While writing producers, I observed the same error which was resolved by setting sasl configurations to EXTERNAL but I could do it then as I was writing configuration beans on my own, here I am trying to use out of the box support from spring.
OK, so here is what i found. There is an open defect on spring-boot which mentions that due to unavailability of configuring sasl while using spring boot, it always uses PLAIN mode of authentication and there is a workaround which made my code work as expected. Below is the configuration class I added.
#Configuration
public class RabbitMQConfig {
#Autowired
private RabbitProperties rabbitProperties;
#Autowired
private CachingConnectionFactory cachingConnectionFactory;
#PostConstruct
public void init() {
if ( rabbitProperties.getSsl().isEnabled() && rabbitProperties.getSsl().getKeyStore() != null ) {
cachingConnectionFactory.getRabbitConnectionFactory().setSaslConfig( DefaultSaslConfig.EXTERNAL );
}
}
}
I'm trying to setup a spring boot batch project that uses a ResourcelessTransactionManager transaction manager using Java Configuration, but I'm having no luck.
The reason I am trying to do this is that I don't want any state persisted, and I'd prefer not to waste memory with hsqldb if I don't want it to begin with. I have an existing Spring Batch project that is not using Spring Boot, and it is working with no persistance and without hsqldb.
I'm using this sample project as the base (but with hsqldb removed), and this other answer as a reference but I keep getting this exception:
Caused by: org.springframework.boot.autoconfigure.jdbc.DataSourceProperties$DataSourceBeanCreationException: Cannot determine embedded database driver class for database type NONE. If you want an embedded database please put a supported one on the classpath. If you have database settings to be loaded from a particular profile you may need to active it (no profiles are currently active).
at org.springframework.boot.autoconfigure.jdbc.DataSourceProperties.determineDriverClassName(DataSourceProperties.java:218) ~[spring-boot-autoconfigure-1.4.0.RELEASE.jar:1.4.0.RELEASE]
at org.springframework.boot.autoconfigure.jdbc.DataSourceConfiguration.createDataSource(DataSourceConfiguration.java:42) ~[spring-boot-autoconfigure-1.4.0.RELEASE.jar:1.4.0.RELEASE]
at org.springframework.boot.autoconfigure.jdbc.DataSourceConfiguration$Tomcat.dataSource(DataSourceConfiguration.java:55) ~[spring-boot-autoconfigure-1.4.0.RELEASE.jar:1.4.0.RELEASE]
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_73]
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) ~[na:1.8.0_73]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) ~[na:1.8.0_73]
at java.lang.reflect.Method.invoke(Unknown Source) ~[na:1.8.0_73]
at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:162) ~[spring-beans-4.3.2.RELEASE.jar:4.3.2.RELEASE]
... 56 common frames omitted
This is what I modified:
#SpringBootApplication
#EnableBatchProcessing
#Configuration
public class SampleBatchApplication {
#Autowired
private JobBuilderFactory jobs;
#Autowired
private StepBuilderFactory steps;
#Bean
protected Tasklet tasklet() {
return new Tasklet() {
#Override
public RepeatStatus execute(StepContribution contribution,
ChunkContext context) {
return RepeatStatus.FINISHED;
}
};
}
#Bean
public Job job() throws Exception {
return this.jobs.get("job").start(step1()).build();
}
#Bean
protected Step step1() throws Exception {
return this.steps.get("step1").tasklet(tasklet()).build();
}
public static void main(String[] args) throws Exception {
// System.exit is common for Batch applications since the exit code can be used to
// drive a workflow
System.exit(SpringApplication
.exit(SpringApplication.run(SampleBatchApplication.class, args)));
}
#Bean
ResourcelessTransactionManager transactionManager() {
return new ResourcelessTransactionManager();
}
#Bean
public JobRepository getJobRepo() throws Exception {
return new MapJobRepositoryFactoryBean(transactionManager()).getObject();
}
}
What do I need to do to make it use the ResourcelessTransactionManager?
EDIT: Added clarity around why I want the ResourcelessTransactionManager to work.
Below are some basic spring boot properties to set up data sources. By looking at driver class , boot can infer your db type and can auto create DataSource bean.
spring.datasource.driver-class-name
spring.datasource.url
spring.datasource.username
spring.datasource.password
spring.datasource.tomcat.max-active
spring.datasource.tomcat.initialSize
spring.datasource.tomcat.maxIdle
Last three properties are for setting up connection pools in container.
Explicit DataSource information is missing and no in-memory database is provided in classpath.
Fix issue by explicitly providing entries in application.properties or by including in-memory db ( H2 , HSQL etc ) in class path.
Your configuration looks OK for not using any data sources ( i.e. if you have configured ResourcelessTransactionManager & MapJobRepository ) as long as you don't use EnableAutoConfiguration but your stack trace indicates usage of Boot with EnableAutoConfiguration.
I guess, selective disabling of data source is not allowed, see question
EDIT: I was able to fix error in your code by adding #SpringBootApplication(exclude={DataSource.class,DataSourceAutoConfiguration.class})
Logs dumped this - after bean creation process,
Exclusions:
org.apache.tomcat.jdbc.pool.DataSource
org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration
Your problem seem to be no data source available in your configuration. Spring Batch needs database so persist its state.
Spring Boot can automatically configure in memory DB if you have some on classpath. Example application you are referring to has HSQL included in POM here: https://github.com/spring-projects/spring-boot/blob/v1.4.0.RELEASE/spring-boot-samples/spring-boot-sample-batch/pom.xml#L26
So to fix your problem, define access to your Database.
Hej,
I am trying to implement OAuth2 in an Application using Spring-Boot. I am struggling with the implementation of the JdbcTokenStore (did I understood this right, that this is to store the Token in the Database?)
My Code looks like this:
#Configuration
#EnableAuthorizationServer
protected static class OAuth2Config extends AuthorizationServerConfigurerAdapter {
#Autowired
private DataSource dataSource;
private TokenStore tokenStore = new JdbcTokenStore(dataSource);
....
#Override
public void configure(OAuth2AuthorizationServerConfigurer oauthServer) throws Exception {
oauthServer.tokenStore(tokenStore).authenticationManager(authenticationManager);
}
Doing this I am getting following error:
Caused by: org.springframework.beans.BeanInstantiationException: Could not instantiate bean class [se.....config.OAuth2ServerConfig$OAuth2Config$$EnhancerBySpringCGLIB$$f6b9ba94]: Constructor threw exception; nested exception is java.lang.IllegalArgumentException: DataSource required
The database connection itself seems to work, at least I can login with user data (username / password) stored in the database when I use InMemoryTokenStore.
Can anyone tell me what I am doing wrong or recommend sources where good examples are for this issue?
Thanks a lot!
That's a basic dependency injection problem (nothing fancy and nothing oauth- or Boot- related). You can't initialize a field from an #Autowired (the wiring takes place after initialization). You need to pull that out into a #PostConstruct or a #Bean.