使用Spring Boot 1.3.3和Spring XD 1.3.1进行Redis自动配置时出错

时间:2016-04-05 01:33:22

标签: java spring spring-boot spring-integration spring-xd

我尝试创建自定义Spring XD(v1.3.1)模块以及利用一些Spring Boot Starter项目,但我遇到了Redis的错误。

我在这里有一个非常简单的示例项目:https://github.com/fgreg/redis-error-example可以重现错误。我认为这与我正在使用的Spring Boot版本有关。

基本上,当我尝试运行集成测试时; Spring XD无法启动错误:

org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'redisTemplate' defined in class path resource [org/springframework/boot/autoconfigure/data/redis/RedisAutoConfiguration$RedisConfiguration.class]: Unsatisfied dependency expressed through constructor argument with index 0 of type [org.springframework.data.redis.connection.RedisConnectionFactory]: : Error creating bean with name 'org.springframework.boot.autoconfigure.data.redis.RedisAutoConfiguration$RedisPooledConnectionConfiguration': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: protected org.springframework.boot.autoconfigure.data.redis.RedisProperties org.springframework.boot.autoconfigure.data.redis.RedisAutoConfiguration$AbstractRedisConfiguration.properties; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [org.springframework.boot.autoconfigure.data.redis.RedisProperties] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.boot.autoconfigure.data.redis.RedisAutoConfiguration$RedisPooledConnectionConfiguration': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: protected org.springframework.boot.autoconfigure.data.redis.RedisProperties org.springframework.boot.autoconfigure.data.redis.RedisAutoConfiguration$AbstractRedisConfiguration.properties; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [org.springframework.boot.autoconfigure.data.redis.RedisProperties] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}

    at org.springframework.beans.factory.support.ConstructorResolver.createArgumentArray(ConstructorResolver.java:749)
    at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:464)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateUsingFactoryMethod(AbstractAutowireCapableBeanFactory.java:1123)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1018)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:510)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:482)
    at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:306)
    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230)
    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:302)
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197)
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:772)
    at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:839)
    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:538)
    at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:686)
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:320)
    at org.springframework.boot.builder.SpringApplicationBuilder.run(SpringApplicationBuilder.java:139)
    at org.springframework.boot.builder.SpringApplicationBuilder.run(SpringApplicationBuilder.java:129)
    at org.springframework.boot.builder.SpringApplicationBuilder.run(SpringApplicationBuilder.java:129)
    at org.springframework.xd.dirt.server.singlenode.SingleNodeApplication.run(SingleNodeApplication.java:83)
    at com.example.UpperCaseProcessorIntegrationTest.setUp(UpperCaseProcessorIntegrationTest.java:34)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:497)
    at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
    at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
    at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
    at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:24)
    at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
    at org.junit.runner.JUnitCore.run(JUnitCore.java:137)
    at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:119)
    at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:42)
    at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:234)
    at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:74)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:497)
    at com.intellij.rt.execution.application.AppMain.main(AppMain.java:144)
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.boot.autoconfigure.data.redis.RedisAutoConfiguration$RedisPooledConnectionConfiguration': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: protected org.springframework.boot.autoconfigure.data.redis.RedisProperties org.springframework.boot.autoconfigure.data.redis.RedisAutoConfiguration$AbstractRedisConfiguration.properties; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [org.springframework.boot.autoconfigure.data.redis.RedisProperties] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}
    at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:334)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1214)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:543)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:482)
    at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:306)
    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230)
    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:302)
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197)
    at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:368)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateUsingFactoryMethod(AbstractAutowireCapableBeanFactory.java:1123)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1018)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:510)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:482)
    at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:306)
    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230)
    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:302)
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197)
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.findAutowireCandidates(DefaultListableBeanFactory.java:1192)
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1116)
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:1014)
    at org.springframework.beans.factory.support.ConstructorResolver.resolveAutowiredArgument(ConstructorResolver.java:813)
    at org.springframework.beans.factory.support.ConstructorResolver.createArgumentArray(ConstructorResolver.java:741)
    ... 38 more
Caused by: org.springframework.beans.factory.BeanCreationException: Could not autowire field: protected org.springframework.boot.autoconfigure.data.redis.RedisProperties org.springframework.boot.autoconfigure.data.redis.RedisAutoConfiguration$AbstractRedisConfiguration.properties; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [org.springframework.boot.autoconfigure.data.redis.RedisProperties] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}
    at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:573)
    at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:88)
    at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:331)
    ... 59 more
Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [org.springframework.boot.autoconfigure.data.redis.RedisProperties] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.raiseNoSuchBeanDefinitionException(DefaultListableBeanFactory.java:1373)
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1119)
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:1014)
    at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:545)
    ... 61 more

但是,如果我降级回版本

"org.springframework.boot:spring-boot-starter-integration:1.2.3.RELEASE"

在我的build.gradle中,一切正常。

我正在浏览Spring Boot 1.3 release notes,唯一突然出现的是对自动配置缓存的新支持(包括Redis)。

我认为,由于Spring XD使用Redis进行分析,因此Spring Boot会在类路径中找到这些类并尝试配置Redis。我如何让它阻止它?或者,正确加载我的类路径中application.yamlspring-xd-dirt-1.3.1.RELEASE.jar文件中的redis配置?

我尝试过以下方法但没有成功:

  • @EnableAutoConfiguration(exclude = RedisAutoConfiguration.class)添加到我的IntegrationConfiguration课程。我认为它甚至在考虑我的配置类之前就失败了。
  • 从我的依赖项中排除spring-boot-autoconfigure模块。这只会导致各种其他失败。
  • 我可以尝试使用spring.autoconfigure.excludes属性,但我不知道将它放在哪里可以实际工作。我无法将其作为new SingleNodeApplication().run()的参数传递(它作为未知选项失败),当我将其放入spring-module.properties文件时,它不会被拾取。此外,当我最终开始部署这个自定义模块时,我不想将其设置为启动参数,我希望模块是自包含的。

修改:其他一些信息。对于我的真实项目,由于added support for Cassandra,我想使用Spring Boot 1.3。

1 个答案:

答案 0 :(得分:0)

我更加努力地看待我的依赖项,我注意到了:

compile - Compile classpath for source set 'main'.
+--- org.springframework.boot:spring-boot-starter-integration:1.3.3.RELEASE
|    +--- org.springframework.boot:spring-boot-starter:1.3.3.RELEASE
|    |    +--- org.springframework.boot:spring-boot:1.3.3.RELEASE
|    |    |    +--- org.springframework:spring-core:4.2.5.RELEASE
|    |    |    |    \--- commons-logging:commons-logging:1.2
|    |    |    \--- org.springframework:spring-context:4.2.5.RELEASE
|    |    |         +--- org.springframework:spring-aop:4.2.5.RELEASE
|    |    |         |    +--- aopalliance:aopalliance:1.0
|    |    |         |    +--- org.springframework:spring-beans:4.2.5.RELEASE
|    |    |         |    |    \--- org.springframework:spring-core:4.2.5.RELEASE (*)
|    |    |         |    \--- org.springframework:spring-core:4.2.5.RELEASE (*)
|    |    |         +--- org.springframework:spring-beans:4.2.5.RELEASE (*)
|    |    |         +--- org.springframework:spring-core:4.2.5.RELEASE (*)
|    |    |         \--- org.springframework:spring-expression:4.2.5.RELEASE
|    |    |              \--- org.springframework:spring-core:4.2.5.RELEASE (*)
|    |    +--- org.springframework.boot:spring-boot-autoconfigure:1.3.3.RELEASE <-------
|    |    |    \--- org.springframework.boot:spring-boot:1.3.3.RELEASE (*)             |
                                                                                       |
                                                               notice the 1.3.3 here----
...


provided
\--- org.springframework.xd:spring-xd-dirt:1.3.1.RELEASE
     ...
     +--- org.springframework.boot:spring-boot-autoconfigure:1.2.3.RELEASE <-----------
     |    +--- org.springframework.boot:spring-boot:1.2.3.RELEASE                     |
                                                                                      |
                                                                                      |
                                                                 and the 1.2.3 here----

当然,我查看了运行时类路径,它包括Spring Boot的1.2.3和1.3.3版本。所以看来,由于XD DiRT使用Spring boot v1.2.3,我不能/不应该使用v1.3.3。

我的解决方案似乎是,不要使用Spring Boot。