Location of Application Context XML file
Web.xml Entries
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>
classpath:**/application-context.xml
</param-value>
</context-param>
<listener>
<listener-class>
org.springframework.web.context.ContextLoaderListener
</listener-class>
</listener>
Bean entry in Application-Context.xml File.
<bean id="tweeterService" class="com.serviceImpl.TweeterServiceImpl">
</bean>
Getting beans instance from Application Context in java
@RequestMapping( value = "/pageInfo", method = RequestMethod.GET)
public @ResponseBody String getPageInfo() {
/*
*Try to avoid using this.
*
ApplicationContext context = new FileSystemXmlApplicationContext("applicationContext.xml"); */
// Use below code for bean creation
ApplicationContext ctx = new ClassPathXmlApplicationContext("../application-context.xml");
if(ctx!=null)
{
TweeterService ts =(TweeterService)ctx.getBean("tweeterService");
}
Thanks
Khansdroid
No comments:
Post a Comment