This week's book giveaway is in the Jobs Discussion forum.
We're giving away four copies of Java Interview Guide and have Anthony DePalma on-line!
See this thread for details.
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 Java Interview Guide this week in the Jobs Discussion 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: 1682


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
It's not a secret anymore!