rsrch
May 6th, 2008, 01:00 PM
I have a silly problem. For most of you it may be cake walk. Please help me to resolve this.
My project structure is
project
/WEB-INF
/classes/com/../..
/config
/jsp
/lib
/tld
My issue is I have a applicationContext.xml config file.
When I placed my applicationContext.xml config file in /WEB-INF/classes folder I am able to access it using the bean finder class with location simply "applicationContext.xml" and everything is working fine.
But when I placed applicationContext in any other folder my bean finder class
is throwing FileNotFound Exception.
When I placed it in config folder I am not able to access with relative path "/config/applicationContext.xml" or "config/applicationContext.xml".
And also I tried to access by placing directly under WEB-INF folder and
using path "/WEB-INF/applicationContext.xml" I failed access it from my bean.
public class BeanFinder {
/** Logger for this class and subclasses */
protected final Log log = LogFactory.getLog(getClass());
private static ApplicationContext ctx;
public Object getBean(ServletRequest request, String beanName) {
if (ctx == null) {
if (!(request instanceof HttpServletRequest)) {
throw new IllegalArgumentException("Can only process HttpServletRequest");
}
HttpServletRequest httpRequest = (HttpServletRequest) request;
ctx = getContext(httpRequest);
}
Object obj = new Object();
return obj;
}
public Resource getResource(String location){
Resource template = new ClassPathXmlApplicationContext().getResource(locat ion);
return template;
}
public Object getBean(String beanName) throws BeansException {
// String[] configLocation = "file:../WEB-INF/config/applicationContext-hibernate.xml";
// ctx = new FileSystemXmlApplicationContext(configLocation);
// String[] configLocation = {"classpath:/config/applicationContext.xml"};
String[] configLocation = {"classpath:applicationContext.xml"};
ctx = new ClassPathXmlApplicationContext(configLocation);
log.info("Context: " + ctx);
Object obj = ctx.getBean(beanName);
return obj;
}
/**
* Allows test cases to override where application context obtained from.
*
* @param httpRequest which can be used to find the <code>ServletContext</code>
*
* @return the Spring application context
*/
public ApplicationContext getContext(HttpServletRequest request) {
return WebApplicationContextUtils.getRequiredWebApplicati onContext(
request.getSession().getServletContext());
}
I want to access my config file by placing it under config folder. How can I achieve this. Please help me.
Thanks in advance.
rsrch
My project structure is
project
/WEB-INF
/classes/com/../..
/config
/jsp
/lib
/tld
My issue is I have a applicationContext.xml config file.
When I placed my applicationContext.xml config file in /WEB-INF/classes folder I am able to access it using the bean finder class with location simply "applicationContext.xml" and everything is working fine.
But when I placed applicationContext in any other folder my bean finder class
is throwing FileNotFound Exception.
When I placed it in config folder I am not able to access with relative path "/config/applicationContext.xml" or "config/applicationContext.xml".
And also I tried to access by placing directly under WEB-INF folder and
using path "/WEB-INF/applicationContext.xml" I failed access it from my bean.
public class BeanFinder {
/** Logger for this class and subclasses */
protected final Log log = LogFactory.getLog(getClass());
private static ApplicationContext ctx;
public Object getBean(ServletRequest request, String beanName) {
if (ctx == null) {
if (!(request instanceof HttpServletRequest)) {
throw new IllegalArgumentException("Can only process HttpServletRequest");
}
HttpServletRequest httpRequest = (HttpServletRequest) request;
ctx = getContext(httpRequest);
}
Object obj = new Object();
return obj;
}
public Resource getResource(String location){
Resource template = new ClassPathXmlApplicationContext().getResource(locat ion);
return template;
}
public Object getBean(String beanName) throws BeansException {
// String[] configLocation = "file:../WEB-INF/config/applicationContext-hibernate.xml";
// ctx = new FileSystemXmlApplicationContext(configLocation);
// String[] configLocation = {"classpath:/config/applicationContext.xml"};
String[] configLocation = {"classpath:applicationContext.xml"};
ctx = new ClassPathXmlApplicationContext(configLocation);
log.info("Context: " + ctx);
Object obj = ctx.getBean(beanName);
return obj;
}
/**
* Allows test cases to override where application context obtained from.
*
* @param httpRequest which can be used to find the <code>ServletContext</code>
*
* @return the Spring application context
*/
public ApplicationContext getContext(HttpServletRequest request) {
return WebApplicationContextUtils.getRequiredWebApplicati onContext(
request.getSession().getServletContext());
}
I want to access my config file by placing it under config folder. How can I achieve this. Please help me.
Thanks in advance.
rsrch