Config class with below configuration will load all the required classes in the application as beans by component scan during startup of application as below:
@Configuration
@EnableWebMvc
@ComponentScan(basePackages = {"package1","package2"}
public MvcConfig implements WebMvcConfigurer {
}
How to load the webapplication context inside my junit integration test ? tried below code already which is not working:
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(classes = { MvcConfig.class })
public class ITtest {
@Autowired
private ApplicationContext wac;
private MockMvc mockMvc;
@Before
public void setup() throws Exception {
this.mockMvc = MockMvcBuilders.webAppContextSetup((WebApplicationContext) this.wac).build();
}
}
I need to create a mockMVC instance with the web Application context as shown in my setup method.
What is the problem with my code. I expect the context to get loaded with all the classes obtained by package scan of MvcConfig class in my junit integration test.