Announcement Announcement Module
Collapse
No announcement yet.
Unable to return specified BeanFactory instance Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Unable to return specified BeanFactory instance

    Hi All,

    i am getting the the error from index.jsp

    "org.apache.jasper.JasperException: org.springframework.beans.factory.access.Bootstrap Exception: Unable to return specified BeanFactory instance: factory key [beanFactory], from group with resource name [classpath*:beanRefContext.xml]; nested exception is org.springframework.beans.factory.NoSuchBeanDefini tionException: No bean named 'beanFactory' is defined
    org.apache.jasper.servlet.JspServletWrapper.handle JspException(JspServletWrapper.java:515)
    org.apache.jasper.servlet.JspServletWrapper.servic e(JspServletWrapper.java:411)
    org.apache.jasper.servlet.JspServlet.serviceJspFil e(JspServlet.java:322)
    org.apache.jasper.servlet.JspServlet.service(JspSe rvlet.java:249)
    javax.servlet.http.HttpServlet.service(HttpServlet .java:717)
    org.jboss.web.tomcat.filters.ReplyHeaderFilter.doF ilter(ReplyHeaderFilter.java:96)
    "

    [index.jsp]

    BeanFactoryLocator beanFactoryLoc = ContextSingletonBeanFactoryLocator.getInstance();
    BeanFactoryReference beanFactoryReference = beanFactoryLoc .useBeanFactory("beanFactory");
    BeanFactory beanFactory = beanFactoryReference.getFactory();

    [web.xml]
    <listener>
    <listener-class>org.springframework.web.context.ContextLoade rListener</listener-class>
    </listener>

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

    [beanRefContext.xml]

    <bean id="beanFactory" class="org.springframework.context.support.ClassPa thXmlApplicationContext">
    <constructor-arg>
    <list>
    <value type="java.lang.String">classpath*:springActivitiC ontext.xml</value>
    </list>
    </constructor-arg>
    </bean>
    </beans>

    Can somebody help me out?

    Thanks in advance.

    kt

  • #2
    Please use [ code][/code ] tags when posting code.. I suggest a read of the reference guide and javadocs of the classes you use... The way you use those beans isn't the way it is supposed to work.. Next to that you shouldn't need or even want to use a BeanFactory inside your jsps, in general that is a sign your page does to much (it should basically only render the data which is in the model).

    Simply use the ContextLoaderListener to load the springActivitiContext.xml and use the WebApplicationContextUtils to get access to that ApplicationContext (although I still strongly advice against that!).

    Comment

    Working...
    X