इंजेक्ट करने में असमर्थ है मैं वसंत बूट 1.4.0.RELEASE
का उपयोग कर रहा हूं। मैं अपने नियंत्रक वर्ग के लिए परीक्षण लिख रहा हूं। मुझे निम्नलिखित अपवाद मिलता है।वसंत बूट परीक्षण TestRestTemplate और MockMvc
org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'com.concur.cognos.authentication.service.ServiceControllerITTest': Unsatisfied dependency expressed through field 'restTemplate': 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)}; nested exception is 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)}
यहाँ
public class ServiceControllerITTest extends ApplicationTests {
@Autowired
private TestRestTemplate restTemplate;
@Autowired
private MockMvc mvc;
@Test
public void exampleTest() throws Exception {
// test
}
}
ApplicationTests.java
@RunWith(SpringRunner.class)
@SpringBootTest
@WebAppConfiguration
//@DirtiesContext
public class ApplicationTests {
@Autowired
Environment env;
@Test
public void contextLoads() {
}
}
मैंने जोड़ा। अब मैं करने के 'java.lang.IllegalStateException: org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContext' –
में ApplicationContext \t लोड करने में असफल तुम अब भी' TestRestTemplate' और 'MockMvc' autowire करने की कोशिश कर रहे हैं? ऐसा करने से समझ में नहीं आता है। आपको एक या दूसरे का उपयोग करना चाहिए। –
यह या तो मदद नहीं करता है। मैंने 'मॉकएमवीसी' पर टिप्पणी की और केवल 'testRestTemplate' को स्वचालित किया। अभी भी मुझे उपरोक्त टिप्पणी –