0

私のアプリケーションは、環境が基本的に機能しているかどうかをテストするだけです。したがって、SpringSource の gitHub リポジトリにある「Hello Worlds」の例に対応するテストクラスをセットアップしました。Neo4j は静的 Web アプリとして含まれ、組み込みで実行されます。Web インターフェイスは必ずしも必要ではありません。問題は、Junit を介してテストケースの実行を開始すると、次のようなエラーが発生することです。

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'GalaxyServiceTests': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private GalaxyService GalaxyServiceTests.galaxyService; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No matching bean of type [GalaxyService] 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)}

私のアプリケーション構成はこのようなものです

    <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<beans xmlns="http://www.springframework.org/schema/beans"
        xmlns:context="http://www.springframework.org/schema/context"
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xmlns:neo4j="http://www.springframework.org/schema/data/neo4j"
        xsi:schemaLocation="
            http://www.springframework.org/schema/beans
            http://www.springframework.org/schema/beans/spring-beans.xsd
            http://www.springframework.org/schema/context
            http://www.springframework.org/schema/context/spring-context.xsd
            http://www.springframework.org/schema/data/neo4j
            http://www.springframework.org/schema/data/neo4j/spring-neo4j.xsd">
<context:annotation-config/>
<bean id="graphDatabaseService" class="org.neo4j.kernel.EmbeddedGraphDatabase"
    destroy-method="shutdown">
    <constructor-arg index="0" value="target/graph.db" />
    <constructor-arg index="1">
        <map><entry key="enable_remote_shell" value="true"/></map>
    </constructor-arg>
</bean>
<!-- <bean id="serverWrapper" class="org.neo4j.server.WrappingNeoServerBootstrapper"  -->
<!--    init-method="start" destroy-method="stop"> -->
<!--    <constructor-arg ref="graphDatabaseService"/> -->
<!-- </bean> -->
</beans>

テストクラスは非常に単純です

@ContextConfiguration( "file:c:/Users/ben/Dropbox/Semester 6/VM Graphentheorie/devEnv/bodega/application-context.xml")

@RunWith(SpringJUnit4ClassRunner.class)
@Transactional
public class GalaxyServiceTests {

//  @Autowired
//  private GalaxyService galaxyService;

    @Autowired
    private Neo4jTemplate template;

    @Rollback(false)
    @BeforeTransaction
    public void cleanUpGraph() {
        Neo4jHelper.cleanDb(template);
    }

    @Test
    public void allowWorldCreation(){
//      GraphDatabaseService     graphDatabaseService =  new GraphDatabaseFactory().newEmbeddedDatabase( "target/graph.db" );
//      Node abc = graphDatabaseService.createNode();
//      abc.setProperty("name","ben");

        World abc = new World("Erde",1);
        template.save(abc);

私のpomは次のようになります:

<dependencies>
    <dependency>
    <groupId>org.springframework</groupId>
    <artifactId>spring-context</artifactId>
    <version>3.0.4.RELEASE</version>
</dependency>
<dependency>
    <groupId>org.springframework</groupId>
    <artifactId>spring-test</artifactId>
    <version>3.0.7.RELEASE</version>
    <scope>test</scope>
    <exclusions>
            <exclusion>
                <groupId>commons-logging</groupId>
                <artifactId>commons-logging</artifactId>
            </exclusion>
        </exclusions>
</dependency>
        <dependency>
        <groupId>junit</groupId>
        <artifactId>junit</artifactId>
        <version>4.8.1</version>
        <scope>test</scope>
    </dependency>
        <dependency>
            <groupId>org.springframework.data</groupId>
            <artifactId>spring-data-neo4j</artifactId>
            <version>2.2.0.BUILD-SNAPSHOT</version>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-tx</artifactId>
            <version>3.2.2.RELEASE</version>
        </dependency>
        <dependency>
            <groupId>org.neo4j.app</groupId>
            <artifactId>neo4j-server</artifactId>
            <version>2.0.0-M02</version>
            <classifier>static-web</classifier>
        </dependency>

私はneo4jに関連して春に慣れていないので、このエラーを解決できません。誰かがヒントやアドバイスを得た場合 - 事前に感謝します

EDIT i は spring-data の依存関係を 2.2.0.BUILD-SNAPSHOT から 2.2.0.RELEASE に変更しました。これで、エラーがコンソールに渡される時点まで neo4j が実行されます。

21:11:48.196 [main] ERROR o.s.test.context.TestContextManager - Caught exception while allowing TestExecutionListener [org.springframework.test.context.support.DependencyInjectionTestExecutionListener@7e26f5a7] to prepare test instance [GalaxyServiceTests@64d74895]
java.lang.IllegalStateException: Failed to load ApplicationContext

EDIT2 http://github.com/BenMatheja/bodega でリポジトリを公開しました

EDIT3 application-context.xml のパスがめちゃくちゃでした。私はその問題を修正しました@ContextConfiguration( locations = {"classpath:/META-INF/application-context.xml"})

私はその時点で例外です

依存関係のタイプ [start.GalaxyService] の適格な Bean が見つかりません: この依存関係のオートワイヤー候補として適格な少なくとも 1 つの Bean が必要です

JUnit4 テストを実行するたびにスローされます。

EDIT4 昨日、なんとか機能させることができました。Application-context のいくつかの部分はかなり混乱していました。

<context:spring-configured/>
<context:annotation-config/>
<context:component-scan base-package="components"/>
<neo4j:config graphDatabaseService="graphDatabaseService"/>
<neo4j:config storeDirectory="target/graph.db"/>
<neo4j:repositories base-package="Repositories"/>

これは、私の作業中のアプリ コンテキストのスニペットです。さらに、 @Service を GalaxyService クラスに添付するのを逃しました。

現在、すべてが意図したとおりに機能しています。これは、同じ問題に直面している誰かを助けるかもしれません。

4

0 に答える 0