Announcement Announcement Module
Collapse
No announcement yet.
"List" of Interfaces in Spring Configuration XML Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • "List" of Interfaces in Spring Configuration XML

    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).

    Code:
    public interface MessageHandler {
       public void process(BufferedReader br);
       public void setMessageCheckerList(List mcList);
       public List getMessageCheckerList();
     }
    In my Spring XML configuration , i have something like this ,along with other beans
    Code:
    <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 instantiate 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.

  • #2
    Post your testing code...

    Comment


    • #3
      Here is the code

      Code:
       public static void main(String[] args) {
      	ApplicationContext context = new ClassPathXmlApplicationContext(
      			"context.xml");
      	BeanFactory factory = context;
              FileListenerImpl fl = (FileListenerImpl)factory.getBean("messageListener");
              String workingDirectory = fl.getWorkingDirectory();
              MessageHandler ms = (MessageHandlerImpl)factory.getBean("messageHandler");
              HL7CheckerImpl hl = (HL7CheckerImpl)factory.getBean("HL7Checker");
              MessageExecutor messageExecutor = hl.getMessageExecutor();
              System.out.println("test"+ms.getMessageCheckerList());  // This is actually working, But doesnt work when called from Implementation
              System.out.println("objj"+messageExecutor);
              KahootzExecutorImpl ke = (KahootzExecutorImpl)factory.getBean("kahootzExecutor");
              System.out.println("jj " +ke.getCommandString());
              fl.start();
              do{
                  fl.addFile(workingDirectory);
                  fl.addListener(fl);
              }while(!false);   
           	}

      Comment


      • #4
        When i instantiate the bean "messageHandler" and call the getMessageCheckerList, It returns a null value. These getter and setter methods are working fine without using spring.
        Ehrm... You aren't instantiating instances yourself are you?! That will give you a new instance which isn't spring managed or injected by spring. You need to get the instance from the applicationcontext.

        Comment

        Working...
        X