Announcement Announcement Module
Collapse
No announcement yet.
newbie question Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • newbie question

    Hi,

    i am starting with spring and i cannot put it to work into my servlet container (IBM WSAD 5).

    The sample is as follows:
    - i've added the listener to the web.xml config file:
    Code:
    <listener>
      <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
    </listener>
    - the bean is quite simple:
    Code:
    package test;
    
    public class BeanTest &#123;
    	
    	private String field;
    
    	public String getField&#40;&#41; &#123;
    		return field;
    	&#125;
    
    	public void setField&#40;String field&#41; &#123;
    		this.field = field;
    	&#125;
    &#125;
    - the spring config file at WEB-INF/applicationContext.xml:
    Code:
    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http&#58;//www.springframework.org/dtd/spring-beans.dtd">
    
    <beans>
    	<bean id="myBean" class="test.BeanTest">
    		<property name="field"><value>testFieldValue</value></property>										
    	</bean>
    </beans>
    - the servlet get method:
    Code:
    public void doGet&#40;HttpServletRequest request, HttpServletResponse response&#41;
    						throws ServletException, IOException &#123;
    
    	WebApplicationContext wac = WebApplicationContextUtils.getWebApplicationContext&#40;getServletContext&#40;&#41;&#41;;
    	BeanTest bt = &#40;BeanTest&#41; wac.getBean&#40;"myBean"&#41;;
    		
    	response.setContentType&#40;"text/plain"&#41;;
    	response.getWriter&#40;&#41;.println&#40;bt.getField&#40;&#41;&#41;;
    &#125;
    When the container starts it throws the following messages:

    Error registering bean with name 'myBean' defined in ServletContext resource [/WEB-INF/applicationContext.xml]: Bean class [test.BeanTest] not found; nested exception is java.lang.ClassNotFoundException: test.BeanTest java.lang.ClassNotFoundException: test.BeanTest

    The stackTrace:

    Code:
    &#91;21/04/05 12&#58;23&#58;59&#58;246 CEST&#93; 1c7de748 ContextLoader I org.springframework.web.context.ContextLoader  Root WebApplicationContext&#58; initialization started
    &#91;21/04/05 12&#58;23&#58;59&#58;246 CEST&#93; 1c7de748 WebGroup      I SRVE0180I&#58; &#91;SpringWebTest&#93; &#91;/SpringWebTest&#93; &#91;Servlet.LOG&#93;&#58; Loading Spring root WebApplicationContext
    &#91;21/04/05 12&#58;23&#58;59&#58;871 CEST&#93; 1c7de748 XmlBeanDefini I org.springframework.beans.factory.xml.XmlBeanDefinitionReader  Loading XML bean definitions from ServletContext resource &#91;/WEB-INF/applicationContext.xml&#93;
    &#91;21/04/05 12&#58;24&#58;00&#58;090 CEST&#93; 1c7de748 ContextLoader E org.springframework.web.context.ContextLoader  Context initialization failed
    &#91;21/04/05 12&#58;24&#58;00&#58;105 CEST&#93; 1c7de748 ContextLoader E org.springframework.web.context.ContextLoader  TRAS0014I&#58; The following Exception was caught&#58; org.springframework.beans.factory.BeanDefinitionStoreException&#58; Error registering bean with name 'myBean' defined in ServletContext resource &#91;/WEB-INF/applicationContext.xml&#93;&#58; Bean class &#91;test.BeanTest&#93; not found; nested exception is java.lang.ClassNotFoundException&#58; test.BeanTest java.lang.ClassNotFoundException&#58; test.BeanTest
    	at java.net.URLClassLoader.findClass&#40;URLClassLoader.java&#58;240&#41;
    	at com.ibm.ws.bootstrap.ExtClassLoader.findClass&#40;ExtClassLoader.java&#58;38&#41;
    	at java.lang.ClassLoader.loadClass&#40;ClassLoader.java&#58;516&#41;
    	at java.lang.ClassLoader.loadClass&#40;ClassLoader.java&#58;448&#41;
    	at java.lang.Class.forName0&#40;Native Method&#41;
    	at java.lang.Class.forName&#40;Class.java&#58;220&#41;
    	at org.springframework.util.ClassUtils.forName&#40;ClassUtils.java&#58;84&#41;
    	at org.springframework.beans.factory.support.BeanDefinitionReaderUtils.createBeanDefinition&#40;BeanDefinitionReaderUtils.java&#58;61&#41;
    	at org.springframework.beans.factory.xml.DefaultXmlBeanDefinitionParser.parseBeanDefinitionElement&#40;DefaultXmlBeanDefinitionParser.java&#58;331&#41;
    	at org.springframework.beans.factory.xml.DefaultXmlBeanDefinitionParser.parseBeanDefinitionElement&#40;DefaultXmlBeanDefinitionParser.java&#58;299&#41;
    	at org.springframework.beans.factory.xml.DefaultXmlBeanDefinitionParser.parseBeanDefinitions&#40;DefaultXmlBeanDefinitionParser.java&#58;236&#41;
    	at org.springframework.beans.factory.xml.DefaultXmlBeanDefinitionParser.registerBeanDefinitions&#40;DefaultXmlBeanDefinitionParser.java&#58;185&#41;
    	at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.registerBeanDefinitions&#40;XmlBeanDefinitionReader.java&#58;188&#41;
    	at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions&#40;XmlBeanDefinitionReader.java&#58;146&#41;
    	at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions&#40;AbstractBeanDefinitionReader.java&#58;99&#41;
    	at org.springframework.web.context.support.XmlWebApplicationContext.loadBeanDefinitions&#40;XmlWebApplicationContext.java&#58;114&#41;
    	at org.springframework.web.context.support.XmlWebApplicationContext.loadBeanDefinitions&#40;XmlWebApplicationContext.java&#58;82&#41;
    	at org.springframework.context.support.AbstractRefreshableApplicationContext.refreshBeanFactory&#40;AbstractRefreshableApplicationContext.java&#58;87&#41;
    	at org.springframework.context.support.AbstractApplicationContext.refresh&#40;AbstractApplicationContext.java&#58;264&#41;
    	at org.springframework.web.context.support.AbstractRefreshableWebApplicationContext.refresh&#40;AbstractRefreshableWebApplicationContext.java&#58;131&#41;
    	at org.springframework.web.context.ContextLoader.createWebApplicationContext&#40;ContextLoader.java&#58;230&#41;
    	at org.springframework.web.context.ContextLoader.initWebApplicationContext&#40;ContextLoader.java&#58;156&#41;
    	at org.springframework.web.context.ContextLoaderListener.contextInitialized&#40;ContextLoaderListener.java&#58;48&#41;
    	at com.ibm.ws.webcontainer.srt.WebGroup.notifyServletContextCreated&#40;WebGroup.java&#58;1358&#41;
    	at com.ibm.ws.webcontainer.srt.WebGroup.init&#40;WebGroup.java&#58;240&#41;
    	at com.ibm.ws.webcontainer.WebContainer.addWebApplication&#40;WebContainer.java&#58;950&#41;
    	at com.ibm.ws.runtime.component.WebContainerImpl.install&#40;WebContainerImpl.java&#58;133&#41;
    	at com.ibm.ws.runtime.component.WebContainerImpl.start&#40;WebContainerImpl.java&#58;360&#41;
    	at com.ibm.ws.runtime.component.ApplicationMgrImpl.start&#40;ApplicationMgrImpl.java&#58;401&#41;
    	at com.ibm.ws.runtime.component.DeployedApplicationImpl.fireDeployedObjectStart&#40;DeployedApplicationImpl.java&#58;743&#41;
    	at com.ibm.ws.runtime.component.DeployedModuleImpl.start&#40;DeployedModuleImpl.java&#58;337&#41;
    	at com.ibm.ws.runtime.component.DeployedApplicationImpl.start&#40;DeployedApplicationImpl.java&#58;531&#41;
    	at com.ibm.ws.runtime.component.ApplicationMgrImpl.startApplication&#40;ApplicationMgrImpl.java&#58;254&#41;
    	at com.ibm.ws.runtime.component.ApplicationMgrImpl.start&#40;ApplicationMgrImpl.java&#58;232&#41;
    	at com.ibm.ws.runtime.component.ContainerImpl.startComponents&#40;ContainerImpl.java&#58;343&#41;
    	at com.ibm.ws.runtime.component.ContainerImpl.start&#40;ContainerImpl.java&#58;234&#41;
    	at com.ibm.ws.runtime.component.ApplicationServerImpl.start&#40;ApplicationServerImpl.java&#58;117&#41;
    	at com.ibm.ws.runtime.component.ContainerImpl.startComponents&#40;ContainerImpl.java&#58;343&#41;
    	at com.ibm.ws.runtime.component.ContainerImpl.start&#40;ContainerImpl.java&#58;234&#41;
    	at com.ibm.ws.runtime.component.ServerImpl.start&#40;ServerImpl.java&#58;182&#41;
    	at com.ibm.ws.runtime.WsServer.start&#40;WsServer.java&#58;135&#41;
    	at com.ibm.ws.runtime.WsServer.main&#40;WsServer.java&#58;232&#41;
    	at java.lang.reflect.Method.invoke&#40;Native Method&#41;
    	at com.ibm.ws.bootstrap.WSLauncher.main&#40;WSLauncher.java&#58;94&#41;
    	at com.ibm.etools.websphere.tools.runner.api.ServerRunnerV5$1.run&#40;ServerRunnerV5.java&#58;97&#41;
    .
                                     org.springframework.beans.factory.BeanDefinitionStoreException&#58; Error registering bean with name 'myBean' defined in ServletContext resource &#91;/WEB-INF/applicationContext.xml&#93;&#58; Bean class &#91;test.BeanTest&#93; not found; nested exception is java.lang.ClassNotFoundException&#58; test.BeanTest
    java.lang.ClassNotFoundException&#58; test.BeanTest
    	at java.net.URLClassLoader.findClass&#40;URLClassLoader.java&#58;240&#41;
    	at com.ibm.ws.bootstrap.ExtClassLoader.findClass&#40;ExtClassLoader.java&#58;38&#41;
    	at java.lang.ClassLoader.loadClass&#40;ClassLoader.java&#58;516&#41;
    	at java.lang.ClassLoader.loadClass&#40;ClassLoader.java&#58;448&#41;
    	at java.lang.Class.forName0&#40;Native Method&#41;
    	at java.lang.Class.forName&#40;Class.java&#58;220&#41;
    	at org.springframework.util.ClassUtils.forName&#40;ClassUtils.java&#58;84&#41;
    	at org.springframework.beans.factory.support.BeanDefinitionReaderUtils.createBeanDefinition&#40;BeanDefinitionReaderUtils.java&#58;61&#41;
    	at org.springframework.beans.factory.xml.DefaultXmlBeanDefinitionParser.parseBeanDefinitionElement&#40;DefaultXmlBeanDefinitionParser.java&#58;331&#41;
    	at org.springframework.beans.factory.xml.DefaultXmlBeanDefinitionParser.parseBeanDefinitionElement&#40;DefaultXmlBeanDefinitionParser.java&#58;299&#41;
    	at org.springframework.beans.factory.xml.DefaultXmlBeanDefinitionParser.parseBeanDefinitions&#40;DefaultXmlBeanDefinitionParser.java&#58;236&#41;
    	at org.springframework.beans.factory.xml.DefaultXmlBeanDefinitionParser.registerBeanDefinitions&#40;DefaultXmlBeanDefinitionParser.java&#58;185&#41;
    	at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.registerBeanDefinitions&#40;XmlBeanDefinitionReader.java&#58;188&#41;
    	at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions&#40;XmlBeanDefinitionReader.java&#58;146&#41;
    	at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions&#40;AbstractBeanDefinitionReader.java&#58;99&#41;
    	at org.springframework.web.context.support.XmlWebApplicationContext.loadBeanDefinitions&#40;XmlWebApplicationContext.java&#58;114&#41;
    	at org.springframework.web.context.support.XmlWebApplicationContext.loadBeanDefinitions&#40;XmlWebApplicationContext.java&#58;82&#41;
    	at org.springframework.context.support.AbstractRefreshableApplicationContext.refreshBeanFactory&#40;AbstractRefreshableApplicationContext.java&#58;87&#41;
    	at org.springframework.context.support.AbstractApplicationContext.refresh&#40;AbstractApplicationContext.java&#58;264&#41;
    	at org.springframework.web.context.support.AbstractRefreshableWebApplicationContext.refresh&#40;AbstractRefreshableWebApplicationContext.java&#58;131&#41;
    	at org.springframework.web.context.ContextLoader.createWebApplicationContext&#40;ContextLoader.java&#58;230&#41;
    	at org.springframework.web.context.ContextLoader.initWebApplicationContext&#40;ContextLoader.java&#58;156&#41;
    	at org.springframework.web.context.ContextLoaderListener.contextInitialized&#40;ContextLoaderListener.java&#58;48&#41;
    	at com.ibm.ws.webcontainer.srt.WebGroup.notifyServletContextCreated&#40;WebGroup.java&#58;1358&#41;
    	at com.ibm.ws.webcontainer.srt.WebGroup.init&#40;WebGroup.java&#58;240&#41;
    	at com.ibm.ws.webcontainer.WebContainer.addWebApplication&#40;WebContainer.java&#58;950&#41;
    	at com.ibm.ws.runtime.component.WebContainerImpl.install&#40;WebContainerImpl.java&#58;133&#41;
    	at com.ibm.ws.runtime.component.WebContainerImpl.start&#40;WebContainerImpl.java&#58;360&#41;
    	at com.ibm.ws.runtime.component.ApplicationMgrImpl.start&#40;ApplicationMgrImpl.java&#58;401&#41;
    	at com.ibm.ws.runtime.component.DeployedApplicationImpl.fireDeployedObjectStart&#40;DeployedApplicationImpl.java&#58;743&#41;
    	at com.ibm.ws.runtime.component.DeployedModuleImpl.start&#40;DeployedModuleImpl.java&#58;337&#41;
    	at com.ibm.ws.runtime.component.DeployedApplicationImpl.start&#40;DeployedApplicationImpl.java&#58;531&#41;
    	at com.ibm.ws.runtime.component.ApplicationMgrImpl.startApplication&#40;ApplicationMgrImpl.java&#58;254&#41;
    	at com.ibm.ws.runtime.component.ApplicationMgrImpl.start&#40;ApplicationMgrImpl.java&#58;232&#41;
    	at com.ibm.ws.runtime.component.ContainerImpl.startComponents&#40;ContainerImpl.java&#58;343&#41;
    	at com.ibm.ws.runtime.component.ContainerImpl.start&#40;ContainerImpl.java&#58;234&#41;
    	at com.ibm.ws.runtime.component.ApplicationServerImpl.start&#40;ApplicationServerImpl.java&#58;117&#41;
    	at com.ibm.ws.runtime.component.ContainerImpl.startComponents&#40;ContainerImpl.java&#58;343&#41;
    	at com.ibm.ws.runtime.component.ContainerImpl.start&#40;ContainerImpl.java&#58;234&#41;
    	at com.ibm.ws.runtime.component.ServerImpl.start&#40;ServerImpl.java&#58;182&#41;
    	at com.ibm.ws.runtime.WsServer.start&#40;WsServer.java&#58;135&#41;
    	at com.ibm.ws.runtime.WsServer.main&#40;WsServer.java&#58;232&#41;
    	at java.lang.reflect.Method.invoke&#40;Native Method&#41;
    	at com.ibm.ws.bootstrap.WSLauncher.main&#40;WSLauncher.java&#58;94&#41;
    	at com.ibm.etools.websphere.tools.runner.api.ServerRunnerV5$1.run&#40;ServerRunnerV5.java&#58;97&#41;
    Also, i've tried to find the clas by name Class.forName("test.BeanTest"); and it works so the class is there...

    The same code runs fine as stand-alone java app:
    Code:
      BeanFactory beanFactory = new FileSystemXmlApplicationContext&#40;"applicationContext.xml"&#41;;
      BeanTest bt = &#40;BeanTest&#41; beanFactory.getBean&#40;"myBean"&#41;;
    		
      System.out.println&#40;bt.getField&#40;&#41;&#41;;
    Well... Thanks!

  • #2
    i am using spring 1.2 RC2

    Comment


    • #3
      I know its a twisted view, but WSAD test environment might call the listener before loading web application classes so it couldnt access test.BeanTest class. Anyone knows if is that possible? Any way to correct it?

      I've run a dumb test configuring a String instead my bean and it does the right thing...
      Code:
      <beans>
      	<bean id="myBean" class="java.lang.String">
      		<constructor-arg><value>myValue</value></constructor-arg>
      	</bean>
      </beans>

      Comment


      • #4
        well...

        the class is available when the ContextListener performs the configuration load process: i've coded ny BeanTest as a listener and executed it before spring's one so it's loaded at least in the same name space.

        What is wrong?

        Comment


        • #5
          I think I know the answer to this. I read it from Spring in Action this morning. It seems that WebSphere 5.x does not initialise listeners before servlets. Try something like this instead:

          Code:
          <servlet>
            <servlet-name>context</servlet-name>
            <servlet-class>org.springframework.web.context.ContextLoaderServlet</servlet-class>
            <load-on-startup>1</load-on-startup>
          </servlet>

          Comment


          • #6
            It worked...

            I've got that book at univerity but couldn't find anything!

            Thanks

            Comment


            • #7
              Glad to help. I've got the eBook (or Digital Edition as is it now) - useful for searching in. Page 274 if you're interested.

              Cheers

              Comment

              Working...
              X