so I have a project that use spring-data-neo4j and met a obscure problem. I use java config for spring-neo4j,Neo4jConfig.java:
@Configuration
@EnableNeo4jRepositories(basePackages = "org.neo4j.example.repository")
@EnableTransactionManagement
public class Neo4jConfig extends Neo4jConfiguration {
@Bean
public SessionFactory getSessionFactory() {
// with domain entity base package(s)
return new SessionFactory("org.neo4j.example.domain");
}
// needed for session in view in web-applications
@Bean
@Scope(value = "session", proxyMode = ScopedProxyMode.TARGET_CLASS)
public Session getSession() throws Exception {
return super.getSession();
}
}
the I hava a DAO and one implements,BeanDaoImpl.java:
@Repository
public class BeanDaoImpl implements BeanDao {
public String getStr() {
return "from BeanImpl";
}
}
then I have a service use the DaoImpl,note that the autowired is BeanDaoImpl,not BeanDao:
@Service
public class MyBeanService {
@Autowired
private BeanDaoImpl daoImpl;
public String getServiceString(){
return daoImpl.getStr();
}
}
here is my app-context.xml:
<context:component-scan base-package="com.springconflict" />
the version is springframework 4.2.5, spring-data-neo4j 4.1.11,it seems spring-data-neo4j has compatibility with spring 4.2.5;
here is the compile error info:
Caused by: org.springframework.beans.factory.BeanCreationException: Could not autowire field: private com.springconflict.dao.impl.BeanDaoImpl com.springconflict.service.MyBeanService.daoImpl; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [com.springconflict.dao.impl.BeanDaoImpl] 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)}
The odds are either I remove Neo4jConfig
or use @Autowired BeanDao
the test can pass. also, I use a common @Configuration
class, the test still pass,so the problem may in Neo4jConfiguration
, can someone tell me why and how to fix this?
I have no access to change @Autowired BeanDaoImpl
to @Autowired BeanDao
in real project.