2 lipei19890425 lipei19890425 于 2016.09.11 18:46 提问

Spring boot Test 方法启动异常

Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [org.springframework.boot.test.web.client.TestRestTemplate] found for dependency [org.springframework.boot.test.web.client.TestRestTemplate]: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}

以下是我的test方法

 package com.hyh;

import org.apache.log4j.Logger;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.test.web.client.TestRestTemplate;
import org.springframework.test.context.junit4.SpringRunner;

@RunWith(SpringRunner.class)
@SpringBootTest(classes=SampleController.class)
public class Test01 {

    private Logger log = Logger.getLogger(getClass());


    @Autowired
    private TestRestTemplate restTemplate;


    @Test
    public void contextLoads() {
        log.info("in the test method");

        this.restTemplate.getForEntity("/", String.class, "Phil");
    }
}

1个回答

devmiao
devmiao   Ds   Rxr 2016.09.12 00:03
Csdn user default icon
上传中...
上传图片
插入图片
准确详细的回答,更有利于被提问者采纳,从而获得C币。复制、灌水、广告等回答会被删除,是时候展现真正的技术了!