如果遇到"ActiveMQ配置:BrokerXMLConfig activemq.xml-相对路径文件未找到"的错误,可以尝试以下解决方法:
BrokerService broker = new BrokerService();
broker.setBrokerName("myBroker");
broker.setUseJmx(true);
broker.setPersistent(false);
broker.addConnector("tcp://localhost:61616");
// 设置activemq.xml的路径
String configPath = "./activemq.xml";
broker.setConfigurationUri(configPath);
broker.start();
setConfigurationUri()
方法。BrokerService broker = new BrokerService();
broker.setBrokerName("myBroker");
broker.setUseJmx(true);
broker.setPersistent(false);
broker.addConnector("tcp://localhost:61616");
// 获取activemq.xml的路径
ClassLoader classLoader = getClass().getClassLoader();
URL configUrl = classLoader.getResource("activemq.xml");
String configPath = configUrl.getPath();
broker.setConfigurationUri(configPath);
broker.start();
BrokerService broker = new BrokerService();
broker.setBrokerName("myBroker");
broker.setUseJmx(true);
broker.setPersistent(false);
broker.addConnector("tcp://localhost:61616");
// 设置activemq.xml的绝对路径
String configPath = "/path/to/activemq.xml";
broker.setConfigurationUri(configPath);
broker.start();
请根据实际情况选择适合的解决方法来解决该错误。