java - Cannot lookup JNDI resource on redeployment -
Problem:
My web app listens to JMS messages in queue and processes messages . I have written some test cases which are for running on CI, to confirm whether messages have been received and processed properly
Spring Config
& lt ;! - JMS message listener - & gt; & Lt; Bean id = "Some message listener" category = "com.whatever.MyListener" /> & Lt ;! - Cached Connection Factory - & gt; & Lt; Bean id = "Cached Connectional" category = "org.springframework.jms.connection.CachingConnectionFactory" & gt; & Lt; Property Name = "targetConnectionFactory" ref = "ActiveMakuConnection Factory" & gt; & Lt; / Property & gt; & Lt; Property Name = "sessionCacheSize" value = "10" & gt; & Lt; / Property & gt; & Lt; Property Name = "ReconnectOpenExpression" value = "true" & gt; & Lt; / Property & gt; & Lt; / Bean & gt; & Lt ;! - Spring message listener - & gt; & Lt; JMS: Audience Container Container-Type = "Default" Connection-Factory = "Cached Connection Factory" Accept = "Client" & gt; & Lt; JMS: listeners destination = "DESTINATION" riff = "some message listener" method = "on message" id = "jmsSomeMessageListener" /> & Lt; / Jms: listener-container & gt; MyListener sees a JNDI database resource to get code inside the class to get an SDL connection . The resource next to the JMS message depends on obtaining a valid SQL connection. JNDDI resource constraints to resources definition context.xml .
At CI for the first time when I re-deploy the war using the Maven targets tomcat: undeploy and tomcat: deploy , my message listener now obtains a database connection Not able to. I get the following exception
exception
java.lang.RuntimeException: javax.naming.NameNotFoundException: name [comp / env / jdbc / Postgrace] is not bound in this context. [Comp] Unable to find This code is DataSource
JNDI lookup code < / P>
reference ctx = new initial concerts (); Datasource DS = (Datasource) CTX. Lookup ("java: comp / env / jdbc / postgres"); I have tried to solve this problem:
I suspect that due to a leak or inappropriate undeployment in an old context the application is unchanged without . By using onDestroy () to stop message listener (jmsSomeMessageListener) from a ServletContextListener by method No effort has been made.
Prevent the message listener before making a tomcat call: undeploy did not help either I was hoping that restarting the listener would force it to use a new reference
Question: Why is the context after revision becoming stale? It is only on the listener and not on the other code that looks at the same context What can I do to fix the problem? (I'm opening to restart the server for every CI construct, temporarily crush the problem)
I solved a similar problem where my database pool was open but I was unable to use JNDI after my war review. I closed the issue with the connection and closed it with JDDI when the war was not lowered.
import javax.servlet.ServletContextEvent; Import javax.servlet.ServletContextListener; Public Class Meals implemented ServletContextListener {Private string DB = "EFU"; @ Override Public Reconnaissance Recession (PCT); PGPoolingDataSource connectionPool = (PGPoolingDataSource) New InitialContext (). Lookup (db); If (connectionpool = null) {connectionPool.close (); New initial contact () Unbind (db); }}} You need to add a block to your web, which is entering your class as a listener:
& lt ; Listener & gt; & Lt; Audience category & gt; Com.foo.bar.MyClass & lt; / Listener Category & gt; & Lt; / Listener & gt;
Comments
Post a Comment