Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Liutauras Vilda
  • Paul Clapham
Sheriffs:
  • paul wheaton
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Piet Souris
Bartenders:
  • Mike London

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

 
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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..
 
Bartender
Posts: 1682
7
Android Mac OS X IntelliJ IDE Spring Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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