私は構造を持つ複数のモジュールプロジェクトを持っているリポジトリ春ブーツ、複数のモジュールテストオートワイヤリング
@Repository
public interface CustomerRepository extends JpaRepository<Customer, Long> {
}
とリポジトリのテストでは
@SpringBootApplication
public class Application {
public static void main(String[] args) {
SpringApplication.run(Application.class);
}
}
@RunWith(SpringRunner.class)
@SpringBootTest
public class CustomerRepositoryTest {
@Autowired
private CustomerRepository repository;
@Test
public void shouldSave() {
// When
final Customer saved = repository.save(new Customer());
// Then
assertThat(saved.getID()).isNotNull();
}
}
今、私はこのテストを実行すると、私はエラーを取得:
Unable to find a @SpringBootConfiguration, you need to use @ContextConfiguration or @SpringBootTest(classes=...) with your test
私は私のリポジトリモジュール内のApplicationクラスを持っている場合、このdoesntのは、表示されますが、私は区切られるためにそれらを必要とします。これを動作させる最良の方法は何ですか?それが助け場合
は私の春の依存関係は、以下のとおりです。
compile("org.springframework.boot:spring-boot-starter-data-jpa")
compile("com.h2database:h2")
testCompile("org.springframework.boot:spring-boot-starter-test")
それは、パッケージ階層の問題と思われるプラグインorg.springframework.boot:spring-boot-gradle-plugin:1.5.8.RELEASE
'アプリケーション '(テストを含む)以外のすべてのクラスを別のパッケージ(たとえば、' src/main/java/example/subpackage')に移動してみてください。 '@ SpringBootApplication'と' @ SpringBootTest'が同じパッケージに含まれている場合、コンポーネントスキャンに問題があることを思い出してください。私はそれが知っている問題だと思うが、参照を見つけることができません – jannis
@jannis私はまだ同じエラーが発生します:(私は 'Application'クラスを持っていなくてもそれを設定する方法をテストする方法がありますか? – Edd
@jannis '@ SpringBootTest'はRESTレイヤーのために意図されているので、そのようにしてもかまいません – Edd