mirror of
https://github.com/apache/activemq.git
synced 2025-02-27 12:55:32 +00:00
https://issues.apache.org/jira/browse/AMQ-4034 - support configuration properties
git-svn-id: https://svn.apache.org/repos/asf/activemq/trunk@1436956 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
06e67e02bb
commit
a6bceeb6da
@ -26,7 +26,7 @@
|
|||||||
|
|
||||||
|
|
||||||
<broker xmlns="http://activemq.apache.org/schema/core"
|
<broker xmlns="http://activemq.apache.org/schema/core"
|
||||||
brokerName="localhost"
|
brokerName="${broker-name}"
|
||||||
dataDirectory="data"
|
dataDirectory="data"
|
||||||
start="false">
|
start="false">
|
||||||
|
|
||||||
|
@ -1,3 +1,3 @@
|
|||||||
broker-name=localhost
|
broker-name=amq-broker
|
||||||
data=${karaf.data}/localhost
|
data=${karaf.data}/${broker-name}
|
||||||
config=${karaf.base}/etc/activemq.xml
|
config=${karaf.base}/etc/activemq.xml
|
@ -25,10 +25,12 @@ import org.osgi.service.cm.ManagedServiceFactory;
|
|||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
import org.springframework.beans.factory.xml.XmlBeanDefinitionReader;
|
import org.springframework.beans.factory.xml.XmlBeanDefinitionReader;
|
||||||
|
import org.springframework.context.ConfigurableApplicationContext;
|
||||||
|
import org.springframework.context.support.ClassPathXmlApplicationContext;
|
||||||
|
import org.springframework.context.support.PropertySourcesPlaceholderConfigurer;
|
||||||
import org.springframework.core.io.Resource;
|
import org.springframework.core.io.Resource;
|
||||||
|
|
||||||
import java.util.Dictionary;
|
import java.util.*;
|
||||||
import java.util.HashMap;
|
|
||||||
|
|
||||||
public class ActiveMQServiceFactory implements ManagedServiceFactory {
|
public class ActiveMQServiceFactory implements ManagedServiceFactory {
|
||||||
|
|
||||||
@ -54,17 +56,37 @@ public class ActiveMQServiceFactory implements ManagedServiceFactory {
|
|||||||
}
|
}
|
||||||
|
|
||||||
LOG.info("Starting broker " + name);
|
LOG.info("Starting broker " + name);
|
||||||
//TODO properties
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
Thread.currentThread().setContextClassLoader(BrokerService.class.getClassLoader());
|
Thread.currentThread().setContextClassLoader(BrokerService.class.getClassLoader());
|
||||||
Resource resource = Utils.resourceFromString(config);
|
Resource resource = Utils.resourceFromString(config);
|
||||||
ResourceXmlApplicationContext ctx = new ResourceXmlApplicationContext((resource)) {
|
|
||||||
|
ResourceXmlApplicationContext ctx = new ResourceXmlApplicationContext(resource, Collections.EMPTY_LIST, null, Collections.EMPTY_LIST, false) {
|
||||||
protected void initBeanDefinitionReader(XmlBeanDefinitionReader reader) {
|
protected void initBeanDefinitionReader(XmlBeanDefinitionReader reader) {
|
||||||
reader.setValidating(false);
|
reader.setValidating(false);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// Handle properties in configuration
|
||||||
|
PropertySourcesPlaceholderConfigurer configurator =
|
||||||
|
new PropertySourcesPlaceholderConfigurer();
|
||||||
|
|
||||||
|
//convert dictionary to properties. Is there a better way?
|
||||||
|
Properties props = new Properties();
|
||||||
|
Enumeration elements = properties.keys();
|
||||||
|
while (elements.hasMoreElements()) {
|
||||||
|
Object key = elements.nextElement();
|
||||||
|
props.put(key, properties.get(key));
|
||||||
|
}
|
||||||
|
|
||||||
|
configurator.setProperties(props);
|
||||||
|
configurator.setIgnoreUnresolvablePlaceholders(true);
|
||||||
|
|
||||||
|
ctx.addBeanFactoryPostProcessor(configurator);
|
||||||
|
|
||||||
|
ctx.refresh();
|
||||||
|
|
||||||
|
// Start the broker
|
||||||
BrokerService broker = ctx.getBean(BrokerService.class);
|
BrokerService broker = ctx.getBean(BrokerService.class);
|
||||||
if (broker == null) {
|
if (broker == null) {
|
||||||
throw new ConfigurationException(null, "Broker not defined");
|
throw new ConfigurationException(null, "Broker not defined");
|
||||||
|
Loading…
x
Reference in New Issue
Block a user