Announcement Announcement Module
Collapse
No announcement yet.
Web Application Spring Usage from Main Servlet.service method Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Web Application Spring Usage from Main Servlet.service method

    I have the following Spring XML configuration files:
    • beanRefFactory.xml
    • applicationContext.xml,
    • applicationContext-dataSource.xml

    Which is configured in the web.xml as follows:
    Code:
    <context-param>
      <param-name>contextConfigLocation</param-name>
      <param-value>classpath:beanRefFactory.xml,
                  classpath:applicationContext.xml,
                  classpath:applicationContext-dataSource.xml
      </param-value>
    </context-param>
    and spring is loaded using
    Code:
    <listener>
      <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
    </listener>
    and I have Main Servlet configured as follows:
    Code:
    <servlet>
     <servlet-name>SCMSAction</servlet-name>
     <servlet-class>org.aliabdelaziz.gui.common.SCMSServlet</servlet-class>
    ...
     <init-param>
      <param-name>config</param-name>
      <param-value>
       /WEB-INF/struts-config-sch.xml,
       /WEB-INF/struts-config-adm.xml, 
       /WEB-INF/struts-config-inv.xml
      </param-value>
     </init-param>
       ...
     <load-on-startup>1</load-on-startup>
    </servlet>
    
    <servlet-mapping>
     <servlet-name>SCMSAction</servlet-name>
     <url-pattern>*.do</url-pattern>
    </servlet-mapping>
    and the following is my SCMSServlet
    public class SCMSServlet extends ActionServlet {
    .....
    public void service(HttpServletRequest request, HttpServletResponse response)
    throws IOException, ServletException {
    try {
    if(request.getRequestURI().indexOf(ADMIN_MODULE) != -1) {
    AMSClasspathUtils.initialise(); // Do some Spring calls
    PMSClasspathUtils.initialise(); // Do some Spring calls
    KMSClasspathUtils.initialise(); // Do some Spring calls
    }
    } catch (Exception e) {
    }
    ...
    }
    }
    And I have all my actions belongs to one of the following modules {INV, SCH, Admin}
    When I try to access any Action that is not in the Admin Module just after the WebApplication started; the spring calls get executed successfully without problems; Later if I tried to access Admin Actions it get executed successfully I guess because Spring get initialized successfully.

    Success Spring Logging messages
    Code:
    - Initializing composable request processor for module prefix ''
    - Initialize action of type: org.aliabdelaziz.scms.gui.invro.actions.card.stock.CardStockEditionAction
    - Refreshing org.springframework.context.support.ClassPathXmlApplicationContext@e9406c: display name [org.springframework.context.support.ClassPathXmlApplicationContext@e9406c]; startup date [Sun Apr 29 18:39:21 GMT+04:00 2012]; root of context hierarchy
    - Loading XML bean definitions from URL [jar:file:/D:/scms/scms-struts/build/web/WEB-INF/lib/scms-business.jar!/beanRefFactory.xml]
    - Bean factory for application context [org.springframework.context.support.ClassPathXmlApplicationContext@e9406c]: org.springframework.beans.factory.support.DefaultListableBeanFactory@e400a4
    - Pre-instantiating singletons in org.springframework.beans.factory.support.DefaultListableBeanFactory@e400a4: defining beans [beanRefFactory]; root of factory hierarchy
    - Refreshing org.springframework.context.support.ClassPathXmlApplicationContext@8af1c6: display name [org.springframework.context.support.ClassPathXmlApplicationContext@8af1c6]; startup date [Sun Apr 29 18:39:21 GMT+04:00 2012]; root of context hierarchy
    - Loading XML bean definitions from class path resource .....
    If I tried to access any of the Admin's Actions just after the web Application started I got the following Spring Exception (and the same thing happens with me if I tried to invoke WebServices Imediatly after my WebApplication Started and before invoking any {INV, SCH}'s Action to initialize the Spring)
    "org.springframework.beans.factory.NoSuchBeanDefini tionException: No bean named 'beanRefFactory' is defined"

    Code:
    2012-04-29 19:01:50,648 ["http-bio-9082"-exec-26] INFO  org.aliabdelaziz.fwk.SCMSClassLoader  - SCMS AMS ClassLoader initialisation complete.
    - SCMS AMS ClassLoader initialisation complete.
    2012-04-30 10:20:52,891 ["http-bio-9082"-exec-26] ERROR org.aliabdelaziz.fwk.logs.SCMSLogManager  - Component SCMS		error.scms.kms.configuration
    org.springframework.beans.factory.access.BootstrapException: Unable to return specified BeanFactory instance: factory key [beanRefFactory], from group with resource name [classpath*:beanRefFactory.xml]; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'beanRefFactory' is defined
    Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'beanRefFactory' is defined
    	at org.springframework.beans.factory.support.DefaultListableBeanFactory.getBeanDefinition(DefaultListableBeanFactory.java:356)
    	at org.springframework.beans.factory.support.AbstractBeanFactory.getMergedBeanDefinition(AbstractBeanFactory.java:916)
    	at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:243)
    	at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:160)
    	at org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:733)
    	at org.springframework.beans.factory.access.SingletonBeanFactoryLocator.useBeanFactory(SingletonBeanFactoryLocator.java:395)
    	at org.aliabdelaziz.scms.ServiceLocator.getContext(ServiceLocator.java:106)
    	at org.aliabdelaziz.scms.ServiceLocator.getClasspathService(ServiceLocator.java:156)
    	at org.aliabdelaziz.scms.web.ext.kms.KMSClasspathUtils.resetKMSClassloader(KMSClasspathUtils.java:62)
    	at org.aliabdelaziz.scms.web.ext.kms.KMSClasspathUtils.initialise(KMSClasspathUtils.java:42)
    	at org.aliabdelaziz.scms.gui.common.SCMSServlet.service(SCMSServlet.java:91)
    	at javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
    	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:304)
    	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
    	at org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:684)
    	...
    	at java.lang.Thread.run(Thread.java:662)
    - Component SCMS		error.scms.kms.configuration
    org.springframework.beans.factory.access.BootstrapException: Unable to return specified BeanFactory instance: factory key [beanRefFactory], from group with resource name [classpath*:beanRefFactory.xml]; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'beanRefFactory' is defined
    Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'beanRefFactory' is defined
    	at org.springframework.beans.factory.support.DefaultListableBeanFactory.getBeanDefinition(DefaultListableBeanFactory.java:356)
    	at org.springframework.beans.factory.support.AbstractBeanFactory.getMergedBeanDefinition(AbstractBeanFactory.java:916)
    	at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:243)
    	at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:160)
    	at org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:733)
    	at org.springframework.beans.factory.access.SingletonBeanFactoryLocator.useBeanFactory(SingletonBeanFactoryLocator.java:395)
    	at org.aliabdelaziz.scms.ServiceLocator.getContext(ServiceLocator.java:106)
    	at org.aliabdelaziz.scms.ServiceLocator.getClasspathService(ServiceLocator.java:156)
    	at org.aliabdelaziz.scms.web.ext.kms.KMSClasspathUtils.resetKMSClassloader(KMSClasspathUtils.java:62)
    	at org.aliabdelaziz.scms.web.ext.kms.KMSClasspathUtils.initialise(KMSClasspathUtils.java:42)
    	at org.aliabdelaziz.scms.gui.common.SCMSServlet.service(SCMSServlet.java:91)
    ...
    log4j:ERROR Failed to rename [d:/temp/scms.txt] to [d:/temp/scms.txt.2012-04-29].
    - Initializing composable request processor for module prefix ''
    2012-04-30 10:21:10,448 ["http-bio-9082"-exec-26] ERROR org.aliabdelaziz.scms.gui.common.SCMSServlet  - Caught an exception while processing the request /scms/admin/conf/main.do
    javax.servlet.ServletException: Cannot find catalog 'struts'
    	at org.apache.struts.chain.ComposableRequestProcessor.init(ComposableRequestProcessor.java:161)
    	at org.apache.struts.action.ActionServlet.getRequestProcessor(ActionServlet.java:620)
    	at org.apache.struts.action.ActionServlet.process(ActionServlet.java:1910)
    	at org.apache.struts.action.ActionServlet.doGet(ActionServlet.java:449)
    	at javax.servlet.http.HttpServlet.service(HttpServlet.java:621)
    	at org.aliabdelaziz.scms.gui.common.SCMSServlet.service(SCMSServlet.java:99)
    	at javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
    	...
    	at javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
    	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:304)
    	...
    	at java.lang.Thread.run(Thread.java:662)
    - Caught an exception while processing the request /scms/admin/conf/main.do
    javax.servlet.ServletException: Cannot find catalog 'struts'
    	at org.apache.struts.chain.ComposableRequestProcessor.init(ComposableRequestProcessor.java:161)
    	at org.apache.struts.action.ActionServlet.getRequestProcessor(ActionServlet.java:620)
    	at org.apache.struts.action.ActionServlet.process(ActionServlet.java:1910)
    	at org.apache.struts.action.ActionServlet.doGet(ActionServlet.java:449)
    	at javax.servlet.http.HttpServlet.service(HttpServlet.java:621)
    	at org.aliabdelaziz.scms.gui.common.SCMSServlet.service(SCMSServlet.java:99)
    	at javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
    	...
    So How can I fix this? Do I need to load Spring manually as standalone in the places that get this spring exceptions?
    Last edited by Ali Abdel-Aziz; Apr 30th, 2012, 04:19 AM. Reason: formatting
Working...
X