I am using spring boot 1.4.0.RELEASE. I am writing tests for my controller class. I get the following exception.
org.springframework.beans.facto
If you read the java doc of SpringBootTest annotation, it says that annotation provides below features (not listing all of them here, but only what are relevant to the question.)
So @SpringBootTest(webEnvironment=WebEnvironment.RANDOM_PORT) provides the ability to autowire TestRestTemplate because it starts a fully running web server [as mentioned in @AndyWilkinson' answer as well].
But if you want to autowire MockMvc as well in same TestClass then use @AutoConfigureMockMvc annotation over TestClass.
This is how a Test class may look like:
@RunWith(SpringRunner.class)
@SpringBootTest(webEnvironment=WebEnvironment.RANDOM_PORT)
@AutoConfigureMockMvc
public class SBTest {
@Autowired
private TestRestTemplate restTemplate;
@Autowired
private MockMvc mvc;
// tests
}