I have a working prototype Spring Boot application which listens on a Kafka queue. Apart from the configuration in application.yml, all that is required is a MessageListener implementation annotated with #KafkaListener.
Am now introducing Spring Integration, and to do so have configured these beans:
#Bean
public KafkaMessageDrivenChannelAdapter<String, String>
adapter(KafkaMessageListenerContainer<String, String> container) {
KafkaMessageDrivenChannelAdapter<String, String> kafkaMessageDrivenChannelAdapter =
new KafkaMessageDrivenChannelAdapter<>(container);
kafkaMessageDrivenChannelAdapter.setOutputChannel(receiver());
return kafkaMessageDrivenChannelAdapter;
}
#Bean
public KafkaMessageListenerContainer<String, String> container() throws Exception {
ContainerProperties properties = new ContainerProperties(this.topic);
// set more properties
return new KafkaMessageListenerContainer<>(consumerFactory(), properties);
}
#Bean
public ConsumerFactory<String, String> consumerFactory() {
Map<String, Object> props = ...; // set proerties
return new DefaultKafkaConsumerFactory<>(props);
}
The application is not starting, and is throwing this error:
Parameter 1 of method kafkaListenerContainerFactory in org.springframework.boot.autoconfigure.kafka.KafkaAnnotationDrivenConfiguration required a bean of type 'org.springframework.kafka.core.ConsumerFactory' that could not be found.
- Bean method 'kafkaConsumerFactory' in 'KafkaAutoConfiguration' not loaded because #ConditionalOnMissingBean (types: org.springframework.kafka.core.ConsumerFactory; SearchStrategy: all) found bean 'consumerFactory'
Action:
Consider revisiting the conditions above or defining a bean of type 'org.springframework.kafka.core.ConsumerFactory' in your configuration.
This is even though I have defined a ConsumerFactory bean.
Running in debug mode, it is apparent that Boot is loading a KafkaListenerEndpointContainer bean to listen on the broker:
[org.springframework.kafka.KafkaListenerEndpointContainer#0-0-C-1] o.a.k.c.c.internals.AbstractCoordinator : Discovered coordinator localhost:9092 (id: 2147483999 rack: null) for group my_group.
Then:
KafkaAnnotationDrivenConfiguration matched:
- #ConditionalOnClass found required class 'org.springframework.kafka.annotation.EnableKafka'; #ConditionalOnMissingClass did not find unwanted class (OnClassCondition)
KafkaAnnotationDrivenConfiguration#kafkaListenerContainerFactory matched:
- #ConditionalOnMissingBean (names: kafkaListenerContainerFactory; SearchStrategy: all) did not find any beans (OnBeanCondition)
KafkaAnnotationDrivenConfiguration#kafkaListenerContainerFactoryConfigurer matched:
- #ConditionalOnMissingBean (types: org.springframework.boot.autoconfigure.kafka.ConcurrentKafkaListenerContainerFactoryConfigurer; SearchStrategy: all) did not find any beans (OnBeanCondition)
KafkaAnnotationDrivenConfiguration.EnableKafkaConfiguration matched:
- #ConditionalOnMissingBean (names: org.springframework.kafka.config.internalKafkaListenerAnnotationProcessor; SearchStrategy: all) did not find any beans (OnBeanCondition)
KafkaAutoConfiguration matched:
- #ConditionalOnClass found required class 'org.springframework.kafka.core.KafkaTemplate'; #ConditionalOnMissingClass did not find unwanted class (OnClassCondition)
KafkaAutoConfiguration#kafkaProducerFactory matched:
- #ConditionalOnMissingBean (types: org.springframework.kafka.core.ProducerFactory; SearchStrategy: all) did not find any beans (OnBeanCondition)
KafkaAutoConfiguration#kafkaProducerListener matched:
- #ConditionalOnMissingBean (types: org.springframework.kafka.support.ProducerListener; SearchStrategy: all) did not find any beans (OnBeanCondition)
KafkaAutoConfiguration#kafkaTemplate matched:
- #ConditionalOnMissingBean (types: org.springframework.kafka.core.KafkaTemplate; SearchStrategy: all) did not find any beans (OnBeanCondition)
I think what is happening is that the Spring Boot\Kafa auto configuration is clashing with the Spring Integration\Kafka setup. What is the correct way to resolve this?
Thanks
You can either use Boot's Consumer factory...
#Bean
public KafkaMessageListenerContainer<String, String> container(ConsumerFactory<String, String> cf) {
...
}
Or disable kafka auto configuration
#SpringBootApplication(exclude = KafkaAutoConfiguration.class)
Related
I have a springboot application using spring security and keycloak. when executing the application, securing with jwt tokens works as expected.
then i have a seperate test application.yml where i try to disable keycloak, as found in tutorials in the web.
for webmvc tests, this does not work as expected. although i try to disable everything security and keycloak related, still KeycloakWebSecurityConfigurerAdapter tries to use the KeycloakConfigResolver class, not finding it.
it then falls back to load the keycloak.json file and fails.
what do i have to make MockMvc tests work? i just want to have every request permitted as implemented in the configure HttpSecurity method. keycloak basically shouldnt be used for mockmvc tests.
pom:
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.7.4-SNAPSHOT</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
[...]
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
</dependency>
<dependency>
<groupId>org.keycloak</groupId>
<artifactId>keycloak-spring-boot-starter</artifactId>
<version>19.0.2</version>
</dependency>
Config:
keycloak:
enabled: false
realm: mock
resource: mock
auth-server-url: http://mock
bearer-only: true
credentials:
secret: mock
spring:
autoconfigure:
exclude: org.keycloak.adapters.springboot.KeycloakAutoConfiguration
Keycloak Bean Configuration:
#Configuration
#EnableWebSecurity
#ConditionalOnProperty(name = ["keycloak.enabled"], havingValue = "false", matchIfMissing = false)
class KeycloakDisabledConfig: KeycloakWebSecurityConfigurerAdapter(){
override fun configure(http: HttpSecurity) {
http.csrf()
.disable()
.authorizeRequests()
.anyRequest()
.permitAll()
}
override fun configure(web: WebSecurity) {
web.ignoring().antMatchers("/**")
}
override fun sessionAuthenticationStrategy(): SessionAuthenticationStrategy = RegisterSessionAuthenticationStrategy(
SessionRegistryImpl()
)
Test:
#WebMvcTest(value = [OrganizationController::class], excludeAutoConfiguration = [SecurityAutoConfiguration::class])
#AutoConfigureMockMvc(addFilters = false)
#Import(value = [
OrganizationMapper::class
])
internal class OrganizationControllerTest{
#Autowired
lateinit var mockmvc: MockMvc
loaded context:
Positive matches:
-----------------
ErrorMvcAutoConfiguration matched:
- #ConditionalOnClass found required classes 'javax.servlet.Servlet', 'org.springframework.web.servlet.DispatcherServlet' (OnClassCondition)
- found 'session' scope (OnWebApplicationCondition)
ErrorMvcAutoConfiguration#basicErrorController matched:
- #ConditionalOnMissingBean (types: org.springframework.boot.web.servlet.error.ErrorController; SearchStrategy: current) did not find any beans (OnBeanCondition)
ErrorMvcAutoConfiguration#errorAttributes matched:
- #ConditionalOnMissingBean (types: org.springframework.boot.web.servlet.error.ErrorAttributes; SearchStrategy: current) did not find any beans (OnBeanCondition)
ErrorMvcAutoConfiguration.WhitelabelErrorViewConfiguration matched:
- #ConditionalOnProperty (server.error.whitelabel.enabled) matched (OnPropertyCondition)
- ErrorTemplate Missing did not find error template view (ErrorMvcAutoConfiguration.ErrorTemplateMissingCondition)
ErrorMvcAutoConfiguration.WhitelabelErrorViewConfiguration#beanNameViewResolver matched:
- #ConditionalOnMissingBean (types: org.springframework.web.servlet.view.BeanNameViewResolver; SearchStrategy: all) did not find any beans (OnBeanCondition)
ErrorMvcAutoConfiguration.WhitelabelErrorViewConfiguration#defaultErrorView matched:
- #ConditionalOnMissingBean (names: error; SearchStrategy: all) did not find any beans (OnBeanCondition)
GsonAutoConfiguration matched:
- #ConditionalOnClass found required class 'com.google.gson.Gson' (OnClassCondition)
GsonAutoConfiguration#gson matched:
- #ConditionalOnMissingBean (types: com.google.gson.Gson; SearchStrategy: all) did not find any beans (OnBeanCondition)
GsonAutoConfiguration#gsonBuilder matched:
- #ConditionalOnMissingBean (types: com.google.gson.GsonBuilder; SearchStrategy: all) did not find any beans (OnBeanCondition)
GsonHttpMessageConvertersConfiguration matched:
- #ConditionalOnClass found required class 'com.google.gson.Gson' (OnClassCondition)
HttpEncodingAutoConfiguration matched:
- #ConditionalOnClass found required class 'org.springframework.web.filter.CharacterEncodingFilter' (OnClassCondition)
- found 'session' scope (OnWebApplicationCondition)
- #ConditionalOnProperty (server.servlet.encoding.enabled) matched (OnPropertyCondition)
HttpEncodingAutoConfiguration#characterEncodingFilter matched:
- #ConditionalOnMissingBean (types: org.springframework.web.filter.CharacterEncodingFilter; SearchStrategy: all) did not find any beans (OnBeanCondition)
HttpMessageConvertersAutoConfiguration matched:
- #ConditionalOnClass found required class 'org.springframework.http.converter.HttpMessageConverter' (OnClassCondition)
- NoneNestedConditions 0 matched 1 did not; NestedCondition on HttpMessageConvertersAutoConfiguration.NotReactiveWebApplicationCondition.ReactiveWebApplication did not find reactive web application classes (HttpMessageConvertersAutoConfiguration.NotReactiveWebApplicationCondition)
HttpMessageConvertersAutoConfiguration#messageConverters matched:
- #ConditionalOnMissingBean (types: org.springframework.boot.autoconfigure.http.HttpMessageConverters; SearchStrategy: all) did not find any beans (OnBeanCondition)
HttpMessageConvertersAutoConfiguration.StringHttpMessageConverterConfiguration matched:
- #ConditionalOnClass found required class 'org.springframework.http.converter.StringHttpMessageConverter' (OnClassCondition)
HttpMessageConvertersAutoConfiguration.StringHttpMessageConverterConfiguration#stringHttpMessageConverter matched:
- #ConditionalOnMissingBean (types: org.springframework.http.converter.StringHttpMessageConverter; SearchStrategy: all) did not find any beans (OnBeanCondition)
JacksonAutoConfiguration matched:
- #ConditionalOnClass found required class 'com.fasterxml.jackson.databind.ObjectMapper' (OnClassCondition)
JacksonAutoConfiguration.Jackson2ObjectMapperBuilderCustomizerConfiguration matched:
- #ConditionalOnClass found required class 'org.springframework.http.converter.json.Jackson2ObjectMapperBuilder' (OnClassCondition)
JacksonAutoConfiguration.JacksonObjectMapperBuilderConfiguration matched:
- #ConditionalOnClass found required class 'org.springframework.http.converter.json.Jackson2ObjectMapperBuilder' (OnClassCondition)
JacksonAutoConfiguration.JacksonObjectMapperBuilderConfiguration#jacksonObjectMapperBuilder matched:
- #ConditionalOnMissingBean (types: org.springframework.http.converter.json.Jackson2ObjectMapperBuilder; SearchStrategy: all) did not find any beans (OnBeanCondition)
JacksonAutoConfiguration.JacksonObjectMapperConfiguration matched:
- #ConditionalOnClass found required class 'org.springframework.http.converter.json.Jackson2ObjectMapperBuilder' (OnClassCondition)
JacksonAutoConfiguration.JacksonObjectMapperConfiguration#jacksonObjectMapper matched:
- #ConditionalOnMissingBean (types: com.fasterxml.jackson.databind.ObjectMapper; SearchStrategy: all) did not find any beans (OnBeanCondition)
JacksonAutoConfiguration.ParameterNamesModuleConfiguration matched:
- #ConditionalOnClass found required class 'com.fasterxml.jackson.module.paramnames.ParameterNamesModule' (OnClassCondition)
JacksonAutoConfiguration.ParameterNamesModuleConfiguration#parameterNamesModule matched:
- #ConditionalOnMissingBean (types: com.fasterxml.jackson.module.paramnames.ParameterNamesModule; SearchStrategy: all) did not find any beans (OnBeanCondition)
JacksonHttpMessageConvertersConfiguration.MappingJackson2HttpMessageConverterConfiguration matched:
- #ConditionalOnClass found required class 'com.fasterxml.jackson.databind.ObjectMapper' (OnClassCondition)
- #ConditionalOnProperty (spring.mvc.converters.preferred-json-mapper=jackson) matched (OnPropertyCondition)
- #ConditionalOnBean (types: com.fasterxml.jackson.databind.ObjectMapper; SearchStrategy: all) found bean 'jacksonObjectMapper' (OnBeanCondition)
JacksonHttpMessageConvertersConfiguration.MappingJackson2HttpMessageConverterConfiguration#mappingJackson2HttpMessageConverter matched:
- #ConditionalOnMissingBean (types: org.springframework.http.converter.json.MappingJackson2HttpMessageConverter ignored: org.springframework.hateoas.server.mvc.TypeConstrainedMappingJackson2HttpMessageConverter,org.springframework.data.rest.webmvc.alps.AlpsJsonHttpMessageConverter; SearchStrategy: all) did not find any beans (OnBeanCondition)
KeycloakDisabledConfig matched:
- #ConditionalOnProperty (keycloak.enabled=false) matched (OnPropertyCondition)
MockMvcAutoConfiguration matched:
- found 'session' scope (OnWebApplicationCondition)
MockMvcAutoConfiguration#dispatcherServlet matched:
- #ConditionalOnMissingBean (types: org.springframework.web.servlet.DispatcherServlet; SearchStrategy: all) did not find any beans (OnBeanCondition)
MockMvcAutoConfiguration#dispatcherServletPath matched:
- #ConditionalOnMissingBean (types: org.springframework.boot.autoconfigure.web.servlet.DispatcherServletPath; SearchStrategy: all) did not find any beans (OnBeanCondition)
MockMvcAutoConfiguration#mockMvc matched:
- #ConditionalOnMissingBean (types: org.springframework.test.web.servlet.MockMvc; SearchStrategy: all) did not find any beans (OnBeanCondition)
MockMvcAutoConfiguration#mockMvcBuilder matched:
- #ConditionalOnMissingBean (types: org.springframework.test.web.servlet.MockMvcBuilder; SearchStrategy: all) did not find any beans (OnBeanCondition)
NoOpCacheConfiguration matched:
- Cache org.springframework.boot.autoconfigure.cache.NoOpCacheConfiguration NONE cache type (CacheCondition)
SecurityFilterAutoConfiguration matched:
- #ConditionalOnClass found required classes 'org.springframework.security.web.context.AbstractSecurityWebApplicationInitializer', 'org.springframework.security.config.http.SessionCreationPolicy' (OnClassCondition)
- found 'session' scope (OnWebApplicationCondition)
SecurityFilterAutoConfiguration#securityFilterChainRegistration matched:
- #ConditionalOnBean (names: springSecurityFilterChain; SearchStrategy: all) found bean 'springSecurityFilterChain' (OnBeanCondition)
SpringDataWebAutoConfiguration matched:
- #ConditionalOnClass found required classes 'org.springframework.data.web.PageableHandlerMethodArgumentResolver', 'org.springframework.web.servlet.config.annotation.WebMvcConfigurer' (OnClassCondition)
- found 'session' scope (OnWebApplicationCondition)
- #ConditionalOnMissingBean (types: org.springframework.data.web.PageableHandlerMethodArgumentResolver; SearchStrategy: all) did not find any beans (OnBeanCondition)
SpringDataWebAutoConfiguration#pageableCustomizer matched:
- #ConditionalOnMissingBean (types: org.springframework.data.web.config.PageableHandlerMethodArgumentResolverCustomizer; SearchStrategy: all) did not find any beans (OnBeanCondition)
SpringDataWebAutoConfiguration#sortCustomizer matched:
- #ConditionalOnMissingBean (types: org.springframework.data.web.config.SortHandlerMethodArgumentResolverCustomizer; SearchStrategy: all) did not find any beans (OnBeanCondition)
TaskExecutionAutoConfiguration matched:
- #ConditionalOnClass found required class 'org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor' (OnClassCondition)
TaskExecutionAutoConfiguration#applicationTaskExecutor matched:
- #ConditionalOnMissingBean (types: java.util.concurrent.Executor; SearchStrategy: all) did not find any beans (OnBeanCondition)
TaskExecutionAutoConfiguration#taskExecutorBuilder matched:
- #ConditionalOnMissingBean (types: org.springframework.boot.task.TaskExecutorBuilder; SearchStrategy: all) did not find any beans (OnBeanCondition)
UserDetailsServiceAutoConfiguration matched:
- #ConditionalOnClass found required class 'org.springframework.security.authentication.AuthenticationManager' (OnClassCondition)
- #ConditionalOnBean (types: org.springframework.security.config.annotation.ObjectPostProcessor; SearchStrategy: all) found bean 'objectPostProcessor'; #ConditionalOnMissingBean (types: org.springframework.security.authentication.AuthenticationManager,org.springframework.security.authentication.AuthenticationProvider,org.springframework.security.core.userdetails.UserDetailsService,org.springframework.security.authentication.AuthenticationManagerResolver,org.springframework.security.oauth2.jwt.JwtDecoder,org.springframework.security.oauth2.server.resource.introspection.OpaqueTokenIntrospector,org.springframework.security.oauth2.client.registration.ClientRegistrationRepository,org.springframework.security.saml2.provider.service.registration.RelyingPartyRegistrationRepository; SearchStrategy: all) did not find any beans (OnBeanCondition)
ValidationAutoConfiguration matched:
- #ConditionalOnClass found required class 'javax.validation.executable.ExecutableValidator' (OnClassCondition)
- #ConditionalOnResource found location classpath:META-INF/services/javax.validation.spi.ValidationProvider (OnResourceCondition)
ValidationAutoConfiguration#defaultValidator matched:
- #ConditionalOnMissingBean (types: javax.validation.Validator; SearchStrategy: all) did not find any beans (OnBeanCondition)
ValidationAutoConfiguration#methodValidationPostProcessor matched:
- #ConditionalOnMissingBean (types: org.springframework.validation.beanvalidation.MethodValidationPostProcessor; SearchStrategy: current) did not find any beans (OnBeanCondition)
WebMvcAutoConfiguration matched:
- #ConditionalOnClass found required classes 'javax.servlet.Servlet', 'org.springframework.web.servlet.DispatcherServlet', 'org.springframework.web.servlet.config.annotation.WebMvcConfigurer' (OnClassCondition)
- found 'session' scope (OnWebApplicationCondition)
- #ConditionalOnMissingBean (types: org.springframework.web.servlet.config.annotation.WebMvcConfigurationSupport; SearchStrategy: all) did not find any beans (OnBeanCondition)
WebMvcAutoConfiguration#formContentFilter matched:
- #ConditionalOnProperty (spring.mvc.formcontent.filter.enabled) matched (OnPropertyCondition)
- #ConditionalOnMissingBean (types: org.springframework.web.filter.FormContentFilter; SearchStrategy: all) did not find any beans (OnBeanCondition)
WebMvcAutoConfiguration.EnableWebMvcConfiguration#flashMapManager matched:
- #ConditionalOnMissingBean (names: flashMapManager; SearchStrategy: all) did not find any beans (OnBeanCondition)
WebMvcAutoConfiguration.EnableWebMvcConfiguration#localeResolver matched:
- #ConditionalOnMissingBean (names: localeResolver; SearchStrategy: all) did not find any beans (OnBeanCondition)
WebMvcAutoConfiguration.EnableWebMvcConfiguration#themeResolver matched:
- #ConditionalOnMissingBean (names: themeResolver; SearchStrategy: all) did not find any beans (OnBeanCondition)
WebMvcAutoConfiguration.WebMvcAutoConfigurationAdapter#defaultViewResolver matched:
- #ConditionalOnMissingBean (types: org.springframework.web.servlet.view.InternalResourceViewResolver; SearchStrategy: all) did not find any beans (OnBeanCondition)
WebMvcAutoConfiguration.WebMvcAutoConfigurationAdapter#requestContextFilter matched:
- #ConditionalOnMissingBean (types: org.springframework.web.context.request.RequestContextListener,org.springframework.web.filter.RequestContextFilter; SearchStrategy: all) did not find any beans (OnBeanCondition)
WebMvcAutoConfiguration.WebMvcAutoConfigurationAdapter#viewResolver matched:
- #ConditionalOnBean (types: org.springframework.web.servlet.ViewResolver; SearchStrategy: all) found beans 'defaultViewResolver', 'beanNameViewResolver', 'mvcViewResolver'; #ConditionalOnMissingBean (names: viewResolver types: org.springframework.web.servlet.view.ContentNegotiatingViewResolver; SearchStrategy: all) did not find any beans (OnBeanCondition)
Stacktrace:
Caused by: java.io.FileNotFoundException: Unable to locate Keycloak configuration file: keycloak.json
at org.keycloak.adapters.springsecurity.AdapterDeploymentContextFactoryBean.loadKeycloakDeployment(AdapterDeploymentContextFactoryBean.java:83) ~[keycloak-spring-security-adapter-19.0.1.jar:19.0.1]
at org.keycloak.adapters.springsecurity.AdapterDeploymentContextFactoryBean.afterPropertiesSet(AdapterDeploymentContextFactoryBean.java:76) ~[keycloak-spring-security-adapter-19.0.1.jar:19.0.1]
at org.keycloak.adapters.springsecurity.config.KeycloakWebSecurityConfigurerAdapter.adapterDeploymentContext(KeycloakWebSecurityConfigurerAdapter.java:72) ~[keycloak-spring-security-adapter-19.0.1.jar:19.0.1]
at com.jschausberger.demo.keycloak.KeycloakDisabledConfig$$EnhancerBySpringCGLIB$$ef3c2204.CGLIB$adapterDeploymentContext$13(<generated>) ~[classes/:na]
at com.jschausberger.demo.keycloak.KeycloakDisabledConfig$$EnhancerBySpringCGLIB$$ef3c2204$$FastClassBySpringCGLIB$$3c55188.invoke(<generated>) ~[classes/:na]
at org.springframework.cglib.proxy.MethodProxy.invokeSuper(MethodProxy.java:244) ~[spring-core-5.3.23.jar:5.3.23]
at org.springframework.context.annotation.ConfigurationClassEnhancer$BeanMethodInterceptor.intercept(ConfigurationClassEnhancer.java:331) ~[spring-context-5.3.23.jar:5.3.23]
at com.jschausberger.demo.keycloak.KeycloakDisabledConfig$$EnhancerBySpringCGLIB$$ef3c2204.adapterDeploymentContext(<generated>) ~[classes/:na]
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:na]
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77) ~[na:na]
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:na]
at java.base/java.lang.reflect.Method.invoke(Method.java:568) ~[na:na]
at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:154) ~[spring-beans-5.3.23.jar:5.3.23]
... 91 common frames omitted
First, do not use Keycloak adapter for Spring (keycloak-spring-boot-starter). It is very deprecated and not compatible with spring-boot 3 (RC1 this week, release in November). Use spring-boot-starter-oauth2-resource-server instead. Article here, more tutorials there.
Second, do not disable security in your unit-test. Use mocked authentication and use it to unit-test your security rules. You might refer to article and tutorials linked above to figure out how.
I recently added Spring-data to my project and then I found that in my REST controllers, my models provided by clients were no longer being automatically serialized from JSON. How can I fix this?
I added:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-mongodb</artifactId>
</dependency>
and now the User param isn't having it's String arg constructor called and u is null!
#PostMapping()
#ResponseBody
public User createUser(HttpServletRequest request, #RequestParam("user") User u) {
log.info("Got user! " + u);
users.save(u);
Optional<User> found = users.findById(u.getEmail());
log.info("Saved user!! ");
return found.get();
}
If you build your .war with spring-data, run java -jar <path-to-war> --debug and then build it/run it without spring-data and diff the outputs, you can see that the following beans are included when spring-data is added.
SpringDataWebAutoConfiguration matched:
- #ConditionalOnClass found required classes 'org.springframework.data.web.PageableHandlerMethodArgumentResolver', 'org.springframework.web.servlet.config.annotation.WebMvcConfigurer' (OnClassCondition)
- found ConfigurableWebEnvironment (OnWebApplicationCondition)
- #ConditionalOnMissingBean (types: org.springframework.data.web.PageableHandlerMethodArgumentResolver; SearchStrategy: all) did not find any beans (OnBeanCondition)
SpringDataWebAutoConfiguration#pageableCustomizer matched:
- #ConditionalOnMissingBean (types: org.springframework.data.web.config.PageableHandlerMethodArgumentResolverCustomizer; SearchStrategy: all) did not find any beans (OnBeanCondition)
SpringDataWebAutoConfiguration#sortCustomizer matched:
- #ConditionalOnMissingBean (types: org.springframework.data.web.config.SortHandlerMethodArgumentResolverCustomizer; SearchStrategy: all) did not find any beans (OnBeanCondition)
This is because Spring data exposes REST controllers that link to your data repositories as mentioned here: http://spring.io/projects/spring-data-rest and this breaks the default auto-configurations for serializing objects passed to REST controllers.
Simply exclude the auto configuration and your existing auto serialization will work:
#SpringBootApplication(exclude = { SpringDataWebAutoConfiguration.class })
public class MyApplication{
public static void main(String[] args) {
SpringApplication.run(MyApplication.class, args);
}
}
I have a problem with Spring Boot version 2.0.1.RELEASE (in Spring Boot 2.0.0.RELEASE the below configuration worked nice).
Could somebody help me out please why this configuration is not working?
I have this configuration and this config did not match the ConditionalOnBean condition.
The AutoConfigureOrder / Order / AutoConfigureAfter seems that doesn't have any effect.
#Configuration
#ConditionalOnClass({DataSource.class, JpaRepository.class})
#ConditionalOnBean(DataSource.class)
#AutoConfigureAfter(DataSourceAutoConfiguration.class)
#ConditionalOnProperty(prefix = "spring.data.jpa.repositories", name = "enabled", havingValue = "true", matchIfMissing = true)
#AutoConfigureOrder(LOWEST_PRECEDENCE)
#Order(LOWEST_PRECEDENCE)
public class MyJpaAuditAutoConfiguration {
#ConditionalOnMissingBean
#Bean
public MyTransactionHelper transactionHelper() {
return new MyTransactionHelper();
}
}
In spring.factories I have:
org.springframework.boot.autoconfigure.EnableAutoConfiguration=org.example.MyJpaAuditAutoConfiguration
Application start output for this configuration:
DataSourceAutoConfiguration matched:
- #ConditionalOnClass found required classes 'javax.sql.DataSource', 'org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseType'; #ConditionalOnMissingClass did not find unwanted class (OnClassCondition)
...
JpaAuditAutoConfiguration:
Did not match:
- #ConditionalOnBean (types: javax.sql.DataSource; SearchStrategy: all) did not find any beans of type javax.sql.DataSource (OnBeanCondition)
Matched:
- #ConditionalOnClass found required classes 'javax.sql.DataSource', 'org.springframework.data.jpa.repository.JpaRepository'; #ConditionalOnMissingClass did not find unwanted class (OnClassCondition)
- #ConditionalOnProperty (spring.data.jpa.repositories.enabled=true) matched (OnPropertyCondition)
In my opinion, the config class is evaluated before DataSourceAutoConfiguration and that's the reason why the bean cannot be found.
Other configs like DataSourceHealthIndicatorAutoConfiguration found the bean.
DataSourceHealthIndicatorAutoConfiguration matched:
- #ConditionalOnClass found required classes 'org.springframework.jdbc.core.JdbcTemplate', 'org.springframework.jdbc.datasource.lookup.AbstractRoutingDataSource'; #ConditionalOnMissingClass did not find unwanted class (OnClassCondition)
- #ConditionalOnEnabledHealthIndicator management.health.defaults.enabled is considered true (OnEnabledHealthIndicatorCondition)
- #ConditionalOnBean (types: javax.sql.DataSource; SearchStrategy: all) found bean 'dataSource' (OnBeanCondition)
After spring boot upgrade to version 2.1.2.RELEASE it was solved automatically.
(I renamed some classes in the answer)
So in Spring Boot version 2.1.2.RELEASE:
#Configuration
#ConditionalOnBean(DataSource.class)
#ConditionalOnClass({DataSource.class, JpaRepository.class})
#ConditionalOnProperty(prefix = "spring.data.jpa.repositories", name = "enabled", havingValue = "true", matchIfMissing = true)
#AutoConfigureAfter(DataSourceAutoConfiguration.class)
public class JpaTransactionHelperAutoConfiguration {
#ConditionalOnMissingBean
#Bean
public TransactionHelper transactionHelper() {
return new TransactionHelper();
}
}
NOTE: by removing the #AutoConfigureAfter(DataSourceAutoConfiguration.class) it won't work in Spring Boot version 2.1.2.RELEASE.
In Spring Boot version 2.0.1.RELEASE I just removed the ConditionalOnBean annotation:
#Configuration
#ConditionalOnClass({DataSource.class, JpaRepository.class})
#ConditionalOnProperty(prefix = "spring.data.jpa.repositories", name = "enabled", havingValue = "true", matchIfMissing = true)
#AutoConfigureAfter(DataSourceAutoConfiguration.class)
public class JpaTransactionHelperAutoConfiguration {
#ConditionalOnMissingBean
#Bean
public TransactionHelper transactionHelper() {
return new TransactionHelper();
}
}
Using spring boot 2.0.0.M5 with web starter and flywaydb on the classpath.
The auto-configuration debug output on one hand shows there's a data source configured as expected:
DataSourceAutoConfiguration matched:
- #ConditionalOnClass found required classes 'javax.sql.DataSource', 'org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseType'; #ConditionalOnMissingClass did not find unwanted class (OnClassCondition)
DataSourceAutoConfiguration.PooledDataSourceConfiguration matched:
- AnyNestedCondition 1 matched 1 did not; NestedCondition on DataSourceAutoConfiguration.PooledDataSourceCondition.PooledDataSourceAvailable PooledDataSource found supported DataSource; NestedCondition on DataSourceAutoConfiguration.PooledDataSourceCondition.ExplicitType #ConditionalOnProperty (spring.datasource.type) did not find property 'type' (DataSourceAutoConfiguration.PooledDataSourceCondition)
- #ConditionalOnMissingBean (types: javax.sql.DataSource,javax.sql.XADataSource; SearchStrategy: all) did not find any beans (OnBeanCondition)
DataSourceConfiguration.Hikari matched:
- #ConditionalOnClass found required class 'com.zaxxer.hikari.HikariDataSource'; #ConditionalOnMissingClass did not find unwanted class (OnClassCondition)
- #ConditionalOnProperty (spring.datasource.type=com.zaxxer.hikari.HikariDataSource) matched (OnPropertyCondition)
On the other hand, the auto-config fails to configure FlywayAutoConfiguration due to "missing (?!)" data source:
FlywayAutoConfiguration:
Did not match:
- #ConditionalOnBean (types: javax.sql.DataSource; SearchStrategy: all) did not find any beans of type javax.sql.DataSource (OnBeanCondition)
Matched:
- #ConditionalOnClass found required class 'org.flywaydb.core.Flyway'; #ConditionalOnMissingClass did not find unwanted class (OnClassCondition)
- #ConditionalOnProperty (spring.flyway.enabled) matched (OnPropertyCondition)
Any suggestions how to fix (or at least further debug) this will be greatly appreciated!
Same problem with Spring Boot 2.0.2.
I don't really why it don't see it, but when manually instanciating the dataSource fixed it :
#Bean
public DataSource dataSource(//
#Value("${spring.datasource.url}") String url, //
#Value("${spring.datasource.username}") String username, //
#Value("${spring.datasource.password}") String password, //
#Value("${spring.datasource.driver-class}") String driver, //
#Value("${spring.datasource.hikari.connection-timeout:30}") Long timeout, //
#Value("${spring.datasource.hikari.maximum-pool-size:20}") Integer maxPoolSize ) {
HikariConfig config = new HikariConfig();
config.setJdbcUrl(url);
config.setUsername(username);
config.setPassword(password);
config.setDriverClassName(driver);
config.setConnectionTimeout(timeout);
config.setMaximumPoolSize(maxPoolSize);
return new HikariDataSource(config);
}
To make flyway migration work on spring boot application start you need following:
build.gradle
implementation 'org.springframework.boot:spring-boot-starter-jooq'
implementation 'org.flywaydb:flyway-core'
implementation 'mysql:mysql-connector-java'
application.yml:
spring:
datasource:
password: mypass
url: jdbc:mysql://localhost:3306/database
username: myuser
driver-class-name: com.mysql.cj.jdbc.Driver
src/main/resources/db/migration/V1_1_0__my_first_migration.sql
CREATE TABLE IF NOT EXISTS `employee` (
`id` int NOT NULL AUTO_INCREMENT PRIMARY KEY,
`name` varchar(20),
`email` varchar(50),
`date_of_birth` timestamp
)ENGINE=InnoDB DEFAULT CHARSET=UTF8;
Jooq brings in dependencies such spring-boot-starter-jdbc and com.zaxxer:HikariCP (connection pooling), this makes spring detect datasource and inject flyway initialisation.
The setup:
a JPA ReviewRepository extending CrudRepository<TEntity, TId>
My test uses the slice test annotation #DataJpaTest
My test #Autowired ReviewRepository repo
The problem:
My #Autowired fails and raises a NoSuchBeanDefinitionException saying that there is no Bean qualified to be injected into my ReviewRepository repo field.
Things I've tried:
With and without #ContextConfiguration(classes = AppEntry.class)
With and without #EnableJpaRepositories in my AppEntry class
The Error:
Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 'boxfish.apis.youtube.channelDiscovery.reviews.domain.reviews.ReviewRepository' available: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: {#org.springframework.beans.factory.annotation.Autowired(required=true)}
at org.springframework.beans.factory.support.DefaultListableBeanFactory.raiseNoMatchingBeanFound(DefaultListableBeanFactory.java:1486)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1104)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:1066)
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:585)
Code for ReviewRepositoryTest.java
#RunWith(SpringJUnit4ClassRunner.class)
#ContextConfiguration(classes = AppEntry.class)
#ActiveProfiles(INTEGRATION)
#DataJpaTest
#AutoConfigureTestDatabase(replace = NONE)
#Transactional
public class ReviewRepositoryTest {
#Autowired
private ReviewRepository repo;
#Test
public void findOneByExpansionIdAndPartIdInAndType() {
assertTrue(true);
}
}
Code for ReviewRepository.java
public interface ReviewRepository extends CrudRepository<ReviewEntity, ReviewEntityId> {
}
Code for AppEntry.java
#SpringBootApplication
#EnableJpaRepositories
public class AppEntry {
public static void main(final String[] args) {
SpringApplication.run(AppEntry.class, args);
}
}
Spring Boot Auto Configuration Report
=========================
AUTO-CONFIGURATION REPORT
=========================
Positive matches:
-----------------
DataSourceAutoConfiguration matched:
- #ConditionalOnClass found required classes 'javax.sql.DataSource', 'org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseType'; #ConditionalOnMissingClass did not find unwanted class (OnClassCondition)
DataSourceAutoConfiguration#dataSourceInitializer matched:
- #ConditionalOnMissingBean (types: org.springframework.boot.autoconfigure.jdbc.DataSourceInitializer; SearchStrategy: all) did not find any beans (OnBeanCondition)
DataSourceAutoConfiguration.PooledDataSourceConfiguration matched:
- AnyNestedCondition 1 matched 1 did not; NestedCondition on DataSourceAutoConfiguration.PooledDataSourceCondition.PooledDataSourceAvailable PooledDataSource found supported DataSource; NestedCondition on DataSourceAutoConfiguration.PooledDataSourceCondition.ExplicitType #ConditionalOnProperty (spring.datasource.type) did not find property 'type' (DataSourceAutoConfiguration.PooledDataSourceCondition)
- #ConditionalOnMissingBean (types: javax.sql.DataSource,javax.sql.XADataSource; SearchStrategy: all) did not find any beans (OnBeanCondition)
DataSourceConfiguration.Tomcat matched:
- #ConditionalOnClass found required class 'org.apache.tomcat.jdbc.pool.DataSource'; #ConditionalOnMissingClass did not find unwanted class (OnClassCondition)
- #ConditionalOnProperty (spring.datasource.type=org.apache.tomcat.jdbc.pool.DataSource) matched (OnPropertyCondition)
DataSourcePoolMetadataProvidersConfiguration.TomcatDataSourcePoolMetadataProviderConfiguration matched:
- #ConditionalOnClass found required class 'org.apache.tomcat.jdbc.pool.DataSource'; #ConditionalOnMissingClass did not find unwanted class (OnClassCondition)
DataSourceTransactionManagerAutoConfiguration matched:
- #ConditionalOnClass found required classes 'org.springframework.jdbc.core.JdbcTemplate', 'org.springframework.transaction.PlatformTransactionManager'; #ConditionalOnMissingClass did not find unwanted class (OnClassCondition)
DataSourceTransactionManagerAutoConfiguration.DataSourceTransactionManagerConfiguration matched:
- #ConditionalOnSingleCandidate (types: javax.sql.DataSource; SearchStrategy: all) found a primary bean from beans 'dataSource' (OnBeanCondition)
DataSourceTransactionManagerAutoConfiguration.TransactionManagementConfiguration matched:
- #ConditionalOnMissingBean (types: org.springframework.transaction.annotation.AbstractTransactionManagementConfiguration; SearchStrategy: all) did not find any beans (OnBeanCondition)
FlywayAutoConfiguration matched:
- #ConditionalOnClass found required class 'org.flywaydb.core.Flyway'; #ConditionalOnMissingClass did not find unwanted class (OnClassCondition)
- #ConditionalOnProperty (flyway.enabled) matched (OnPropertyCondition)
- #ConditionalOnBean (types: javax.sql.DataSource; SearchStrategy: all) found bean 'dataSource' (OnBeanCondition)
FlywayAutoConfiguration.FlywayConfiguration matched:
- #ConditionalOnMissingBean (types: org.flywaydb.core.Flyway; SearchStrategy: all) did not find any beans (OnBeanCondition)
FlywayAutoConfiguration.FlywayConfiguration#flywayInitializer matched:
- #ConditionalOnMissingBean (types: org.springframework.boot.autoconfigure.flyway.FlywayMigrationInitializer; SearchStrategy: all) did not find any beans (OnBeanCondition)
FlywayAutoConfiguration.FlywayConfiguration.FlywayInitializerJpaDependencyConfiguration matched:
- #ConditionalOnClass found required class 'org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean'; #ConditionalOnMissingClass did not find unwanted class (OnClassCondition)
- #ConditionalOnBean (types: org.springframework.orm.jpa.AbstractEntityManagerFactoryBean; SearchStrategy: all) found bean '&entityManagerFactory' (OnBeanCondition)
FlywayAutoConfiguration.FlywayJpaDependencyConfiguration matched:
- #ConditionalOnClass found required class 'org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean'; #ConditionalOnMissingClass did not find unwanted class (OnClassCondition)
- #ConditionalOnBean (types: org.springframework.orm.jpa.AbstractEntityManagerFactoryBean; SearchStrategy: all) found bean '&entityManagerFactory' (OnBeanCondition)
HibernateJpaAutoConfiguration matched:
- #ConditionalOnClass found required classes 'org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean', 'org.springframework.transaction.annotation.EnableTransactionManagement', 'javax.persistence.EntityManager'; #ConditionalOnMissingClass did not find unwanted class (OnClassCondition)
- HibernateEntityManager found class 'org.hibernate.ejb.HibernateEntityManager' (HibernateJpaAutoConfiguration.HibernateEntityManagerCondition)
JdbcTemplateAutoConfiguration matched:
- #ConditionalOnClass found required classes 'javax.sql.DataSource', 'org.springframework.jdbc.core.JdbcTemplate'; #ConditionalOnMissingClass did not find unwanted class (OnClassCondition)
- #ConditionalOnSingleCandidate (types: javax.sql.DataSource; SearchStrategy: all) found a primary bean from beans 'dataSource' (OnBeanCondition)
JdbcTemplateAutoConfiguration#jdbcTemplate matched:
- #ConditionalOnMissingBean (types: org.springframework.jdbc.core.JdbcOperations; SearchStrategy: all) did not find any beans (OnBeanCondition)
JdbcTemplateAutoConfiguration#namedParameterJdbcTemplate matched:
- #ConditionalOnMissingBean (types: org.springframework.jdbc.core.namedparam.NamedParameterJdbcOperations; SearchStrategy: all) did not find any beans (OnBeanCondition)
JpaBaseConfiguration#entityManagerFactory matched:
- #ConditionalOnMissingBean (types: org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean,javax.persistence.EntityManagerFactory; SearchStrategy: all) did not find any beans (OnBeanCondition)
JpaBaseConfiguration#entityManagerFactoryBuilder matched:
- #ConditionalOnMissingBean (types: org.springframework.boot.orm.jpa.EntityManagerFactoryBuilder; SearchStrategy: all) did not find any beans (OnBeanCondition)
JpaBaseConfiguration#jpaVendorAdapter matched:
- #ConditionalOnMissingBean (types: org.springframework.orm.jpa.JpaVendorAdapter; SearchStrategy: all) did not find any beans (OnBeanCondition)
JpaBaseConfiguration#transactionManager matched:
- #ConditionalOnMissingBean (types: org.springframework.transaction.PlatformTransactionManager; SearchStrategy: all) did not find any beans (OnBeanCondition)
NoOpCacheConfiguration matched:
- Cache org.springframework.boot.autoconfigure.cache.NoOpCacheConfiguration NONE cache type (CacheCondition)
TestEntityManagerAutoConfiguration matched:
- #ConditionalOnClass found required class 'javax.persistence.EntityManagerFactory'; #ConditionalOnMissingClass did not find unwanted class (OnClassCondition)
TestEntityManagerAutoConfiguration#testEntityManager matched:
- #ConditionalOnMissingBean (types: org.springframework.boot.test.autoconfigure.orm.jpa.TestEntityManager; SearchStrategy: all) did not find any beans (OnBeanCondition)
TransactionAutoConfiguration matched:
- #ConditionalOnClass found required class 'org.springframework.transaction.PlatformTransactionManager'; #ConditionalOnMissingClass did not find unwanted class (OnClassCondition)
TransactionAutoConfiguration#platformTransactionManagerCustomizers matched:
- #ConditionalOnMissingBean (types: org.springframework.boot.autoconfigure.transaction.TransactionManagerCustomizers; SearchStrategy: all) did not find any beans (OnBeanCondition)
TransactionAutoConfiguration.TransactionTemplateConfiguration matched:
- #ConditionalOnSingleCandidate (types: org.springframework.transaction.PlatformTransactionManager; SearchStrategy: all) found a primary bean from beans 'transactionManager' (OnBeanCondition)
TransactionAutoConfiguration.TransactionTemplateConfiguration#transactionTemplate matched:
- #ConditionalOnMissingBean (types: org.springframework.transaction.support.TransactionTemplate; SearchStrategy: all) did not find any beans (OnBeanCondition)
Negative matches:
-----------------
CacheAutoConfiguration:
Did not match:
- #ConditionalOnBean (types: org.springframework.cache.interceptor.CacheAspectSupport; SearchStrategy: all) did not find any beans (OnBeanCondition)
Matched:
- #ConditionalOnClass found required class 'org.springframework.cache.CacheManager'; #ConditionalOnMissingClass did not find unwanted class (OnClassCondition)
CacheAutoConfiguration.CacheManagerJpaDependencyConfiguration:
Did not match:
- Ancestor org.springframework.boot.autoconfigure.cache.CacheAutoConfiguration did not match (ConditionEvaluationReport.AncestorsMatchedCondition)
Matched:
- #ConditionalOnClass found required class 'org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean'; #ConditionalOnMissingClass did not find unwanted class (OnClassCondition)
CaffeineCacheConfiguration:
Did not match:
- #ConditionalOnClass did not find required classes 'com.github.benmanes.caffeine.cache.Caffeine', 'org.springframework.cache.caffeine.CaffeineCacheManager' (OnClassCondition)
CouchbaseCacheConfiguration:
Did not match:
- #ConditionalOnClass did not find required classes 'com.couchbase.client.java.Bucket', 'com.couchbase.client.spring.cache.CouchbaseCacheManager' (OnClassCondition)
DataSourceAutoConfiguration.EmbeddedDatabaseConfiguration:
Did not match:
- EmbeddedDataSource found supported pooled data source (DataSourceAutoConfiguration.EmbeddedDatabaseCondition)
DataSourceAutoConfiguration.TomcatDataSourceJmxConfiguration:
Did not match:
- #ConditionalOnProperty (spring.datasource.jmx-enabled) did not find property 'jmx-enabled' (OnPropertyCondition)
Matched:
- #ConditionalOnClass found required class 'org.apache.tomcat.jdbc.pool.DataSourceProxy'; #ConditionalOnMissingClass did not find unwanted class (OnClassCondition)
DataSourceConfiguration.Dbcp:
Did not match:
- #ConditionalOnClass did not find required class 'org.apache.commons.dbcp.BasicDataSource' (OnClassCondition)
DataSourceConfiguration.Dbcp2:
Did not match:
- #ConditionalOnClass did not find required class 'org.apache.commons.dbcp2.BasicDataSource' (OnClassCondition)
DataSourceConfiguration.Generic:
Did not match:
- #ConditionalOnProperty (spring.datasource.type) did not find property 'spring.datasource.type' (OnPropertyCondition)
DataSourceConfiguration.Hikari:
Did not match:
- #ConditionalOnClass did not find required class 'com.zaxxer.hikari.HikariDataSource' (OnClassCondition)
DataSourcePoolMetadataProvidersConfiguration.CommonsDbcp2PoolDataSourceMetadataProviderConfiguration:
Did not match:
- #ConditionalOnClass did not find required class 'org.apache.commons.dbcp2.BasicDataSource' (OnClassCondition)
DataSourcePoolMetadataProvidersConfiguration.CommonsDbcpPoolDataSourceMetadataProviderConfiguration:
Did not match:
- #ConditionalOnClass did not find required class 'org.apache.commons.dbcp.BasicDataSource' (OnClassCondition)
DataSourcePoolMetadataProvidersConfiguration.HikariPoolDataSourceMetadataProviderConfiguration:
Did not match:
- #ConditionalOnClass did not find required class 'com.zaxxer.hikari.HikariDataSource' (OnClassCondition)
DataSourceTransactionManagerAutoConfiguration.DataSourceTransactionManagerConfiguration#transactionManager:
Did not match:
- #ConditionalOnMissingBean (types: org.springframework.transaction.PlatformTransactionManager; SearchStrategy: all) found bean 'transactionManager' (OnBeanCondition)
EhCacheCacheConfiguration:
Did not match:
- #ConditionalOnClass did not find required classes 'net.sf.ehcache.Cache', 'org.springframework.cache.ehcache.EhCacheCacheManager' (OnClassCondition)
EurekaDiscoveryClientConfiguration:
Did not match:
- #ConditionalOnProperty (eureka.client.enabled) found different value in property 'eureka.client.enabled' (OnPropertyCondition)
Matched:
- #ConditionalOnClass found required class 'com.netflix.discovery.EurekaClientConfig'; #ConditionalOnMissingClass did not find unwanted class (OnClassCondition)
GenericCacheConfiguration:
Did not match:
- Cache org.springframework.boot.autoconfigure.cache.GenericCacheConfiguration NONE cache type (CacheCondition)
GuavaCacheConfiguration:
Did not match:
- #ConditionalOnClass did not find required class 'org.springframework.cache.guava.GuavaCacheManager' (OnClassCondition)
HazelcastCacheConfiguration:
Did not match:
- #ConditionalOnClass did not find required classes 'com.hazelcast.core.HazelcastInstance', 'com.hazelcast.spring.cache.HazelcastCacheManager' (OnClassCondition)
InfinispanCacheConfiguration:
Did not match:
- #ConditionalOnClass did not find required class 'org.infinispan.spring.provider.SpringEmbeddedCacheManager' (OnClassCondition)
JCacheCacheConfiguration:
Did not match:
- #ConditionalOnClass did not find required classes 'javax.cache.Caching', 'org.springframework.cache.jcache.JCacheCacheManager' (OnClassCondition)
JpaBaseConfiguration.JpaWebConfiguration:
Did not match:
- #ConditionalOnWebApplication (required) not a web application (OnWebApplicationCondition)
Matched:
- #ConditionalOnClass found required class 'org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter'; #ConditionalOnMissingClass did not find unwanted class (OnClassCondition)
JpaRepositoriesAutoConfiguration:
Did not match:
- #ConditionalOnMissingBean (types: org.springframework.data.jpa.repository.support.JpaRepositoryFactoryBean,org.springframework.data.jpa.repository.config.JpaRepositoryConfigExtension; SearchStrategy: all) found bean 'org.springframework.data.jpa.repository.config.JpaRepositoryConfigExtension#0' (OnBeanCondition)
Matched:
- #ConditionalOnClass found required class 'org.springframework.data.jpa.repository.JpaRepository'; #ConditionalOnMissingClass did not find unwanted class (OnClassCondition)
- #ConditionalOnProperty (spring.data.jpa.repositories.enabled=true) matched (OnPropertyCondition)
LiquibaseAutoConfiguration:
Did not match:
- #ConditionalOnClass did not find required class 'liquibase.integration.spring.SpringLiquibase' (OnClassCondition)
RedisCacheConfiguration:
Did not match:
- Cache org.springframework.boot.autoconfigure.cache.RedisCacheConfiguration NONE cache type (CacheCondition)
SimpleCacheConfiguration:
Did not match:
- Cache org.springframework.boot.autoconfigure.cache.SimpleCacheConfiguration NONE cache type (CacheCondition)
TestDatabaseAutoConfiguration#dataSource:
Did not match:
- #ConditionalOnProperty (spring.test.database.replace=AUTO_CONFIGURED) found different value in property 'replace' (OnPropertyCondition)
TestDatabaseAutoConfiguration#embeddedDataSourceBeanFactoryPostProcessor:
Did not match:
- #ConditionalOnProperty (spring.test.database.replace=ANY) found different value in property 'replace' (OnPropertyCondition)
Exclusions:
-----------
None
Unconditional classes:
----------------------
org.springframework.boot.test.autoconfigure.jdbc.TestDatabaseAutoConfiguration
This problem is solved
Not much later than the question was posted, I found the answer: my classpath was compromised. I had two natures enabled in my eclipse project (Spring STS and Gradle) and they following happened:
Both plugins imported dependencies for Spring-JPA
This has caused Spring Autoconfigurator to be confused about which Repository resolution routine to use and entered strict mode
After that, my interfaces implementing CrudRepository would not receive an implementation coming from Spring Data JPA
How have I found this?
It was right there, under my nose, not in an error, but in a shy corner of the startup log (INFO):
14:26:40.729 [main] INFO b.a.y.c.r.i.ReviewUpserIntegrationTest - The following profiles are active: integration
14:26:40.734 [main] INFO o.s.b.c.e.AnnotationConfigEmbeddedWebApplicationContext - Refreshing org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext#7de4a01f: startup date [Thu Mar 02 14:26:40 GMT 2017]; parent: org.springframework.context.annotation.AnnotationConfigApplicationContext#130e116b
14:26:41.521 [main] INFO o.s.d.r.c.RepositoryConfigurationDelegate - Multiple Spring Data modules found, entering strict repository configuration mode!
14:26:41.562 [main] INFO o.s.d.r.c.RepositoryConfigurationExtensionSupport - Spring Data JPA - Could not safely identify store assignment for repository candidate interface boxfish.apis.youtube.channelDiscovery.reviews.domain.reviews.ReviewRepository.
14:26:41.943 [main] WARN o.s.c.a.ConfigurationClassPostProcessor - Cannot enhance #Configuration bean definition 'refreshScope' since its singleton instance has been created too early. The typical cause is a non-static #Bean method with a BeanDefinitionRegistryPostProcessor return type: Consider declaring such methods as 'static'.
The line we are talking about is Multiple Spring Data modules found, entering strict repository configuration mode!
A good cleanup and de-activation of the natures in Eclipse have solved the problem:
gradle clean cleanEclipse eclipse build --refresh-dependencies in the Shell
Refresh of the project in eclipse