11 Replies Latest reply on Aug 30, 2006 6:15 PM by Maurice Zeijen

    Could not instantiate Seam component

    Marco Pancotti Newbie

      I'm trying to write an application an, just to avoid problems, I'm writing it as a new package of the booking example, using the same ant and deployment file (booking is running and testNG is working for the booking code).

      I wrote an entity bean and an action that should be the same as part of the HotelBookingAction, but when I try to run the testNG it says "could not instantiate Seam Component"

      Where am i wrong?

      This is the test

      package org.tyl.corecomponents.test.business;
      import org.jboss.seam.Component;
      import org.jboss.seam.contexts.Contexts;
      import org.jboss.seam.example.booking.User;
      import org.jboss.seam.mock.SeamTest;
      import org.jboss.seam.mock.SeamTest.Script;
      import org.testng.annotations.Test;
      import org.tyl.corecomponents.business.SystemOfUnitsManager;
      public class SystemOfUnitsTest extends SeamTest {
       public void testSystemOfUnitsManager() throws Exception
       String id = new Script() {
       SystemOfUnitsManager systemOfUnitsManager;
       protected void updateModelValues() throws Exception
       systemOfUnitsManager = (SystemOfUnitsManager) Component.getInstance("systemOfUnitsManager", true);
       protected void invokeApplication()
       String outcome = systemOfUnitsManager.find();
       assert "main".equals( outcome );

      Here is the action class
      package org.tyl.corecomponents.business.impl;
      import static javax.persistence.PersistenceContextType.EXTENDED;
      import java.io.Serializable;
      import java.util.List;
      import javax.ejb.Interceptor;
      import javax.ejb.Stateful;
      import javax.persistence.EntityManager;
      import javax.persistence.PersistenceContext;
      import org.jboss.logging.Logger;
      import org.jboss.seam.annotations.Begin;
      import org.jboss.seam.annotations.Conversational;
      import org.jboss.seam.annotations.Name;
      import org.jboss.seam.annotations.datamodel.DataModel;
      import org.jboss.seam.annotations.datamodel.DataModelSelectionIndex;
      import org.jboss.seam.ejb.SeamInterceptor;
      import org.tyl.corecomponents.business.SystemOfUnitsManager;
      import org.tyl.corecomponents.model.SystemOfUnits;
      public class SystemOfUnitsManagerImpl implements SystemOfUnitsManager, Serializable {
       private static final Logger log = Logger.getLogger(SystemOfUnitsManager.class);
       private String searchString=null;
       private List<SystemOfUnits> systemOfUnitsList;
       private int systemOfUnitsIndex;
       private EntityManager em;
       public String find() {
       systemOfUnitsList = null;
       String searchPattern = searchString==null ? "%" : '%' + searchString.toLowerCase().replace('*', '%') + '%';
       systemOfUnitsList = em.createQuery("from SystemOfUnits where lower(systemOfUnitsID) like :search or lower(nameOfStandardizationBody) like :search")
       .setParameter("search", searchPattern)
       log.info(systemOfUnitsList.size() + " system of units found");
       return "main";

      Here is the interface
      package org.tyl.corecomponents.business;
      import javax.ejb.Remote;
      public interface SystemOfUnitsManager {
       public String find();

      and here is the entity
      package org.tyl.corecomponents.model;
      import java.io.Serializable;
      import java.util.Date;
      import java.util.HashSet;
      import javax.persistence.Column;
      import javax.persistence.Entity;
      import javax.persistence.GeneratorType;
      import javax.persistence.Id;
      import javax.persistence.Version;
      public class SystemOfUnits
       implements Serializable
       private java.lang.String systemOfUnitsID;
       private Integer version;
       private java.lang.String nameOfStandardizationBody;
       public SystemOfUnits()
       public SystemOfUnits(java.lang.String nameofsystem)
       public java.lang.String getSystemOfUnitsID() {
       return systemOfUnitsID;
       public void setSystemOfUnitsID(java.lang.String systemOfUnitsID) {
       this.systemOfUnitsID = systemOfUnitsID;
       public Integer getVersion() {
       return version;
       public void setVersion(Integer version) {
       this.version = version;

      Any help?
      Thank you
      Marco Pancotti

        • 1. Re: Could not instantiate Seam component
          Gavin King Master

          We need the whole stack trace.

          • 2. Re: Could not instantiate Seam component
            Marco Pancotti Newbie

            Here it is

            [TestClass] Creating TestClass for [ClassImpl org.tyl.corecomponents.test.business.SystemOfUnitsTest]
            [TestClass] Adding method org.tyl.corecomponents.test.business.SystemOfUnitsTest.testSystemOfUnitsManager() on TestClass class org.tyl.corecomponents.test.business.SystemOfUnitsTest
            [TestRunner] Running test Nopackage on 1 classes, included groups:[] excluded groups:[]
            TESTCLASS: org.tyl.corecomponents.test.business.SystemOfUnitsTest
            [TestClass] BeforeClass : org.jboss.seam.mock.SeamTest.init()
            [TestClass] BeforeMethod: org.jboss.seam.mock.SeamTest.begin()
            [TestClass] Test : org.tyl.corecomponents.test.business.SystemOfUnitsTest.testSystemOfUnitsManager()
            [TestClass] AfterMethod : org.jboss.seam.mock.SeamTest.end()
            [TestClass] AfterClass : org.jboss.seam.mock.SeamTest.cleanup()
            [Invoker 19116636] Invoking org.jboss.seam.mock.SeamTest.init()
            [TestRunner] Marking class [TestClass class org.tyl.corecomponents.test.business.SystemOfUnitsTest] as beforeConfigurationClass=true
            [TestRunner] PARALLEL LIST:
            [TestRunner] org.tyl.corecomponents.test.business.SystemOfUnitsTest.testSystemOfUnitsManager()
            [TestRunner] SEQUENTIAL LIST:
            [TestRunner] Found 1 applicable methods
            [Invoker 19116636] Invoking org.jboss.seam.mock.SeamTest.begin()
            [Invoker 19116636] Invoking org.tyl.corecomponents.test.business.SystemOfUnitsTest.testSystemOfUnitsManager
            [Invoker 19116636] Invoking org.jboss.seam.mock.SeamTest.end()
            [Invoker 19116636] Invoking org.jboss.seam.mock.SeamTest.cleanup()
            [TestRunner] Marking class [TestClass class org.tyl.corecomponents.test.business.SystemOfUnitsTest] as afterConfigurationClass=true
            *********** INVOKED METHODS
             org.jboss.seam.mock.SeamTest.init() 25421790
             org.tyl.corecomponents.test.business.SystemOfUnitsTest.testSystemOfUnitsManager() 25421790
             org.jboss.seam.mock.SeamTest.cleanup() 25421790
            FAILED: org.tyl.corecomponents.test.business.SystemOfUnitsTest.testSystemOfUnitsManager()
            org.jboss.seam.InstantiationException: Could not instantiate Seam component
             at org.jboss.seam.Component.newInstance(Unknown Source)
             at org.jboss.seam.Component.newInstance(Unknown Source)
             at org.jboss.seam.Component.getInstance(Unknown Source)
             at org.tyl.corecomponents.test.business.SystemOfUnitsTest$1.updateModelValues(SystemOfUnitsTest.java:24)
             at org.jboss.seam.mock.SeamTest$Script.run(Unknown Source)
             at org.tyl.corecomponents.test.business.SystemOfUnitsTest.testSystemOfUnitsManager(SystemOfUnitsTest.java:35)
             at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
             at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
             at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
             at java.lang.reflect.Method.invoke(Unknown Source)
             at org.testng.internal.MethodHelper.invokeMethod(MethodHelper.java:306)
             at org.testng.internal.Invoker.invokeMethod(Invoker.java:343)
             at org.testng.internal.Invoker.invokeTestMethods(Invoker.java:490)
             at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:61)
             at org.testng.TestRunner.privateRun(TestRunner.java:585)
             at org.testng.TestRunner.run(TestRunner.java:480)
             at org.testng.SuiteRunner.privateRun(SuiteRunner.java:191)
             at org.testng.SuiteRunner.run(SuiteRunner.java:117)
             at org.testng.eclipse.runner.RemoteTestNG.run(RemoteTestNG.java:99)
             at org.testng.eclipse.runner.RemoteTestNG.main(RemoteTestNG.java:138)
            Caused by: javax.naming.NamingException: Local server is not initialized
             at org.jnp.interfaces.LocalOnlyContextFactory.getInitialContext(LocalOnlyContextFactory.java:30)
             at javax.naming.spi.NamingManager.getInitialContext(Unknown Source)
             at javax.naming.InitialContext.getDefaultInitCtx(Unknown Source)
             at javax.naming.InitialContext.init(Unknown Source)
             at javax.naming.InitialContext.<init>(Unknown Source)
             at org.jboss.seam.Component.instantiate(Unknown Source)
             ... 20 more
             Tests run: 1, Failures: 1, Skips: 0
            Creating C:\jboss-seam-1.0beta1\examples\booking\testng-failures.xml
            Total tests run: 1, Failures: 1, Skips: 0

            It's clear that the method
             protected void updateModelValues() throws Exception
             systemOfUnitsManager = (SystemOfUnitsManager) Component.getInstance("systemOfUnitsManager", true);

            cannot be executed.
            FYI the component SystemOfUnitsManager was registered by Jboss without exceptions during the deployment.

            Marco Pancotti

            • 3. Re: Could not instantiate Seam component
              Gavin King Master

              So the problem seems to be that JNDI is not available. So I guess that the Embeddable EJB container is not properly started, or else your jndi.properties is missing or does not contain the correct values.

              • 4. Re: Could not instantiate Seam component
                Marco Pancotti Newbie

                OK, but unfortunatly it does not mean anything to me. The problem is that I never worked with EJB and Jboss, I started now just to study Seam, that seems to be a very nice environment. Of course I know that I have to do it, but first I wanted to understand the "Seam advantage".

                To avoid configuration problem (that, at the moment, I'm not able to manage) I added a package to the booking application using exactly the same configuration (jndi.properties etc.). The booking application runs, and the tests on booking application run as well, so I expectd to be able to run my test too. Why is it not true?

                So I think that there are the following possibilities:
                a) to work with Seam you must be aware about configurations aspects that are not yet documented
                b) It's impossible to start in a confortably way without knowing how to work in a Jboss/EJB environment
                c) it's better that i give up and go back to my Spring/Hibernate environment until I have studied EJB/Jboss (or have retired from the business)

                What is your opinion?

                • 5. Re: Could not instantiate Seam component
                  Gavin King Master

                  You should be able to get everything working just by closely following the example application. Of course, to use Seam with EJB3, you will need to learn EJB3.

                  If you don't want to learn EJB3, you could try looking at the noejb example, which uses Seam with Hibernate and plain JavaBeans.

                  • 6. Re: Could not instantiate Seam component
                    Marjon Hilberink Newbie


                    I have a similar problem. I used one of the examples to build my own test / training app, and I'm using an oracle database.
                    when I run the tests, I get this:
                    [testng] INFO 13-04 14:20:08,015 (MCKernelAbstraction.java:install:79) -installing bean: persistence.units:jar=test.jar,unitName=dictionaryTestDatabase with dependencies:
                    [testng] INFO 13-04 14:20:08,015 (MCKernelAbstraction.java:install:82) - AbstractDependencyMetaData@1bfbfb8{dependency=testOracleDS}
                    [testng] INFO 13-04 14:20:08,093 (MCKernelAbstraction.java:install:79) -installing bean: jboss.j2ee:service=EJB3,jar=test,name=BookingListAction with dependencies:
                    [testng] INFO 13-04 14:20:08,093 (MCKernelAbstraction.java:install:82) - AbstractDependencyMetaData@e93999{dependency=persistence.units:jar=test.jar,unitName=dictionaryTestDatabase}
                    [testng] INFO 13-04 14:20:08,125 (MCKernelAbstraction.java:install:79) -installing bean: jboss.j2ee:service=EJB3,jar=test,name=ChangePasswordAction with dependencies:
                    [testng] INFO 13-04 14:20:08,125 (MCKernelAbstraction.java:install:82) - AbstractDependencyMetaData@132021a{dependency=persistence.units:jar=test.jar,unitName=dictionaryTestDatabase}
                    [testng] INFO 13-04 14:20:08,125 (MCKernelAbstraction.java:install:79) -installing bean: jboss.j2ee:service=EJB3,jar=test,name=HotelBookingAction with dependencies:
                    [testng] INFO 13-04 14:20:08,125 (MCKernelAbstraction.java:install:82) - AbstractDependencyMetaData@2803d5{dependency=persistence.units:jar=test.jar,unitName=dictionaryTestDatabase}
                    [testng] INFO 13-04 14:20:08,125 (MCKernelAbstraction.java:install:79) -installing bean: jboss.j2ee:service=EJB3,jar=test,name=ImperfectiveAction with dependencies:
                    [testng] INFO 13-04 14:20:08,125 (MCKernelAbstraction.java:install:82) - AbstractDependencyMetaData@6833f2{dependency=persistence.units:jar=test.jar,unitName=dictionaryTestDatabase}
                    [testng] INFO 13-04 14:20:08,125 (MCKernelAbstraction.java:install:79) -installing bean: jboss.j2ee:service=EJB3,jar=test,name=LoginAction with dependencies:
                    [testng] INFO 13-04 14:20:08,125 (MCKernelAbstraction.java:install:82) - AbstractDependencyMetaData@15e538e{dependency=persistence.units:jar=test.jar,unitName=dictionaryTestDatabase}
                    [testng] INFO 13-04 14:20:08,140 (MCKernelAbstraction.java:install:79) -installing bean: jboss.j2ee:service=EJB3,jar=test,name=LogoutAction with dependencies:
                    [testng] INFO 13-04 14:20:08,468 (MCKernelAbstraction.java:install:79) -installing bean: jboss.j2ee:service=EJB3,jar=test,name=RegisterAction with dependencies:
                    [testng] INFO 13-04 14:20:08,468 (MCKernelAbstraction.java:install:82) -
                    Here is should start exporting the schema and binding my beans, but somehow it doesn't
                    [testng] INFO 13-04 14:20:08,468 (Initialization.java:init:95) -done initializing Seam
                    [testng] INFO 13-04 14:20:08,531 (Ejb.java:shutdown:68) -stopping the embedded EJB container
                    [testng] Creating D:\jboss-seam-1.0beta2\jboss-seam-1.0beta2\examples\dictionary\test-output\Imperfective.html
                    [testng] FAILED: org.jboss.seam.example.booking.test.ImperfectiveTest.testImperfective()
                    [testng] org.jboss.seam.InstantiationException: Could not instantiate Seam component
                    [testng] at org.jboss.seam.Component.newInstance(Component.java:611)
                    [testng] at org.jboss.seam.Component.newInstance(Component.java:1093)
                    [testng] at org.jboss.seam.Component.getInstance(Component.java:1044)
                    [testng] at org.jboss.seam.Component.getInstance(Component.java:1027)
                    [testng] at org.jboss.seam.example.booking.test.ImperfectiveTest$1.updateModelValues(ImperfectiveTest.java:48)
                    [testng] at org.jboss.seam.mock.SeamTest$Script.run(SeamTest.java:182)
                    [testng] at org.jboss.seam.example.booking.test.ImperfectiveTest.testImperfective(ImperfectiveTest.java:34)
                    [testng] at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
                    [testng] at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
                    [testng] at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
                    [testng] at java.lang.reflect.Method.invoke(Method.java:585)
                    [testng] at org.testng.internal.MethodHelper.invokeMethod(MethodHelper.java:463)
                    [testng] at org.testng.internal.Invoker.invokeMethod(Invoker.java:378)
                    [testng] at org.testng.internal.Invoker.invokeTestMethods(Invoker.java:580)
                    [testng] at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:89)
                    [testng] at org.testng.TestRunner.privateRun(TestRunner.java:612)
                    [testng] at org.testng.TestRunner.run(TestRunner.java:503)
                    [testng] at org.testng.SuiteRunner.privateRun(SuiteRunner.java:219)
                    [testng] at org.testng.SuiteRunner.run(SuiteRunner.java:145)
                    [testng] at org.testng.TestNG.createAndRunSuiteRunners(TestNG.java:570)
                    [testng] at org.testng.TestNG.runSuitesLocally(TestNG.java:533)
                    [testng] at org.testng.TestNG.run(TestNG.java:310)
                    [testng] at org.testng.TestNG.privateMain(TestNG.java:660)
                    [testng] at org.testng.TestNG.main(TestNG.java:602)
                    [testng] Caused by: javax.naming.NameNotFoundException: ImperfectiveAction not bound
                    [testng] at org.jnp.server.NamingServer.getBinding(NamingServer.java:529)
                    [testng] at org.jnp.server.NamingServer.getBinding(NamingServer.java:537)
                    [testng] at org.jnp.server.NamingServer.getObject(NamingServer.java:543)
                    [testng] at org.jnp.server.NamingServer.lookup(NamingServer.java:267)
                    [testng] at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:625)
                    [testng] at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:587)
                    [testng] at javax.naming.InitialContext.lookup(InitialContext.java:351)
                    [testng] at org.jboss.seam.Component.instantiate(Component.java:651)
                    [testng] at org.jboss.seam.Component.newInstance(Component.java:607)
                    [testng] ... 23 more

                    When I switch back to the original database, it all works. What am I forgetting? The application itself runs fine, on both databases.

                    I would really appreciate some help!


                    • 7. Re: Could not instantiate Seam component
                      Gavin King Master


                      When I switch back to the original database, it all works.

                      What do you mean by this? You mean you have it working against HSQLDB?

                      • 8. Re: Could not instantiate Seam component
                        Marjon Hilberink Newbie


                        Thanks for your reply. Yes, it does work when I use the HSQLDB. I fixed it though, it seems that you need to edit jboss-bean.xml to point to the correct DB as well when running the tests. I did that, and now it runs just fine.


                        • 9. Re: Could not instantiate Seam component
                          [Si]dragon Newbie


                          "gavin.king@jboss.com" wrote:
                          So the problem seems to be that JNDI is not available. So I guess that the Embeddable EJB container is not properly started, or else your jndi.properties is missing or does not contain the correct values.

                          I am in the same boat as the other poster: this does not mean much to me either and I am familiar with EJB3. Could you clarify all the requirements for running unit tests? What libraries are needed, what files should be on the classpath and where, and so on. As far as I can tell, my configuration is nearly identical to that found in the example applications, I include all the same libraries, my build artifacts contain the same resource files, and so forth. I have been trying to pinpoint the cause but my efforts are fruitless. (See http://jboss.com/index.html?module=bb&op=viewtopic&t=89261 for some of my stack traces.)

                          You say our JNDI properties (may) contain the wrong values. What should it contain? How is it referenced? How does the scaffold know about the datasource? What should the classpath contain? What does the scaffold actually use to run the tests? Should we be looking at the microcontainer configuration? The embedded-ejb configuration? (Note these have the same JNDI properties.)

                          I am enjoying Seam a great deal. You guys have done a great job with this stuff, and I am pushing it like crazy where I work, but I really need some more details on debugging things like this. I will not and cannot proceed on projects without unit testing, making this the only blocker on projects coming down the pipeline.

                          • 10. Test environment notes on my personal wiki.
                            [Si]dragon Newbie

                            I am throwing together notes from my observations related to test environment issues on my personal wiki. For the time being, they will be located at http://sidragon.net/wiki/JBoss_Seam_test_environment but in the future, either I or someone else should add these to the JBoss wiki.

                            • 11. Re: Could not instantiate Seam component
                              Maurice Zeijen Master

                              Also maybe my post on a different topic (with a simeral problem) can help: