Spring Actuator和@DataJpaTest找不到CounterService bean

时间:2017-08-04 15:50:32

标签: spring spring-boot junit actuator

我刚刚在我的Spring启动项目中设置了Spring Actuator,但是现在当我运行我的Jpa单元测试spring抱怨时

org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 'org.springframework.boot.actuate.metrics.CounterService'

因为找不到

@Resource
CounterService counterService;

这是我的测试课

@RunWith(SpringRunner.class)
@SpringBootTest
@DataJpaTest
@ActiveProfiles("dev")
@AutoConfigureTestDatabase(replace = AutoConfigureTestDatabase.Replace.NONE)
public class MyTestClass {

1 个答案:

答案 0 :(得分:1)

将主类包含在@SpringBootTest(classes = MainApplication.java)或其他要加载此测试的类中

<div id="ytplayer1"></div>
<div id="ytplayer2"></div>

<script>
  var player;
  var player2;
  function onYouTubePlayerAPIReady() {
    player = new YT.Player('ytplayer1', {
      height: '390',
      width: '640',
      videoId: 'hdy78ehsjdi'
    });
    player2 = new YT.Player('ytplayer2', {
      height: '390',
      width: '640',
      videoId: '81hdjskilct'
    });
  }
</script>