4 Replies Latest reply on Apr 3, 2007 3:51 PM by Thomas März

    Contexts.getApplicationContext() loses Components

    Thomas März Newbie

      Hello,

      I am using Seam CVS 20070402 with Tomcat 5.5.23 and the following configuration files.

      The problem is that in Lifecycle.endInitialization() Contexts.getApplicationContext() doesn't return all installed components, resp. when starting up the EntityManagerFactory the dependent Microcontainer-component isn't found and I get the following exception:
      javax.naming.NamingException: Local server is not initialized

      When I remove at least one in META-INF/components.xml the EntityManagerFactory starts up fine.

      After increasing the initial capacity of org.jboss.seam.init.Initialization#properties the startup worked with all components in my components.xml.

      WEB-INF/components.xml

      <?xml version="1.0" encoding="UTF-8"?>
      <components
       xmlns="http://jboss.com/products/seam/components"
       xmlns:core="http://jboss.com/products/seam/core"
       xmlns:security="http://jboss.com/products/seam/security"
       xmlns:drools="http://jboss.com/products/seam/drools"
       xmlns:web="http://jboss.com/products/seam/web"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns:mail="http://jboss.com/products/seam/mail"
       xsi:schemaLocation="
       http://jboss.com/products/seam/core
       http://jboss.com/products/seam/core-1.2.xsd
       http://jboss.com/products/seam/components
       http://jboss.com/products/seam/components-1.2.xsd
       http://jboss.com/products/seam/security
       http://jboss.com/products/seam/security-1.2.xsd
       http://jboss.com/products/seam/web
       http://jboss.com/products/seam/web-1.2.xsd
       http://jboss.com/products/seam/drools
       http://jboss.com/products/seam/drools-1.2.xsd">
      
       <core:init jndi-pattern="#{ejbName}/local" debug="true" />
       <core:ejb installed="true" />
       <core:dispatcher />
      
       <core:entity-manager-factory persistence-unit-name="prozessbenchmarkPersistenceUnit" name="entityManagerFactory" />
       <core:managed-persistence-context name="entityManager" auto-create="true" entity-manager-factory="#{entityManagerFactory}" />
      
       <core:manager
       conversation-timeout="120000"
       concurrent-request-timeout="500"
       conversation-id-parameter="cid"
       conversation-is-long-running-parameter="clr" />
      
       <core:locale-selector cookie-enabled="true"/>
      
       <mail:mail-session host="cf.mediawave.de" />
      
       <web:multipart-filter create-temp-files="true" max-request-size="1000000" url-pattern="*.html" />
       <!-- <web:context-filter url-pattern="/content/*" /> -->
      
       <drools:rule-base name="securityRules">
       <drools:rule-files>
       <value>/META-INF/security-rules.drl</value>
       </drools:rule-files>
       </drools:rule-base>
      
       <security:rule-based-identity authenticate-method="#{authenticator.authenticate}" />
      
       <event type="org.jboss.seam.notLoggedIn">
       <action expression="#{redirect.captureCurrentView}" />
       </event>
      
       <event type="org.jboss.seam.postAuthenticate">
       <action expression="#{redirect.returnToCapturedView}" />
       </event>
      
      </components>
      



      META-INF/components.xml
      <?xml version="1.0" encoding="UTF-8"?>
      <components xmlns="http://jboss.com/products/seam/components" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xsi:schemaLocation="
       http://jboss.com/products/seam/components
       http://jboss.com/products/seam/components-1.2.xsd">
      
       <!-- Action -->
       <component name="authenticator" class="com.example.action.Authenticator" scope="conversation" auto-create="true" />
       <component name="mailAction" class="com.example.action.MailAction" scope="conversation" auto-create="true" />
       <component name="userAction" class="com.example.action.UserAction" scope="conversation" auto-create="true" />
       <component name="userBranchAction" class="com.example.action.UserBranchAction" scope="conversation" auto-create="true" />
       <component name="userQuestionnaireAction" class="com.example.questionnaire.action.UserQuestionnaireAction" scope="conversation" auto-create="true" />
       <component name="exportAction" class="com.example.action.ExportAction" scope="conversation" auto-create="true" />
      
       <!-- Util -->
       <component name="configuration" class="com.example.util.Configuration" scope="application" auto-create="true">
       <property name="path">${configuration.path}</property>
       <property name="url">${configuration.url}</property>
       </component>
      
       <!-- Entity -->
       <component name="user" class="com.example.entity.User" scope="conversation" auto-create="true" />
      
       <!-- DAO -->
       <component name="userDao" class="com.example.dao.UserDao" scope="stateless" auto-create="true" />
       <component name="userBranchDao" class="com.example.dao.UserBranchDao" scope="stateless" auto-create="true" />
       <component name="roleDao" class="com.example.dao.RoleDao" scope="stateless" auto-create="true" />
       <component name="questionnaireDao" class="com.example.questionnaire.dao.QuestionnaireDao" scope="stateless" auto-create="true" />
       <component name="questionDao" class="com.example.questionnaire.dao.QuestionDao" scope="stateless" auto-create="true" />
       <component name="answerDao" class="com.example.questionnaire.dao.AnswerDao" scope="stateless" auto-create="true" />
       <component name="userQuestionnaireDao" class="com.example.questionnaire.dao.UserQuestionnaireDao" scope="stateless" auto-create="true" />
       <component name="userQuestionDao" class="com.example.questionnaire.dao.UserQuestionDao" scope="stateless" auto-create="true" />
       <component name="userAnswerDao" class="com.example.questionnaire.dao.UserAnswerDao" scope="stateless" auto-create="true" />
      
       <!-- Framework -->
       <component name="questionnaireHome" class="com.example.questionnaire.home.QuestionnaireHome" scope="conversation">
       <property name="entityClass">com.example.questionnaire.entity.Questionnaire</property>
       </component>
       <component name="questionHome" class="com.example.questionnaire.home.QuestionHome" scope="conversation">
       <property name="entityClass">com.example.questionnaire.entity.Question</property>
       </component>
       <component name="answerHome" class="com.example.questionnaire.home.AnswerHome" scope="conversation">
       <property name="entityClass">com.example.questionnaire.entity.Answer</property>
       </component>
      
      </components>
      


      After reading http://wiki.jboss.org/wiki/Wiki.jsp?page=HelpBugReport I wasn't certain enough if this is worth a Bug report.


      Regards,
      Thomas

        • 1. Re: Contexts.getApplicationContext() loses Components
          Thomas März Newbie

          I lied with

          After increasing the initial capacity of org.jboss.seam.init.Initialization#properties the startup worked with all components in my components.xml.

          since this didnt'solve the issue, rather i posted and tested with the wrong META-INF/components.xml

          I'll try to figure out some solution.

          Here's the non-working file (Last two components added)
          <?xml version="1.0" encoding="UTF-8"?>
          <components xmlns="http://jboss.com/products/seam/components" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
           xsi:schemaLocation="
           http://jboss.com/products/seam/components
           http://jboss.com/products/seam/components-1.2.xsd">
          
           <!-- Action -->
           <component name="authenticator" class="com.example.action.Authenticator" scope="conversation" auto-create="true" />
           <component name="mailAction" class="com.example.action.MailAction" scope="conversation" auto-create="true" />
           <component name="userAction" class="com.example.action.UserAction" scope="conversation" auto-create="true" />
           <component name="userBranchAction" class="com.example.action.UserBranchAction" scope="conversation" auto-create="true" />
           <component name="userQuestionnaireAction" class="com.example.questionnaire.action.UserQuestionnaireAction" scope="conversation" auto-create="true" />
           <component name="exportAction" class="com.example.action.ExportAction" scope="conversation" auto-create="true" />
          
           <!-- Util -->
           <component name="configuration" class="com.example.util.Configuration" scope="application" auto-create="true">
           <property name="path">${configuration.path}</property>
           <property name="url">${configuration.url}</property>
           </component>
          
           <!-- Entity -->
           <component name="user" class="com.example.entity.User" scope="conversation" auto-create="true" />
          
           <!-- DAO -->
           <component name="userDao" class="com.example.dao.UserDao" scope="stateless" auto-create="true" />
           <component name="userBranchDao" class="com.example.dao.UserBranchDao" scope="stateless" auto-create="true" />
           <component name="roleDao" class="com.example.dao.RoleDao" scope="stateless" auto-create="true" />
           <component name="questionnaireDao" class="com.example.questionnaire.dao.QuestionnaireDao" scope="stateless" auto-create="true" />
           <component name="questionDao" class="com.example.questionnaire.dao.QuestionDao" scope="stateless" auto-create="true" />
           <component name="answerDao" class="com.example.questionnaire.dao.AnswerDao" scope="stateless" auto-create="true" />
           <component name="userQuestionnaireDao" class="com.example.questionnaire.dao.UserQuestionnaireDao" scope="stateless" auto-create="true" />
           <component name="userQuestionDao" class="com.example.questionnaire.dao.UserQuestionDao" scope="stateless" auto-create="true" />
           <component name="userAnswerDao" class="com.example.questionnaire.dao.UserAnswerDao" scope="stateless" auto-create="true" />
          
           <!-- Framework -->
           <component name="questionnaireHome" class="com.example.questionnaire.home.QuestionnaireHome" scope="conversation">
           <property name="entityClass">com.example.questionnaire.entity.Questionnaire</property>
           </component>
           <component name="questionHome" class="com.example.questionnaire.home.QuestionHome" scope="conversation">
           <property name="entityClass">com.example.questionnaire.entity.Question</property>
           </component>
           <component name="answerHome" class="com.example.questionnaire.home.AnswerHome" scope="conversation">
           <property name="entityClass">com.example.questionnaire.entity.Answer</property>
           </component>
           <component name="recommendationHome" class="com.example.home.RecommendationHome" scope="conversation">
           <property name="entityClass">com.example.entity.Recommendation</property>
           </component>
           <component name="contactHome" class="com.example.home.ContactHome" scope="conversation">
           <property name="entityClass">com.example.entity.Contact</property>
           </component>
          
          </components>
          


          • 2. Re: Contexts.getApplicationContext() loses Components
            Thomas März Newbie

            It seems I lied again with

            Contexts.getApplicationContext() loses Components

            since it seems to me to be a problem with
            the order the components are started.
            If I remove two entries from META-INF/components.xml
            org.jboss.seam.core.ejb.component ist started as 3rd component.

            If I add them again the startup order is different.

            How can I fix this problem or force a certain startup order?

            • 3. Re: Contexts.getApplicationContext() loses Components
              Pete Muir Master

              I'm not sure I'm following your problem - you're saying *your* components are starting up in the wrong order, so that a component your component depends on isn't available during startup? Use @Startup(depends=) to make sure the components are started before yours.

              http://docs.jboss.com/seam/1.2.0.PATCH1/reference/en/html/annotations.html

              • 4. Re: Contexts.getApplicationContext() loses Components
                Thomas März Newbie

                 

                I'm not sure I'm following your problem - you're saying *your* components are starting up in the wrong order, so that a component your component depends on isn't available during startup? Use @Startup(depends=) to make sure the components are started before yours.


                My components don't depend on each other so the order shouldn't matter. I'd also guess I don't need to set any dependencies to startup components since I only inject the usual suspects (entityManager, facesMessages, log) into my components. The number of my my components just changed the startup order of all components which causes problems.

                Depending on the entries in my META-INF/components.xml file the startup order of the components in Lifecycle#endInitialization() differs.

                If the org.jboss.seam.core.ejb.component is started before the entityManagerFactory all works fine.

                If the org.jboss.seam.core.ejb.component is started after the entityManagerFactory the complete startup fails with:
                javax.naming.NamingException: Local server is not initialized


                I fixed the problem by starting org.jboss.seam.core.ejb.component as the first component in Lifecycle#endInitialization().

                Is my configuration broken or is there any other way to fix this problem?