Spring Config file consisting of List of Implementations

I Am very new to Spring. I have an Interface (MessageHandler ) which has a get method, this method returns a list of Implementations of another interface (messageChecker).

public interface MessageHandler {
   public void process(BufferedReader br);
   public void setMessageCheckerList(List mcList);
   [B]public List getMessageCheckerList();[/B]
 }

In my Spring XML configuration , i have something like this ,along with other beans

<bean id="messageHandler" class="com.XXX.messagereceiver.MessageHandlerImpl">
  <property name="messageCheckerList" ref="checkerList"/>
 </bean>

 <bean id="checkerList" class="java.util.ArrayList">
  <constructor-arg>
   <list>
    <ref bean="HL7Checker"/>
   </list>
  </constructor-arg>
 </bean>

 <bean id="HL7Checker" class="com.XXX.messagereceiver.HL7CheckerImpl">
     <property name="messageExecutor" ref="kahootzExecutor"/>
 </bean>

Here i am passing a checkerlist - which is a list of Implementations ( For now i have only 1) of the Interface (messageChecker)

Checkerlist is containing references to Bean Id's which are actual implementaions.

HL7Checker is an implementation of an Interface messageChecker.

But when i run the main program, When i inject the bean "messageHandler" and call the getMessageCheckerList, It returns a null value. These getter and setter methods are working fine without using spring.

I am not sure what seems to be the problem.

Answers


I don't know the answer for you troubles, but I would check:

  • is the setter setMessageCheckerList(List) in messageHandler bean called? (either using some debugger or some trace output like System.out...). If it's not, there's probably something wrong with your Spring XML configuration setup. The bean definition you posted requires the property to be set and Spring wouldn't create the messageHandler bean without setting the property.
  • who calls the setMessageCheckerList(List) setter? Or even more precise, what code writes to the field which stores the value of the property? Maybe the field is initialized properly by Spring but gets overwritten to null later on?
  • are you sure you call the getMessageCheckerList on the very same object Spring has configured for you (that is, the messageHandler bean). The definition you have posted clearly states an instance of MessageHandlerImpl is created by Spring, but it doesn't prevent other instances to be created in other ways. So maybe the instance created by Spring holds the proper value, but you run the get... on a wrong instance?

Need Your Help

Simpliest python long polling

python django multithreading long-polling ajax-polling

I saw some threads about long polling in python, but my problem is not so bit to use some additional kits like tornado etc.

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.