问题
Application depends on a number of spring data projects including Neo4j, Solr and Jpa. I recently had to update spring-data-solr to Snapshot-3.0.0.M1 (to eliminate another dependency conflict). I think one of the transitive dependency is causing a conflict with neo4j. If I remove spring-neo4j from project, error (see below) seem to go away.
I have a attached a sample project that recreates the issue. Run Test Class AccountServiceJpaTester.testSaveAccount()
Download sample project from here
Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 'java.lang.Class>' available: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: {} at org.springframework.beans.factory.support.DefaultListableBeanFactory.raiseNoMatchingBeanFound(DefaultListableBeanFactory.java:1456) at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1087) at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:1049) at org.springframework.beans.factory.support.ConstructorResolver.resolveAutowiredArgument(ConstructorResolver.java:833) at org.springframework.beans.factory.support.ConstructorResolver.createArgumentArray(ConstructorResolver.java:740) ... 60 more
回答1:
Spring data projects are all based on a common infrastructure (spring data commons). If you use several projects in the spring data family (in your case neo4j, solr, jpa), you have to make sure they are all based on a common version of the infrastructure.
In your case, spring-data-solr 3.0.0 M1
is based on spring-data-commons 2.x
whereas JPA and Neo4j use spring-data-commons 1.x
.
A good way of managing this is to use the spring data BOM. This is explained on the spring data homepage.
To manage the portfolio, a BOM (Bill of Materials - see this example) is published with a curated set of dependencies on the individual project
If you need to update to newer versions than the ones included in the BOM, make sure they are based on the same infrastructure version.
来源:https://stackoverflow.com/questions/43103223/no-qualifying-bean-of-type-java-lang-classorg-springframework-data-repository