I want to use a JMS connection whose factory is stored in JNDI. To access the JNDI, I must specify the initial context factory's class and also the JNDI provider URL.
To my surprise, I found out that this is not possible with just the SpringBoot properties, see this question on StackOverflow.
The JmsProperties object only has a property for the name of the entry for the connection and has no properties to correctly access/build up that context.
As of now, I specify the following Java system properties when starting my program (a standalone one) so that the JMS factory is found:
* java.naming.factory.initial
* java.naming.provider.url
But this is not the Spring way to do things. Also, it's too global. In my case, the two settings should only be used for getting the JMS connection factory, not other JNDI objects. E.g. a datasource (if I used one) might be somewhere else.
IMO those properties should also be exposed via JmsProperties. Or it should be documented how to use custom values here.
As of now, I'm going to create/configure some JNDI related beans manually in order to avoid the need to use Java system properties.
Comment From: wilkinsona
Thanks for the suggestion. Using JNDI in a Spring Boot application is quite unusual, even more so when requiring a custom initial context per object. As you've already described, what you want to do is already possible by manually retrieving the ConnectionFactory from JNDI and exposing it as a bean. Given this situation, I'm not sure that we can justify adding support for this. I'll flag this for discussion at a team meeting to see if there's a preferred course of action among the team.
If we were to do anything here, it should be done consistently. Spring Boot has three application properties that can be used to retrieve a bean from JNDI:
spring.datasource.jndi-namespring.jms.jndi-namespring.mail.jndi-name
Comment From: fml2
Spring Boot has three application properties that can be used to retrieve a bean from JNDI
This was the reason why I expected to be able to do it with just the "inbuilt" properties. By having these properties, SpringBoot makes the statement that it allows to retrieve the objects by specifying some properties. But this promise is implemented to 30% only.
what you want to do is already possible by manually retrieving the ConnectionFactory from JNDI and exposing it as a bean
This is exactly what I did.
Comment From: wilkinsona
We have discussed this today and we are in agreement that the benefits of implementing this are outweighed by the added complexity. Please continue defining your own ConnectionFactory bean instead. Thanks anyway for the suggestion.
Comment From: fml2
Although I think that two additional properties (providerUrl and initialContextFactory) would not add much complexity, I'm fine with your decision.