The moose likes Other Application Frameworks and the fly likes Problem getting Bean reference which is in jar from JSP Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Frameworks » Other Application Frameworks
Bookmark "Problem getting Bean reference which is in jar from JSP " Watch "Problem getting Bean reference which is in jar from JSP " New topic

Problem getting Bean reference which is in jar from JSP

Xavier George
Ranch Hand

Joined: Jul 29, 2005
Posts: 39
I am having problem getting the bean reference (which is in jar file) in JSP.
Everything works fine when I am running from RAD Locally but when I am porting to UNIX box test server it fails to get bean reference.

I am trying to get reference of bean/java class which is in the jar file from JSP page.
Error is - Unable to return specified BeanFactory instance: factory key [my-factory], from group with resource name [classpath*:beanRefFactory.xml]; nested exception is org.springframework.beans.factory.NoSuchBeanDefini tionException: No bean named 'my-Bean' is define


JSP calling methodA() of class Test which is in the jar file.
Code in JSP
BeanFactoryLocator beanFactoryLocator = SingletonBeanFactoryLocator.getInstance();
BeanFactoryReference beanFactoryReference = beanFactoryLocator.useBeanFactory("my-factory"); //*** HERE IS ERROR
bean = beanFactoryReference.getFactory().getBean("my-Bean");
catch(Throwable throwable)
System.out.println("\n\nProbem initializing BeanFactory : " + throwable.getMessage());

And structure of jar file which is in WEB-INF/lib

My beanRefFactory looks like this.
<?xml version="1.0" encoding="UTF-8"?>

<bean id="my-factory" class=" thXmlApplicationContext" lazy-init="true">

applicationContext is simlple bean definition with bean name as "my-Bean".

Even, I made following entry in web.xml(differenct different scenario/configuration)

<param-value>classpath*:/myconfig/applicationContext.xml myconfig/applicationContext.xml</param-value>

<param-value>classpath*:/beanRefContext.xml beanRefContext.xml</param-value>

<servlet-class>org.springframework.web.context.ContextLoade rServlet</servlet-class>
<listener-class>org.springframework.web.context.ContextLoade rListener</listener-class>

Any help will be highly appreciated, I want to resolve this error.
Christophe Verré

Joined: Nov 24, 2005
Posts: 14688

Where is the directory "myconfig". It must be somewhere in the classpath. If you're using a web application, a good bet is under the "classes" directory.

[My Blog]
All roads lead to JavaRanch
I agree. Here's the link:
subject: Problem getting Bean reference which is in jar from JSP
It's not a secret anymore!