AntoineB AntoineB - 11 months ago 164
Java Question

SpringBoot + ActiveMQ - How to set trusted packages?

I'm creating two springboot server & client applications communicating using JMS, and everything is working fine the release

for activemq, but as soon as I update to the
version, I'm getting the following error : Could not convert JMS message; nested exception is javax.jms.JMSException: Failed to build body from content. Serializable class not available to broker. Reason: java.lang.ClassNotFoundException: Forbidden class MyClass! This class is not trusted to be serialized as ObjectMessage payload. Please take a look at for more information on how to configure trusted classes.

I went on the URL that is provided and I figured out that my issue is related to the new security implemented in the
release of ActiveMQ, and I understand that I could fix it by defining the trusted packages, but I have no idea on where to put such a configuration in my SpringBoot project.

The only reference I'm making to the JMS queue in my client and my server is setting up it's URI in and enabling JMS on my "main" class with
, and here's my configuration on the separate broker :

@ConfigurationProperties(prefix = "activemq")
public class BrokerConfiguration {

* Defaults to TCP 10000
private String connectorURI = "tcp://";
private String kahaDBDataDir = "../../data/activemq";

public String getConnectorURI() {
return connectorURI;

public void setConnectorURI(String connectorURI) {
this.connectorURI = connectorURI;

public String getKahaDBDataDir() {
return kahaDBDataDir;

public void setKahaDBDataDir(String kahaDBDataDir) {
this.kahaDBDataDir = kahaDBDataDir;

@Bean(initMethod = "start", destroyMethod = "stop")
public BrokerService broker() throws Exception {
KahaDBPersistenceAdapter persistenceAdapter = new KahaDBPersistenceAdapter();
persistenceAdapter.setDirectory(new File(kahaDBDataDir));

final BrokerService broker = new BrokerService();
broker.setShutdownHooks(Collections.<Runnable> singletonList(new SpringContextHook()));

final ManagementContext managementContext = new ManagementContext();

return broker;

So I'd like to know where I'm supposed to specify the trusted packages.

Thanks :)

Answer Source

Add the following bean:

public ActiveMQConnectionFactory activeMQConnectionFactory() {
    ActiveMQConnectionFactory factory = new ActiveMQConnectionFactory("your broker URL");
    return factory;

The ability to do this via a configuration property has been added for the next release: