【问题标题】:Can Message Driven Bean read the queue names from a properties fileMessage Driven Bean 可以从属性文件中读取队列名称吗
【发布时间】:2014-07-11 11:42:18
【问题描述】:

案例:Have 和消息传递应用程序将部署到 JBOSS 6.1.1 服务器。对于不同的环境有不同的队列名称。有没有办法让队列名称和详细信息从配置文件而不是队列名称中读取

  • 注解中的硬编码
  • 在 ejb-jar.xml 中定义
  • 在 jboss Standalone.xml 中引用

问候, 苏切塔

【问题讨论】:

    标签: java ejb-3.0


    【解决方案1】:

    您可以将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 文件

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-01-16
      • 1970-01-01
      • 2021-11-22
      • 1970-01-01
      • 2012-01-30
      相关资源
      最近更新 更多