2014-07-11 30 views
1

案例:Have和消息传递appln将被部署到JBOSS 6.1.1服务器。为不同的环境设置不同的队列名称。有什么办法有队列名称和细节从一个配置文件,而不是Queuenames消息驱动Bean可以从属性文件中读取队列名称

  • 硬编码在注释
  • 定义在ejb-jar.xml
  • 在JBoss中Standalone.xml
  • 参考阅读

问候, Sucheta

回答

0

你可以把properties文件在您的服务器的根目录。在FileInputStream内访问它并将其设置在MDB类中。 做一个单独的类,并从这个类读取性能:

public class EnvironmentProperties { 

    private static final EnvironmentProperties INSTANCE = new EnvironmentProperties(); 

    private Properties props = null; 
    private Log log = LogFactory.getLog(EnvironmentProperties.class); 

    private EnvironmentProperties() { 
     loadProperties(); 
    } 

    public static EnvironmentProperties getInstance() { 
     return INSTANCE; 
    } 

    public String getJmsName() { 
     return props.getProperty("jms.name"); 
    } 

    public String getJmsQueue() { 
     return props.getProperty("jms.queue"); 
    } 

    private Object readResolve() { 
     return INSTANCE; 
    } 

    private Properties loadProperties() { 
     props = new Properties(); 
     try { 
      String filePath = new File("./config.properties").getCanonicalPath(); 
      FileInputStream fis = new FileInputStream(filePath);   
      props.load(fis); 
      fis.close();    
     } catch (FileNotFoundException e) { 
      log.error(e.getMessage(), e); 
     } catch (IOException e) { 
      log.error(e.getMessage(), e); 
     } 
     return props; 
    } 

} 

可以访问JMS /队列名称:EnvironmentProperties.getInstance().getJmsName();

确保所有服务器

上存在的 properties文件
相关问题