3 Replies Latest reply on Nov 10, 2009 9:04 PM by raja garlapati

    Component.getInstance() always giving the error

    raja garlapati Newbie

      After searching this forum, could not find the exact solution..

      I have a class (say BootStrap ) which has a main method.From this class i am trying to call the DAO class method to do DB activities.

      When i do a Component.getInstance(...,...), its give error .
      I changed to Lifecycle.beginCall()/..endCall() it give me Application context not active.

      Has anyone got any solution for this.

        • 1. Re: Component.getInstance() always giving the error
          Francisco Jose Peredo Noguez Master

          Please post the errors with their full stacktrace

          • 2. Re: Component.getInstance() always giving the error
            raja garlapati Newbie
            Here is my class:

            package org.domain.bannerstore.session;

            import java.io.BufferedReader;
            import java.io.InputStreamReader;
            import java.security.Provider;
            import java.security.Security;

            import org.domain.bannerstore.entity.SSOSecretHome;
            import org.jboss.seam.Component;
            import org.jboss.seam.ScopeType;
            import org.jboss.seam.annotations.AutoCreate;
            import org.jboss.seam.annotations.In;
            import org.jboss.seam.annotations.Name;
            import org.jboss.seam.annotations.Scope;
            import org.jboss.seam.contexts.Lifecycle;

            public class SecretBootStrap {
                private static final String hexstr = "0123456789ABCDEF";
                @In(create = true)
                private SSOSecretHome ssoSecretHome;
                private static void die (String message) {
                                    System.err.println("Error: "+message);
                private void updateSecretkey(String key){
                    try {
                            ssoSecretHome = (SSOSecretHome)Component.getInstance("ssoSecretHome" ,true);
                                    int rows = ssoSecretHome.updateNewSecret(key);
                                    if(rows == 0){
                                            die("Key update not successful");
                                    System.out.println("key update successful");
                            } catch (Exception e) {
                                    System.err.println("key update not successful");
                public static void main(String[] arg) throws Exception {
                            Provider sunJce = new com.sun.crypto.provider.SunJCE();
                            System.out.print("Please enter new secret key: ");
                            BufferedReader in =
                                        new BufferedReader(new InputStreamReader(System.in));
                            String key = in.readLine();
                            if (key == null) {
                                die("No new key given.");
                            if (key.length() != 48) {
                                die("New key not 48 characters long!");
                            for (int i=0; i<48; i++) {
                                if (hexstr.indexOf(Character.toUpperCase(key.charAt(i))) == -1) {
                                        die("Invalid character "+key.charAt(i)+" in key");
                            SecretBootStrap sbs = (SecretBootStrap)Component.getInstance("secretBootStrap" ,true);
                            //update the new secret key


            /**************************Error i ma getting is *******************/
            Exception in thread "main" java.lang.IllegalStateException: Attempted to invoke a Seam component outside an initialized application
                    at org.jboss.seam.contexts.Lifecycle.getApplication(Lifecycle.java:36)
                    at org.jboss.seam.contexts.Lifecycle.beginCall(Lifecycle.java:84)
                    at org.domain.bannerstore.session.SecretBootStrap.main(SecretBootStrap.java:71)

            • 3. Re: Component.getInstance() always giving the error
              raja garlapati Newbie

              That error is happening in the main method when i try to run this class.

              Thank u