Win a copy of Functional Reactive Programming this week in the Other Languages forum!
    Bookmark Topic Watch Topic
  • New Topic

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

 
Laxmi Prasanna Bn
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Report post to moderator
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
Posts: 1682
7
Android IntelliJ IDE Linux Mac OS X Spring
  • Mark post as helpful
  • send pies
  • Report post to moderator
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.
 
    Bookmark Topic Watch Topic
  • New Topic