mirror of https://github.com/apache/activemq.git
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"
|
||||
brokerName="localhost"
|
||||
brokerName="${broker-name}"
|
||||
dataDirectory="data"
|
||||
start="false">
|
||||
|
||||
|
|
|
@ -1,3 +1,3 @@
|
|||
broker-name=localhost
|
||||
data=${karaf.data}/localhost
|
||||
broker-name=amq-broker
|
||||
data=${karaf.data}/${broker-name}
|
||||
config=${karaf.base}/etc/activemq.xml
|
|
@ -25,10 +25,12 @@ import org.osgi.service.cm.ManagedServiceFactory;
|
|||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
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 java.util.Dictionary;
|
||||
import java.util.HashMap;
|
||||
import java.util.*;
|
||||
|
||||
public class ActiveMQServiceFactory implements ManagedServiceFactory {
|
||||
|
||||
|
@ -54,17 +56,37 @@ public class ActiveMQServiceFactory implements ManagedServiceFactory {
|
|||
}
|
||||
|
||||
LOG.info("Starting broker " + name);
|
||||
//TODO properties
|
||||
|
||||
try {
|
||||
Thread.currentThread().setContextClassLoader(BrokerService.class.getClassLoader());
|
||||
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) {
|
||||
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);
|
||||
if (broker == null) {
|
||||
throw new ConfigurationException(null, "Broker not defined");
|
||||
|
|
Loading…
Reference in New Issue