This week's book giveaways are in the Java EE and JavaScript forums.
We're giving away four copies each of The Java EE 7 Tutorial Volume 1 or Volume 2(winners choice) and jQuery UI in Action and have the authors on-line!
See this thread and this one 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 The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Frameworks » Spring
Reply locked New topic
Author

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

Laxmi Prasanna Bn
Greenhorn

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 ?

@RunWith(SpringJUnit4ClassRunner.class)
@WebAppConfiguration

@ContextConfiguration
(
{
"classpath:applicationContext.xml"
}
)
public class ComplianceControllerTest {


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

private MockMvc mockMvc;

@Autowired
private TermSessionBean termSessionBean;

@Before
public void setup() {
log.info("webAppContext setup.");
this.mockMvc = MockMvcBuilders.webAppContextSetup(this.wac).build();
}

@Test
public void testComplianceProcess() throws Exception {
System.out.println("Hello..");
log.info("Hello");
termSessionBean.setAccountTypeCd("05");
termSessionBean.getCustomerSessionBean().setCustomerTypeCd("P");
termSessionBean = buildSession();
this.mockMvc.perform(
get("/Compliance").session(
(MockHttpSession) termSessionBean).accept(
MediaType.TEXT_HTML)).andExpect(status().isOk())
.andExpect(view().name("test"));
}


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
Bartender

Joined: Mar 07, 2010
Posts: 1648
    
    7

Laxmi,

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]
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Could not able to Autowire "WebApplicationContext"while doing the Spring MVC Test