猿问

spring-data-neo4j与Autowired冲突

所以我有一个使用spring-data-neo4j的项目,遇到了一个模糊的问题。我将java config用于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();

    }


}

我有一个DAO和一个工具,BeanDaoImpl.java:


@Repository

public class BeanDaoImpl implements BeanDao {

    public String getStr() {

        return "from BeanImpl";

    }

}

然后我有一个使用DaoImpl的服务,请注意,自动装配的是BeanDaoImpl,而不是BeanDao:


@Service

public class MyBeanService {

    @Autowired

    private BeanDaoImpl daoImpl;



    public String getServiceString(){

        return daoImpl.getStr();

    }

}

这是我的app-context.xml:


    <context:component-scan base-package="com.springconflict" />

版本是springframework 4.2.5,spring-data-neo4j 4.1.11,似乎spring-data-neo4j与spring 4.2.5兼容;


这是编译错误信息:


引起原因:org.springframework.beans.factory.BeanCreationException:无法自动连线字段:私有com.springconflict.dao.impl.BeanDaoImpl com.springconflict.service.MyBeanService.daoImpl; 嵌套的异常是org.springframework.beans.factory.NoSuchBeanDefinitionException:未找到依赖类型为[com.springconflict.dao.dao.impl.BeanDaoImpl]的合格Bean:预计至少有1个Bean可以作为此依赖的自动装配候选。依赖项注释:{@ org.springframework.beans.factory.annotation.Autowired(required = true)}


可能性是我删除Neo4jConfig或使用@Autowired BeanDao测试可以通过。另外,我使用一个普通的@Configuration类,测试仍然通过,所以问题可能出在Neo4jConfiguration,有人可以告诉我为什么以及如何解决此问题吗?我没有权限更改@Autowired BeanDaoImpl到@Autowired BeanDao实际项目。


慕哥6287543
浏览 253回答 1
1回答
随时随地看视频慕课网APP

相关分类

Java
我要回答