テストを実行するときに春ブートオプションビーンはレイジーにすることはできません。

キラービースト:

私の春ブーツ2.1アプリケーションでは、私は次のようになり、サービスクラスを持っています:

@Service
public class AImpl implements A {
    @Autowired
    B bservice;
}

そしてautowiredサービスBは次のようになります。

@Service
public class BImpl implements B {
    @Autowired(required = false)
    @Lazy
    org.springframework.web.client.RestOperations restTemplate;
}

そして、私のテストクラスで:

@RunWith(SpringRunner.class)
@ContextConfiguration(classes = {...})
@DataJpaTest
@EnableJpaRepositories("com.xxx")
@EntityScan("com.xxx")
public class CImplTest {
    @Autowired
    B bservice;
    @Autowired
    A aservice;
}

私のテストを実行しているとき、私は次のエラーメッセージが表示されます。

org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 'org.springframework.web.client.RestOperations' available: Optional dependency not present for lazy injection point

アプリケーションを実行するときしかし、私はこの問題に直面していない、それは罰金を実行します。

注:私は、Java 8オプションでrstTemplateオートワイヤリングを交換しようとしている、それがうまく機能しません。

キラービースト:

これがこの問題の厳密解であるが、Java 8の任意のタイプにしようとしたとき、これはうまくいかなかった場合はわかりません。私は春のに切り替えたときにしかし、ObjectProviderそれは正常に動作しています。理想的には、これは単なる回避策ではなく、この問題の根本的な原因です。

おすすめ

転載: http://43.154.161.224:23101/article/api/json?id=228860&siteId=1