Announcement Announcement Module
Collapse
No announcement yet.
Unable to fine a bean definition in a separated file Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Unable to fine a bean definition in a separated file

    Hi,

    I don't know whether I can get any help from this forum or not. Here is my problem. I have a bean referred in my servelt.xml file, but is definited in the "applicationContext.xml" file. In my web.xml file, I have the following:

    <context-param>
    <param-name>contextConfigLocation</param-name>
    <param-value>/WEB-INF/applicationContext.xml /WEB-INF/applicationContext-hibernate.xml</param-value>
    </context-param>

    I get an error, "no bean name 'xxx' is definited ", when I try to bring the application.

    I have a look through the log files and unable to see the cause of the problem. Any suggestions on how to find out the cause?

    Thanks very much in advance.




  • #2
    If you have defined the bean in the applicationContext.xml file and refer to it from the server.xml file, it should work. The other way around doesn't!!

    rgds,
    Alef Arendsen

    Comment


    • #3
      Any suggestions on how to find out the cause?
      Post the relevant part of config. files and the stack trace.

      Comment


      • #4
        Originally posted by katentim
        Any suggestions on how to find out the cause?
        Post the relevant part of config. files and the stack trace.
        Thanks both for your responses.

        In the servlet.xml file, I have

        <!-- Users controllers & validators -->
        <bean id="userController" class="com.xxx.web.user.UserController">
        <property name="communityManager"><ref bean="communityManager"/></property>
        <property name="methodNameResolver"><ref local="userControllerMethodResolver"/></property>
        </bean>

        In the applicationContext.xml file, I have

        <bean id="communityManager" class="com.xxx.biz.CommunityManagerImpl">
        <property name="entryDao">
        <ref bean="entryDao"/>
        </property>
        <property name="userDao">
        <ref bean="userDao"/>
        </property>
        <property name="attachmentDao">
        <ref bean="attachmentDao"/>
        </property>
        </bean>

        where the DAOs are definited in the applicationContext-hibernate.xml file.

        The related messages in the stout file are the followings:

        3-Apr-2005 4:45:11 PM org.apache.catalina.core.StandardHostDeployer install
        INFO: Installing web application at context path /jsp-examples from URL file:C:\Program Files\Apache Software Foundation\Tomcat 5.0\webapps\jsp-examples
        3-Apr-2005 4:45:12 PM org.apache.catalina.core.StandardHostDeployer install
        INFO: Installing web application at context path from URL file:C:\Program Files\Apache Software Foundation\Tomcat 5.0\webapps\ROOT
        3-Apr-2005 4:45:12 PM org.apache.catalina.core.StandardHostDeployer install
        INFO: Installing web application at context path /servlets-examples from URL file:C:\Program Files\Apache Software Foundation\Tomcat 5.0\webapps\servlets-examples
        3-Apr-2005 4:45:12 PM org.apache.catalina.core.StandardHostDeployer install
        INFO: Installing web application at context path /tomcat-docs from URL file:C:\Program Files\Apache Software Foundation\Tomcat 5.0\webapps\tomcat-docs
        3-Apr-2005 4:45:12 PM org.apache.catalina.core.StandardHostDeployer install
        INFO: Installing web application at context path /webdav from URL file:C:\Program Files\Apache Software Foundation\Tomcat 5.0\webapps\webdav
        3-Apr-2005 4:45:12 PM org.apache.coyote.http11.Http11Protocol start
        INFO: Starting Coyote HTTP/1.1 on http-80
        3-Apr-2005 4:45:13 PM org.apache.jk.common.ChannelSocket init
        INFO: JK2: ajp13 listening on /0.0.0.0:8009
        3-Apr-2005 4:45:13 PM org.apache.jk.server.JkMain start
        INFO: Jk running ID=0 time=31/62 config=C:\Program Files\Apache Software Foundation\Tomcat 5.0\conf\jk2.properties
        3-Apr-2005 4:45:13 PM org.apache.catalina.startup.Catalina start
        INFO: Server startup in 16766 ms
        2005-04-03 16:45:13,546 INFO org.springframework.web.servlet.DispatcherServlet - Initializing servlet 'icommunity'
        2005-04-03 16:45:13,546 INFO org.springframework.web.servlet.DispatcherServlet - FrameworkServlet 'icommunity': initialization started
        2005-04-03 16:45:13,546 INFO org.springframework.beans.factory.xml.XmlBeanDefin itionReader - Loading XML bean definitions from ServletContext resource [/WEB-INF/icommunity-servlet.xml]
        2005-04-03 16:45:13,578 INFO org.springframework.web.context.support.XmlWebAppl icationContext - Bean factory for application context [WebApplicationContext for namespace 'icommunity-servlet']: org.springframework.beans.factory.support.DefaultL istableBeanFactory defining beans [multipartResolver,messageSource,tilesConfigurer,ur lMapping,viewResolver,userController,userControlle rMethodResolver,userValidator,userFormController,e ntryController,entryControllerMethodResolver,commu nityController,communityControllerMethodResolver,s ecureHandlerMapping,signonInterceptor,secure_editU ser,secure_action,secureCommunityControllerMethodR esolver,secure_entry,secureEntryControllerMethodRe solver,entryValidator,secure_editEntry,secure_atta chment,attachmentControllerMethodResolver]; root of BeanFactory hierarchy
        2005-04-03 16:45:13,578 INFO org.springframework.web.context.support.XmlWebAppl icationContext - 24 beans defined in application context [WebApplicationContext for namespace 'icommunity-servlet']
        2005-04-03 16:45:13,578 INFO org.springframework.beans.factory.support.DefaultL istableBeanFactory - Creating shared instance of singleton bean 'messageSource'
        2005-04-03 16:45:13,578 INFO org.springframework.web.context.support.XmlWebAppl icationContext - Using MessageSource [org.springframework.context.support.ResourceBundle MessageSource: basenames=[messages]]
        2005-04-03 16:45:13,578 INFO org.springframework.web.context.support.XmlWebAppl icationContext - Unable to locate ApplicationEventMulticaster with name 'applicationEventMulticaster': using default [org.springframework.context.event.SimpleApplicatio nEventMulticaster@d0357a]
        2005-04-03 16:45:13,578 INFO org.springframework.ui.context.support.UiApplicati onContextUtils - No ThemeSource found for [WebApplicationContext for namespace 'icommunity-servlet']: using ResourceBundleThemeSource
        2005-04-03 16:45:13,578 INFO org.springframework.web.context.support.XmlWebAppl icationContext - Refreshing listeners
        2005-04-03 16:45:13,578 INFO org.springframework.beans.factory.support.DefaultL istableBeanFactory - Pre-instantiating singletons in factory [org.springframework.beans.factory.support.DefaultL istableBeanFactory defining beans [multipartResolver,messageSource,tilesConfigurer,ur lMapping,viewResolver,userController,userControlle rMethodResolver,userValidator,userFormController,e ntryController,entryControllerMethodResolver,commu nityController,communityControllerMethodResolver,s ecureHandlerMapping,signonInterceptor,secure_editU ser,secure_action,secureCommunityControllerMethodR esolver,secure_entry,secureEntryControllerMethodRe solver,entryValidator,secure_editEntry,secure_atta chment,attachmentControllerMethodResolver]; root of BeanFactory hierarchy]
        2005-04-03 16:45:13,578 INFO org.springframework.beans.factory.support.DefaultL istableBeanFactory - Creating shared instance of singleton bean 'multipartResolver'
        2005-04-03 16:45:13,578 INFO org.springframework.beans.factory.support.DefaultL istableBeanFactory - Creating shared instance of singleton bean 'tilesConfigurer'
        2005-04-03 16:45:13,578 INFO org.springframework.web.servlet.view.tiles.TilesCo nfigurer - TilesConfigurer: adding definitions [/WEB-INF/defs/definitions.xml]
        2005-04-03 16:45:13,656 INFO org.springframework.beans.factory.support.DefaultL istableBeanFactory - Creating shared instance of singleton bean 'urlMapping'
        2005-04-03 16:45:13,656 INFO org.springframework.beans.factory.support.DefaultL istableBeanFactory - Creating shared instance of singleton bean 'communityController'
        2005-04-03 16:45:13,656 INFO com.xxx.web.CommunityController - Found action method [public org.springframework.web.servlet.ModelAndView com.xxx.web.CommunityController.helloHandler(javax .servlet.http.HttpServletRequest,javax.servlet.htt p.HttpServletResponse) throws javax.servlet.ServletException]
        2005-04-03 16:45:13,656 INFO com.xxx.web.CommunityController - Found action method [public org.springframework.web.servlet.ModelAndView com.xxx.web.CommunityController.categoryHandler(ja vax.servlet.http.HttpServletRequest,javax.servlet. http.HttpServletResponse) throws javax.servlet.ServletException]
        2005-04-03 16:45:13,656 INFO com.xxx.web.CommunityController - Found action method [public org.springframework.web.servlet.ModelAndView com.xxx.web.CommunityController.cityHandler(javax. servlet.http.HttpServletRequest,javax.servlet.http .HttpServletResponse) throws javax.servlet.ServletException]
        2005-04-03 16:45:13,656 INFO xxx.web.CommunityController - Found action method [public org.springframework.web.servlet.ModelAndView com.xxx.web.CommunityController.selectCityHandler( javax.servlet.http.HttpServletRequest,javax.servle t.http.HttpServletResponse) throws javax.servlet.ServletException]
        2005-04-03 16:45:13,656 INFO com.xxx.web.CommunityController - Found action method [public org.springframework.web.servlet.ModelAndView com.xxx.web.CommunityController.helpHandler(javax. servlet.http.HttpServletRequest,javax.servlet.http .HttpServletResponse) throws javax.servlet.ServletException]
        2005-04-03 16:45:13,656 INFO com.xxx.web.CommunityController - Found action method [public org.springframework.web.servlet.ModelAndView com.xxx.web.CommunityController.signoffHandle(java x.servlet.http.HttpServletRequest,javax.servlet.ht tp.HttpServletResponse) throws java.lang.Exception]
        2005-04-03 16:45:13,656 INFO com.xxx.web.CommunityController - Found action method [public final org.springframework.web.servlet.ModelAndView org.springframework.web.servlet.mvc.AbstractContro ller.handleRequest(javax.servlet.http.HttpServletR equest,javax.servlet.http.HttpServletResponse) throws java.lang.Exception]
        2005-04-03 16:45:13,656 INFO org.springframework.beans.factory.support.DefaultL istableBeanFactory - Destroying singletons in factory {org.springframework.beans.factory.support.Default ListableBeanFactory defining beans [multipartResolver,messageSource,tilesConfigurer,ur lMapping,viewResolver,userController,userControlle rMethodResolver,userValidator,userFormController,e ntryController,entryControllerMethodResolver,commu nityController,communityControllerMethodResolver,s ecureHandlerMapping,signonInterceptor,secure_editU ser,secure_action,secureCommunityControllerMethodR esolver,secure_entry,secureEntryControllerMethodRe solver,entryValidator,secure_editEntry,secure_atta chment,attachmentControllerMethodResolver]; root of BeanFactory hierarchy}
        2005-04-03 16:45:13,656 INFO org.springframework.beans.factory.support.DefaultL istableBeanFactory - Destroying inner beans in factory {org.springframework.beans.factory.support.Default ListableBeanFactory defining beans [multipartResolver,messageSource,tilesConfigurer,ur lMapping,viewResolver,userController,userControlle rMethodResolver,userValidator,userFormController,e ntryController,entryControllerMethodResolver,commu nityController,communityControllerMethodResolver,s ecureHandlerMapping,signonInterceptor,secure_editU ser,secure_action,secureCommunityControllerMethodR esolver,secure_entry,secureEntryControllerMethodRe solver,entryValidator,secure_editEntry,secure_atta chment,attachmentControllerMethodResolver]; root of BeanFactory hierarchy}
        2005-04-03 16:45:13,656 ERROR org.springframework.web.servlet.DispatcherServlet - Context initialization failed
        org.springframework.beans.factory.BeanCreationExce ption: Error creating bean with name 'communityController' defined in ServletContext resource [/WEB-INF/icommunity-servlet.xml]: Can't resolve reference to bean 'communityManager' while setting property 'communityManager'; nested exception is org.springframework.beans.factory.NoSuchBeanDefini tionException: No bean named 'communityManager' is defined: org.springframework.beans.factory.support.DefaultL istableBeanFactory defining beans [multipartResolver,messageSource,tilesConfigurer,ur lMapping,viewResolver,userController,userControlle rMethodResolver,userValidator,userFormController,e ntryController,entryControllerMethodResolver,commu nityController,communityControllerMethodResolver,s ecureHandlerMapping,signonInterceptor,secure_editU ser,secure_action,secureCommunityControllerMethodR esolver,secure_entry,secureEntryControllerMethodRe solver,entryValidator,secure_editEntry,secure_atta chment,attachmentControllerMethodResolver]; root of BeanFactory hierarchy
        org.springframework.beans.factory.NoSuchBeanDefini tionException: No bean named 'communityManager' is defined: org.springframework.beans.factory.support.DefaultL istableBeanFactory defining beans [multipartResolver,messageSource,tilesConfigurer,ur lMapping,viewResolver,userController,userControlle rMethodResolver,userValidator,userFormController,e ntryController,entryControllerMethodResolver,commu nityController,communityControllerMethodResolver,s ecureHandlerMapping,signonInterceptor,secure_editU ser,secure_action,secureCommunityControllerMethodR esolver,secure_entry,secureEntryControllerMethodRe solver,entryValidator,secure_editEntry,secure_atta chment,attachmentControllerMethodResolver]; root of BeanFactory hierarchy
        at org.springframework.beans.factory.support.DefaultL istableBeanFactory.getBeanDefinition(DefaultListab leBeanFactory.java:332)
        at org.springframework.beans.factory.support.Abstract BeanFactory.getMergedBeanDefinition(AbstractBeanFa ctory.java:672)
        at org.springframework.beans.factory.support.Abstract BeanFactory.getBean(AbstractBeanFactory.java:207)
        at org.springframework.beans.factory.support.Abstract BeanFactory.getBean(AbstractBeanFactory.java:159)
        at org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory.resolveReference(Abstra ctAutowireCapableBeanFactory.java:945)
        at org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory.resolveValueIfNecessary (AbstractAutowireCapableBeanFactory.java:879)
        at org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory.applyPropertyValues(Abs tractAutowireCapableBeanFactory.java:820)
        at org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory.populateBean(AbstractAu towireCapableBeanFactory.java:648)
        at org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory.createBean(AbstractAuto wireCapableBeanFactory.java:288)
        at org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory.createBean(AbstractAuto wireCapableBeanFactory.java:223)
        at org.springframework.beans.factory.support.Abstract BeanFactory.getBean(AbstractBeanFactory.java:236)
        at org.springframework.beans.factory.support.Abstract BeanFactory.getBean(AbstractBeanFactory.java:159)
        at org.springframework.context.support.AbstractApplic ationContext.getBean(AbstractApplicationContext.ja va:496)
        at org.springframework.web.servlet.handler.AbstractUr lHandlerMapping.registerHandler(AbstractUrlHandler Mapping.java:162)
        at org.springframework.web.servlet.handler.SimpleUrlH andlerMapping.initApplicationContext(SimpleUrlHand lerMapping.java:96)
        at org.springframework.context.support.ApplicationObj ectSupport.setApplicationContext(ApplicationObject Support.java:89)
        at org.springframework.context.support.ApplicationCon textAwareProcessor.postProcessBeforeInitialization (ApplicationContextAwareProcessor.java:79)
        at org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory.applyBeanPostProcessors BeforeInitialization(AbstractAutowireCapableBeanFa ctory.java:185)
        at org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory.createBean(AbstractAuto wireCapableBeanFactory.java:304)
        at org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory.createBean(AbstractAuto wireCapableBeanFactory.java:223)
        at org.springframework.beans.factory.support.Abstract BeanFactory.getBean(AbstractBeanFactory.java:236)
        at org.springframework.beans.factory.support.Abstract BeanFactory.getBean(AbstractBeanFactory.java:159)
        at org.springframework.beans.factory.support.DefaultL istableBeanFactory.preInstantiateSingletons(Defaul tListableBeanFactory.java:261)
        at org.springframework.context.support.AbstractApplic ationContext.refresh(AbstractApplicationContext.ja va:317)
        at org.springframework.web.context.support.AbstractRe freshableWebApplicationContext.refresh(AbstractRef reshableWebApplicationContext.java:131)
        at org.springframework.web.servlet.FrameworkServlet.c reateWebApplicationContext(FrameworkServlet.java:2 83)
        at org.springframework.web.servlet.FrameworkServlet.i nitWebApplicationContext(FrameworkServlet.java:230 )
        at org.springframework.web.servlet.FrameworkServlet.i nitServletBean(FrameworkServlet.java:199)
        at org.springframework.web.servlet.HttpServletBean.in it(HttpServletBean.java:103)
        at javax.servlet.GenericServlet.init(GenericServlet.j ava:211)
        at org.apache.catalina.core.StandardWrapper.loadServl et(StandardWrapper.java:1029)
        at org.apache.catalina.core.StandardWrapper.allocate( StandardWrapper.java:687)
        at org.apache.catalina.core.StandardWrapperValve.invo ke(StandardWrapperValve.java:144)
        at org.apache.catalina.core.StandardValveContext.invo keNext(StandardValveContext.java:104)
        at org.apache.catalina.core.StandardPipeline.invoke(S tandardPipeline.java:520)
        at org.apache.catalina.core.StandardContextValve.invo keInternal(StandardContextValve.java:198)
        at org.apache.catalina.core.StandardContextValve.invo ke(StandardContextValve.java:152)
        at org.apache.catalina.core.StandardValveContext.invo keNext(StandardValveContext.java:104)
        at org.apache.catalina.core.StandardPipeline.invoke(S tandardPipeline.java:520)
        at org.apache.catalina.core.StandardHostValve.invoke( StandardHostValve.java:137)
        at org.apache.catalina.core.StandardValveContext.invo keNext(StandardValveContext.java:104)
        at org.apache.catalina.valves.ErrorReportValve.invoke (ErrorReportValve.java:118)
        at org.apache.catalina.core.StandardValveContext.invo keNext(StandardValveContext.java:102)
        at org.apache.catalina.core.StandardPipeline.invoke(S tandardPipeline.java:520)
        at org.apache.catalina.core.StandardEngineValve.invok e(StandardEngineValve.java:109)
        at org.apache.catalina.core.StandardValveContext.invo keNext(StandardValveContext.java:104)
        at org.apache.catalina.core.StandardPipeline.invoke(S tandardPipeline.java:520)
        at org.apache.catalina.core.ContainerBase.invoke(Cont ainerBase.java:929)
        at org.apache.coyote.tomcat5.CoyoteAdapter.service(Co yoteAdapter.java:160)
        at org.apache.coyote.http11.Http11Processor.process(H ttp11Processor.java:799)
        at org.apache.coyote.http11.Http11Protocol$Http11Conn ectionHandler.processConnection(Http11Protocol.jav a:705)
        at org.apache.tomcat.util.net.TcpWorkerThread.runIt(P oolTcpEndpoint.java:577)
        at org.apache.tomcat.util.threads.ThreadPool$ControlR unnable.run(ThreadPool.java:683)
        at java.lang.Thread.run(Thread.java:534)

        Comment


        • #5
          Do you have a context loader servlet defined in your web.xml? I've done what you are trying to accomplish many times without problems. For example:

          Code:
          <context-param>
            <param-name>contextConfigLocation</param-name>
            <param-value>/WEB-INF/ctx-dao.xml, /WEB-INF/ctx-mail.xml, /WEB-INF/ctx-service.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>webapp</servlet-name>
            <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
            <load-on-startup>2</load-on-startup>
          </servlet>
          ...
          1. Notice thathe context servlet is loaded before the web app servlet

          2. I've always been under the impression that the context loader servlet load each context XML file in the order they are specified. In my example, you can see that I want my DAOs instanciated first, then my Mail objects, then my Service objects that depend on both the DAOs and Mail objects. My point being that maybe you should list your Hibernate XML file first. Maybe someone else can comment if that ordering is indeed important.


          Keller

          Comment


          • #6
            The outcome is the same after I change the order of the two xml files in my web.xml. I am not sure about the period sign. The jpetstore sample in the spring distribution has a blank space to separate two parameter values of configuration files.

            I notice a statement in the stout.log:

            org.springframework.beans.factory.xml.XmlBeanDefin itionReader - Loading XML bean definitions from ServletContext resource [/WEB-INF/xxx-servlet.xml]

            But, I don't see anything similar for the other two files. I guess the two configuration files aren't loaded at all. How I can detect they are loaded or not?

            Thanks for all your helps.

            Comment

            Working...
            X