Announcement Announcement Module
Collapse
No announcement yet.
MVC Test - MockHttpSession not autowired Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • MVC Test - MockHttpSession not autowired

    Hi,

    Following TDD I am testing my Spring Controllers using spring-mvc test on Spring Version 3.2.2.RELEASE

    PAJController.java
    Code:
    @RunWith(SpringJUnit4ClassRunner.class)
    @WebAppConfiguration
    @ContextConfiguration( classes = {
            com.washingtonpost.jobs.common.config.CServiceConfig.class,
            com.washingtonpost.jobs.employer.config.EServiceConfig.class,
            PajServiceConfig.class,
            PajAppConfig.class,
            WebConfig.class,
            TestConfig.class })
    @TestExecutionListeners({DependencyInjectionTestExecutionListener.class})
    
    public class PAJControllerTest extends AbstractJobsSpringDBUnitTest {
        @Autowired
        WebApplicationContext wac;
    
        @Autowired
        @InjectMocks
        private PAJController pajController;
    
    
        @Autowired
        private MockHttpSession session;
    When I execute I am getting following error

    HTML Code:
    Error creating bean with name 'com.wp.jbs.employer.paj.controller.PAJControllerTest': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private org.springframework.mock.web.MockHttpSession com.wp.jbs.employer.paj.controller.PAJControllerTest.session; nested exception is 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.
    I am not sure how to proceed further.

    Kindly help. Would appreciate if I am missing something obvious. And just to clarify, I was expecting session to be autowire without doing anything extra, or any bean injection in the configurations.

    Thanks
    Last edited by regmem; Jun 20th, 2013, 12:52 PM.
Working...
X