Fix java config

This commit is contained in:
Grzegorz Piwowarek 2016-08-01 18:31:44 +02:00
parent 96f4f732f8
commit eb8526cfde
2 changed files with 4 additions and 11 deletions

View File

@ -11,7 +11,7 @@ import org.springframework.web.servlet.view.InternalResourceViewResolver;
@Configuration @Configuration
@EnableWebMvc @EnableWebMvc
@ComponentScan(basePackages= {"org.baledung.controller.controller","org.baledung.controller.config" }) @ComponentScan(basePackages= {"org.baeldung.controller.controller","org.baeldung.controller.config" })
public class WebConfig extends WebMvcConfigurerAdapter { public class WebConfig extends WebMvcConfigurerAdapter {
@Override @Override
public void configureDefaultServletHandling(DefaultServletHandlerConfigurer configurer) { public void configureDefaultServletHandling(DefaultServletHandlerConfigurer configurer) {

View File

@ -1,7 +1,6 @@
package org.baeldung.controller; package org.baeldung.controller;
import javax.servlet.ServletContext; import com.fasterxml.jackson.databind.ObjectMapper;
import org.baeldung.controller.config.WebConfig; import org.baeldung.controller.config.WebConfig;
import org.baeldung.controller.student.Student; import org.baeldung.controller.student.Student;
import org.junit.Assert; import org.junit.Assert;
@ -11,7 +10,7 @@ import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.test.context.support.AnnotationConfigContextLoader; import org.springframework.test.context.web.AnnotationConfigWebContextLoader;
import org.springframework.test.context.web.WebAppConfiguration; import org.springframework.test.context.web.WebAppConfiguration;
import org.springframework.test.web.servlet.MockMvc; import org.springframework.test.web.servlet.MockMvc;
import org.springframework.test.web.servlet.request.MockMvcRequestBuilders; import org.springframework.test.web.servlet.request.MockMvcRequestBuilders;
@ -19,23 +18,17 @@ import org.springframework.test.web.servlet.setup.MockMvcBuilders;
import org.springframework.web.context.WebApplicationContext; import org.springframework.web.context.WebApplicationContext;
import org.springframework.web.servlet.ModelAndView; import org.springframework.web.servlet.ModelAndView;
import com.fasterxml.jackson.databind.ObjectMapper;
@RunWith(SpringJUnit4ClassRunner.class) @RunWith(SpringJUnit4ClassRunner.class)
@WebAppConfiguration @WebAppConfiguration
@ContextConfiguration(classes={WebConfig.class},loader=AnnotationConfigContextLoader.class ) @ContextConfiguration(classes={WebConfig.class}, loader=AnnotationConfigWebContextLoader.class )
public class ControllerAnnotationTest { public class ControllerAnnotationTest {
@Autowired
private MockMvc mockMvc; private MockMvc mockMvc;
@Autowired @Autowired
private WebApplicationContext wac; private WebApplicationContext wac;
@Autowired
private ServletContext servletContext;
private Student selectedStudent; private Student selectedStudent;
@Before @Before