【发布时间】:2014-07-11 11:42:18
【问题描述】:
案例:Have 和消息传递应用程序将部署到 JBOSS 6.1.1 服务器。对于不同的环境有不同的队列名称。有没有办法让队列名称和详细信息从配置文件而不是队列名称中读取
- 注解中的硬编码
- 在 ejb-jar.xml 中定义
- 在 jboss Standalone.xml 中引用
问候, 苏切塔
【问题讨论】:
案例:Have 和消息传递应用程序将部署到 JBOSS 6.1.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 文件
【讨论】: