Aparna Shaji Peter
Aparna Shaji Peter

Reputation: 155

Spring Boot- set JmsTemplate Configuration Properties from Java class (not from application properties file)

Followed this tutorial https://developer.ibm.com/messaging/2018/04/03/mq-jms-spring-boot/ and developed a Spring Boot JMS applicatin which sends a message to IBM MQ. (used this dependency - mq-jms-spring-boot-starter).

As per the tutorial, the configuration properties (Queue Manager, Channel, Port etc) can be given in application.yml/ application.properties file as below, and JmsTemplate will automatically be configured with the properties.

ibm.mq.queueManager=QM1
ibm.mq.channel=SYSTEM.DEF.SVRCONN
ibm.mq.connName=server.example.com(1414)
ibm.mq.user=user1
ibm.mq.password=passw0rd

The application works perfect and it sends message to the MQ now this way.

But I want to set the properties inside the class, not from the properties file (reading from a database or something). How to set these values inside the class?

Upvotes: 2

Views: 3793

Answers (1)

Mark Taylor
Mark Taylor

Reputation: 1017

You can use a customizer method on the CF after the initial properties have been populated.

In the Application class, this code allows additional properties to be configured:

@Bean
public MQConnectionFactoryCustomizer myCustomizer() {

  MQConnectionFactoryCustomizer c = new MQConnectionFactoryCustomizer() {
    @Override
    public void customize(MQConnectionFactory factory) {
       factory.setXXXX(property, value);
    }
  };
  return c;

}

Upvotes: 2

Related Questions