简体   繁体   中英

Static Variable gives null or default value when read in an EJB- jboss EAP 6.1.0

We have migrated our application from weblogic 10.0 to jboss EAP 6.1.0.

While accessing the properties which is loaded in the init() method of the servlet from our EJB, the value returned is null.

Below method is in Ejbbean class:

public void execute() throws EJBException
    {
System.out.println("Constants.x in execute  ----"+Constants.x);
}

the value printed here is null. Although if we use the same code inside our application anywhere other than EJB, the correct value is returned.

We are loading the properies inside the init method of servlet.

public void init() throws javax.servlet.ServletException 
    {
ServletContext sContext = this.getServletContext();
        try 
        {
    String propFile = sContext.getInitParameter("abc");
            Properties prop = new Properties();
            FileInputStream inStream = new FileInputStream(propFile);
            prop.load(inStream);
Constants.loadValues(prop);
 System.out.println("Constants.x in execute  ----"+Constants.x);
}

the correct value for static variable x is printed here.

        public final class Constants
        {

            public static String x = null;

    public final static void loadValues(Properties prop) throws Exception
        {
    // the properties are loaded here...
    }
}

Whats the reason behind this unexpected behaviour of static variable inside EJB when the same code is working fine elsewhere? This problem was not there in the application when it was deployed on weblogic server.

How can this be fixed?

I got the solution to this problem. jboss-deployment-structure.xml needs to be written for the application with the dependency of the EJB on the WAR.

Reference link: http://www.mastertheboss.com/jboss-server/jboss-deploy/configuring-jboss-as-7-deployment-order

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM