2017-04-19 3 views
0

h2と組み合わせて春に問題があります。テスト用にh2データベースを使用していますが、私は非常に奇妙な動作をしています。Springデータh2:mavenでテストするときのjava.io.FileNotFoundException

私の依存関係:

spring.datasource.url = JDBC:H2:MEM:

... 
    <dependency> 
     <groupId>org.springframework.boot</groupId> 
     <artifactId>spring-boot-starter-data-jpa</artifactId> 
    </dependency> 

    <dependency> 
     <groupId>com.h2database</groupId> 
     <artifactId>h2</artifactId> 
     <scope>test</scope> 
    </dependency> 
    <dependency> 
     <groupId>org.springframework.boot</groupId> 
     <artifactId>spring-boot-starter-test</artifactId> 
     <scope>test</scope> 
    </dependency> 
... 

私はに私のテスト用のJDBC接続文字列を設定DataSourceを

基本テストはありません。

@RunWith(SpringRunner.class) 
@SpringBootTest 
public class DemoApplicationTests { 
    @Test 
    public void contextLoads() { 
    } 
} 

は、私は私のポンポンが配置されている同じディレクトリに

MVNテスト

を実行すると、すべてが正常に動作します。親ディレクトリ

MVN -f ./xxx/pom.xmlテスト

で次のコマンドを実行している場合でも、テストは動作しませんでした。

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory' defined in class path resource [org/springframework/boot/autoconfigure/orm/jpa/HibernateJpaAutoConfiguration.class]: Invocation of init method failed; nested exception is javax.persistence.PersistenceException: Unable to resolve persistence unit root URL 

親ディレクトリでテストを実行するにはどうすればよいですか?

答えて

1

てみ MVN -f XXX /のpom.xmlテスト

+0

は、あなたが私にこの作業の理由の説明を与えることができますか?それは同じではありませんか? – user3046582

+0

現在のフォルダを示す./構文は古いjavaではサポートされていないため、頻繁にエラーが発生する可能性があります。これの潜在的な原因の1つは、MavenバージョンとJDKに応じて、1.4以前のAntパターンマッチングを使用することです。先頭に-fを付けない場合のパラメータ/は、既定のパターンマッチャで相対パスを指定していることを前提としています。将来はさまざまなバリエーションを試してみるとうまくいくはずです。 –

関連する問題