Oh, for a carburetor

I did want to document what solved my latest issue.

Yesterday’s Basic Mistake

In the last day or so I had been trying to get a JMS message producer hooked up to the web method entry point in my test application, so that a SOAP request coming in could kick off the writing of a JMS message to the queue, and then the listener could do the database writing (up to this point I didn’t have a message producer so you had to put messages in the JMS queue manually, using the ActiveMQ console).

I had set up my Spring beans like this:

    <bean id="jmsTemplate" class="org.springframework.jms.core.JmsTemplate">
<property name="connectionFactory" ref="queueConnectionFactory" />
    <bean id="messageSender" class="com.ontsys.dmn.MessageSender">
<property name="jmsTemplate" ref="jmsTemplate" />
<property name="queueName" value="${com.ontsys.xa.example.queue.name}"/>

But in my web service class, I had made the mistake of instantiating a new MessageSender myself instead of having it injected — and then I wondered why the MessageSender’s jmsTemplate was null!

This Time Was Different

I tried to correct yesterday’s mistake by creating a bean definition for MySimpleServiceImpl like I have in the past when this type of thing happens, to inject MySimpleServiceImpl with the messageSender:

    <bean id="serviceImpl" class="com.ontsys.service.MySimpleServiceImpl">
<property name="messageSender" ref="messageSender" />

But I still got the NullPointerException.  What could it be?!

CXF, and an easy solution

Keith helped me see that the MySimpleServiceImpl class was already a Spring bean in the WEB-INF/services.xml Spring bean file which was already being deployed as part of my project.  I simply needed to remove the duplicate MySimpleServiceImpl bean definition from my applicationContext.xml and add the messageSender reference to the existing bean definition in WEB-INF/services.xml (we have autowiring turned off at the moment, in this test project anyway)… and then it worked!

The WEB-INF/{services.xml,web.xml} files really haven’t been on my radar up to this point. Maybe they will be now!

*Title: If you have a carburetor, you can avoid the problems of [fuel] injection, right? (Just joking around after multiple issues involving my (accidental non-) use of dependency injection.)

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.