I created a simple RestController which autowires EntityManager and an other class I have. If I run my app, everything works, the autowires are defined. Now I tried to create a simple test for my class:
@RunWith(SpringJUnit4ClassRunner.class)
@WebAppConfiguration
@EnableWebMvc
@ContextConfiguration(classes = MonitoringController.class)
public class MonitoringControllerTest {
private MockMvc mockMvc;
@Autowired
WebApplicationContext wac;
@Before
public void setup() {mockMvc = MockMvcBuilders.webAppContextSetup(this.wac).build();
}
@Test
public void testMonitoringIsUp()throws Exception {
mockMvc.perform(get("/monitoring"))
.andExpect(status().isOk());
}
Here starts the problem, I'm getting error Caused by: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'monitoringController': Unsatisfied dependency expressed through field 'em'; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 'javax.persistence.EntityManager' available: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}
I guess I'm missing something very simple. Any help appreciated.
Aucun commentaire:
Enregistrer un commentaire