spring-bootactivemq-classicjndicontext.xmlapplication.properties

ActiveMQ How to lookup external context.xml from application.properties or @Annotation [Spring Boot 1.5.8]


I have a Spring Boot 1.5.8 application built with Maven. The project works fine with embedded activeMQ but when I try to set an external data source I cannot get JNDI properties from context.xml located in the server/conf/ directory

This is the context.xml:

 <Context>
    <Resource name="jdbc/TEST" auth="Container" type="javax.sql.DataSource"
                 maxTotal="100" maxIdle="30" maxWaitMillis="10000"
                 username="TEST" password="TEST" driverClassName="oracle.jdbc.OracleDriver"
                 url="jdbc:oracle:thin:@127.0.0.1:1521/TEST"/>
    <Resource name="jms/ConnectionFactory" auth="Container" 
                type="org.apache.activemq.ActiveMQConnectionFactory" 
                description="JMS Connection Factory"
                factory="org.apache.activemq.jndi.JNDIReferenceFactory" 
                brokerURL="tcp://127.0.0.1:8161" 
                brokerName="LocalActiveMQBroker"/>
    <Resource name="jms/ActQueue" 
                auth="Container" 
                type="org.apache.activemq.command.ActiveMQQueue" 
                description="TESTQueue"
                factory="org.apache.activemq.jndi.JNDIReferenceFactory" 
                physicalName="TEST.QUEUE"/>
  </Context>

Originally the application data source was inside application.properties:

# Oracle settings
spring.datasource.url=jdbc:oracle:thin:@127.0.0.1:TEST
spring.datasource.username=TEST
spring.datasource.password=TEST
spring.datasource.driver-class-name=oracle.jdbc.OracleDriver    

#ActiveMQ settings
spring.activemq.broker-url=tcp://localhost:8161
spring.activemq.broker-name=LocalActiveMQBroker
spring.activemq.user=TEST
spring.activemq.password=TEST

My target is to get (lookup) the JNDI resource properties site in server/conf/context.xml through JNDI name.

For example, it was pretty easy for the DB, just write this two line and comment the others:

# Oracle settings from external context.xml (it works!)
spring.datasource.jndi-name=java:/comp/env/jdbc/ACTIgrue
spring.datasource.driver-class-name=oracle.jdbc.OracleDriver

As well above how can i get spring.activemq.broker-url=??? or spring.activemq.broker-name=???

->Every help will be appreciated

UPDATE:

i tried also to bypass the application.properties file and get it directly with annotation as below:

@Resource(name="java:/comp/env/jms/ConnectionFactory")
private ActiveMQConnectionFactory conn;

but the following excepition occurred:

org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'java:/comp/env/jms/ConnectionFactory'

Solution

  • Finally i have found a solution, at this link .

    So this is the correct instruction to put in the application.properties to instance an ActiveMQConnectionFactory bean from JNDI name::

    spring.jms.jndi-name=java:/comp/env/jms/ConnectionFactory
    

    I hope this helps ;)