Results 1 to 7 of 7

Thread: NEWBIE Question: contextLoader not finding bean in context

  1. #1
    Join Date
    Oct 2004
    Posts
    5

    Default NEWBIE Question: contextLoader not finding bean in context

    I've just started using Spring and I am trying to wire up a few beans. I have a bean in an applicationContext.xml that is referenced in my springapp-servlet.xml file.

    I get the error

    Error creating bean with name 'springAppController' defined in resource [/WEB-INF/springapp-servlet.xml
    ] of ServletContext: Can't resolve reference to bean 'someBeanManager' while sett
    ing property

    Do I have to do anything specific in code or in a file to allow the xx-servlet.xml file and the contextLoader to get the beans from the applicationContext.xml?

    THis is the definition in my applicationContext.xml

    Code:
        <bean id="someBeanDAO" class="com.test.dao.SomeBeanDaoImpl">
    		<property name="sessionFactory"><ref local="sessionFactory"/></property>
        </bean>
       
    	<bean id="someBeanManager" class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean">
    		<property name="transactionManager"><ref local="transactionManager"/></property>
    		<property name="target"><ref local="someBeanDAO"/></property>
    		<property name="transactionAttributes">
    			<props>
    				<prop key="get*">PROPAGATION_REQUIRED,readOnly</prop>
    				<prop key="find*">PROPAGATION_REQUIRED,readOnly</prop>
    				<prop key="load*">PROPAGATION_REQUIRED,readOnly</prop>
    				<prop key="store*">PROPAGATION_REQUIRED</prop>
    			</props>
    		</property>
    	</bean>
    And in my springapp-servlet.xml I have

    Code:
        <bean id="springAppController" class="com.test.web.SpringAppController">
    		<property name="someBeanManager"><ref bean="packageManager"/></property>        
        </bean>

  2. #2
    Join Date
    Aug 2004
    Location
    Amsterdam, Netherlands
    Posts
    450

    Default

    Do I have to do anything specific in code or in a file to allow the xx-servlet.xml file and the contextLoader to get the beans from the applicationContext.xml?
    Yes, you have to include the applicationContext.xml in your contextConfigLocations parameter in web.xml. Have a look at web.xml from jPetstore (http://cvs.sourceforge.net/viewcvs.p...=1.9&view=auto) to see how it works.

    Code:
    <context-param>
      <param-name>contextConfigLocation</param-name>
      <param-value>
          /WEB-INF/applicationContext.xml
      </param-value>
    </context-param>
    You also have to include a ContextLoaderListener or ContextLoaderServlet (Depending on you servlet container). Examples can all be found in the file mentioned above.

    Hope this helps.
    Alef Arendsen
    SpringSource
    http://www.springsource.com

  3. #3
    Join Date
    Aug 2004
    Location
    Vrhnika, Slovenia
    Posts
    133

    Default

    Where do you have this <ref bean="packageManager"/> specified?

    Should this be vice versa?
    <property name="packageManager"><ref bean="someBeanManager"/></property>

    Rgds, Ales

  4. #4
    Join Date
    Oct 2004
    Posts
    5

    Default

    Hi, I've included that in (prior to your message). It is being called because I see this in the logs.

    Code:
    2004-10-31 08&#58;30&#58;02,714 INFO &#91;org.springframework.beans.factory.xml.XmlBeanDefin
    itionReader&#93; - <Loading XML bean definitions from resource &#91;/WEB-INF/application
    Context.xml&#93; of ServletContext>
    2004-10-31 08&#58;30&#58;03,435 INFO &#91;org.springframework.web.context.support.XmlWebAppl
    icationContext&#93; - <Bean factory for application context &#91;Root XmlWebApplicationC
    ontext&#93;&#58; org.springframework.beans.factory.support.DefaultListableBeanFactory de
    fining beans &#91;dataSource,sessionFactory,transactionManager,someBeanDAO,someBeanManager&#93;; Root of BeanFactory hierarchy>
    2004-10-31 08&#58;30&#58;03,975 INFO &#91;org.springframework.web.context.support.XmlWebAppl
    icationContext&#93; - <5 beans defined in ApplicationContext &#91;Root XmlWebApplication
    Context&#93;>
    Later on I see the message that the shared instance has been created.

  5. #5
    Join Date
    Oct 2004
    Posts
    5

    Default

    Quote Originally Posted by alesj
    Where do you have this <ref bean="packageManager"/> specified?

    Should this be vice versa?
    <property name="packageManager"><ref bean="someBeanManager"/></property>

    Rgds, Ales
    Sorry, typo.

    They both say "someBeanManager"

  6. #6
    Join Date
    Oct 2004
    Posts
    5

    Default

    My web.xml looks as follows:

    Code:
    	<context-param>
    		<param-name>contextConfigLocation</param-name>
    		<param-value>/WEB-INF/applicationContext.xml</param-value>
    	</context-param>
    
    	<servlet>
    		<servlet-name>context</servlet-name>
    		<servlet-class>org.springframework.web.context.ContextLoaderServlet</servlet-class>
    		<load-on-startup>1</load-on-startup>
    	</servlet>
        
        
        <servlet>
            <servlet-name>springapp</servlet-name>
            <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
            <load-on-startup>1</load-on-startup>
        </servlet>
    
        <servlet-mapping>
            <servlet-name>springapp</servlet-name>
            <url-pattern>*.html</url-pattern>
        </servlet-mapping>

  7. #7
    Join Date
    Oct 2004
    Posts
    5

    Default

    Found the problem. The dispatcher servlet was being loaded before the context loader. I switched that around and it works -- almost.

    Need to solve the "failed to convert property value" problem now.

Similar Threads

  1. Spring container fails with no exception
    By naor in forum Container
    Replies: 9
    Last Post: Oct 1st, 2005, 03:39 PM
  2. EHCaching Hibernate
    By dencamel in forum Data
    Replies: 3
    Last Post: Sep 6th, 2005, 09:03 PM
  3. Stack Overflow
    By rayho222 in forum Container
    Replies: 6
    Last Post: May 17th, 2005, 03:42 AM
  4. could not satisfy dependencies
    By springuser in forum Container
    Replies: 4
    Last Post: Apr 26th, 2005, 01:15 PM
  5. Replies: 1
    Last Post: Apr 25th, 2005, 07:37 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •