1 Reply Latest reply on May 8, 2008 8:24 AM by Nicklas Karlsson

    Application Settings read at startup

    scott duke Novice

      Currently, I have a class which is read during startup. It reads the information fine.



      @Startup
      @Scope(ScopeType.APPLICATION)
      @Stateful
      @Name("propertyInfo")
      public class PropertyInfo implements PropertyInfoLocal, Serializable  {
      
           @Logger
           Log log;
           @PersistenceContext(type = EXTENDED)
           EntityManager em;
           @Out
           private String tmpDir;
      
           @Create
           public void initialize() {
                String fileSep = System
                          .getProperty(SystemConstants.PROPERTY_FILE_SEPARATOR);
                String homeDir = System
                          .getProperty(SystemConstants.PROPERTY_JBOSS_HOME_DIR);
                String dukeProperty = homeDir + fileSep + "deploy" + fileSep
                          + "artwork.ear" + fileSep + "artwork.war" + fileSep + "WEB-INF"
                          + fileSep + "configuration.properties";
                log.info("configuration Properties [#0]", dukeProperty);
      
                Properties props = new Properties();
                try {
                     FileInputStream fis = new FileInputStream(dukeProperty);
                     props.load(fis);
                     String tmpDir = props.getProperty("tmp.dir");
                     System.out.println(" ");
                     System.out.println("tmpDir --->> " + tmpDir);
                     System.out.println(" ");
                } catch (FileNotFoundException ex) {
                     log.error("The 'configuration.properties' file is missing.");
                } catch (IOException ex) {
                     log.error("Unable to read the 'configuration.properties' file.");
                }
           }
      
      ...
      }
      



      The problem is when I try to read this information from within another class. I have tried both:


      PropertyInfo targetDir = (PropertyInfo) Contexts.getApplicationContext().get("propertyInfo");
      



      and


      PropertyInfo pi = (PropertyInfo) Component.getInstance(PropertyInfo.class);
      



      These give me a classCastException.


      Could someone tell me what I am doing wrong? Is there a better way of handling application settings?