File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Spring and the fly likes Could not able to Autowire Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Frameworks » Spring
Reply locked New topic

Could not able to Autowire "WebApplicationContext"while doing the Spring MVC Test

Laxmi Prasanna Bn

Joined: Feb 13, 2012
Posts: 17
Hi Friends,

I'm new to MVC Test

From below code i got the error while Autowiring the "WebApplicationContext" and other autowired fields,
how can we define those beans in äpplciationContext.xml" file ?


public class ComplianceControllerTest {

WebApplicationContext wac; //Not able to create Object (Couldn't be autowired)
MockHttpSession session; //Not able to create Object (Couldn't be autowired)
MockHttpServletRequest request; //Not able to create Object (Couldn't be autowired)
MockHttpServletResponse response; //Not able to create Object (Couldn't be autowired)
ComplianceDelegate complianceDelegate;

private MockMvc mockMvc;

private TermSessionBean termSessionBean;

public void setup() {"webAppContext setup.");
this.mockMvc = MockMvcBuilders.webAppContextSetup(this.wac).build();

public void testComplianceProcess() throws Exception {
termSessionBean = buildSession();
(MockHttpSession) termSessionBean).accept(

One more question, from the above code i'm going to call Controller, here my question i "I'm define the TermSessionBean in this test class
, it will be avaliable in Controller and is this termssionbean also avaliable in Delegate class?"

Thanks for advance..
Bill Gorder

Joined: Mar 07, 2010
Posts: 1632


Please check your private messages for an important administrative matter. Also once again please UseCodeTags <-click.

This appears to be a duplicate of this post. Please follow up with questions in the original thread rather than creating a new one. I am going to lock this topic.

[How To Ask Questions][Read before you PM me]
I agree. Here's the link:
subject: Could not able to Autowire "WebApplicationContext"while doing the Spring MVC Test
Similar Threads
Controller testing error using Spring MVC Test framework
How to create the Object for @Autowired field using Junit test?
Mocking Method call within a Method?
Autowiring does not work inside custom constraint validator using Spring-Test-MVC
Spring MVC 3 Controller JUNIT Testing giving errors