Я пытаюсь прикрепить параметр сеанса с помощью MockHttpServletRequest
, но только объявить атрибут в моем тесте я получаю сообщение об ошибке: followinНастройка MockHttpServletRequest в тестовом модуле контроллера
Caused by: java.lang.IllegalStateException: No thread-bound request found: Are you referring to request attributes outside of an actual web request, or processing a request outside of the originally receiving thread? If you are actually operating within a web request and still receive this message, your code is probably running outside of DispatcherServlet/DispatcherPortlet: In this case, use RequestContextListener or RequestContextFilter to expose the current request.
Я попытался сделать добавить <listener> <listener-class> org.springframework.web.context.request.RequestContextListener </listener-class> </listener>
, как говорят, чтобы сделать в этой ссылке: Getting a 'No thread-bound request found' error from spring in my web app
Test код:
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(loader = WebContextLoader.class, classes = { TestApplicationWebContext.class })
public class ClienteControllerTest {
private MockMvc mockMvc;
@Resource
private WebApplicationContext webApplicationContext;
@Autowired
private org.springframework.mock.web.MockHttpServletRequest request;
@Before
public void inicializacao() {
mockMvc = MockMvcBuilders.webApplicationContextSetup(webApplicationContext).build();
}
@Test
public void teste() throws Exception {
mockMvc.perform(get("/administracao/cliente")).andExpect(status().isOk()).andExpect(forwardedUrl("administracao-cliente/index"));
}
}
Может ли кто-нибудь помочь мне, пожалуйста?
Я использую Spring 3.1, в настоящее время проект, который я работаю не updrage к весне 3.2, есть ли способ сделать это с помощью 3.1 версии? Благодарю. –