title: Spring Framework : Loading multiple .xml configuration files
body: <p>I am trying to come up with a program that loads multiple configuration .xml files in spring framework. </p>
  
  <p>This is the error I have encountered:</p>
  
  <pre><code>Exception in thread "main" org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'JDBCTemplateFileLog' defined in class path resource [BeansFileLog.xml]: Error setting property values; nested exception is org.springframework.beans.PropertyBatchUpdateException; nested PropertyAccessExceptions (1) are:
  PropertyAccessException 1: org.springframework.beans.MethodInvocationException: Property 'dataSource' threw exception; nested exception is java.lang.IllegalArgumentException: Property 'dataSource' is required
  </code></pre>
  
  <p>These are my xml files:</p>
  
  <ol>
  <li><p>Beans-All-Modules.xml</p>
  
  <p><code>&lt;import resource="BeansJDBC.xml" /&gt;
    &lt;import resource="BeansFileLog.xml" /&gt;
    &lt;import resource="BeansCFAE.xml" /&gt;</code></p></li>
  <li><p>BeansJDBC.xml</p>
  
  <p><code>&lt;bean id="dataSource" 
        class="org.springframework.jdbc.datasource.DriverManagerDataSource"&gt;
        &lt;property name="driverClassName" value="com.mysql.jdbc.Driver"/&gt;
        &lt;property name="url" value="jdbc:mysql://localhost:3306/TEST"/&gt;
        &lt;property name="username" value="root"/&gt;
        &lt;property name="password" value="password"/&gt;
  &lt;/bean&gt;</code></p></li>
  <li><p>BeansFileLog.xml</p>
  
  <pre><code>    '&lt;bean id="JDBCTemplateFileLog" class="in.customfileaccessevent.JDBCTemplateFileLog"&gt;
          &lt;property name="dataSource" ref="dataSource" /&gt;
      &lt;/bean&gt;`
  </code></pre></li>
  <li><p>BeansCFAE.xml</p>
  
  <p><code>&lt;bean id="customFileAccessEvent" class="in.customfileaccessevent.CustomFileAccessEvent"&gt;
      &lt;constructor-arg index="0" type="java.lang.String"&gt;
              &lt;value&gt;E:/HelloWorld.doc&lt;/value&gt;
      &lt;/constructor-arg&gt;
  &lt;/bean&gt;</code></p>
  
  <pre><code>`&lt;bean id="customEventHandler" class="in.customfileaccessevent.CustomFileAccessEventHandler" /&gt;
  
  &lt;bean id="customFileAccessEventPublisher" class="in.customfileaccessevent.CustomFileAccessEventPublisher" /&gt;`
  </code></pre></li>
  </ol>
  
  <p>I have added external jar file "MysqlConnecterJ.. .jar" to the program. Still I am unable to figure out what the problem is?</p>
  
  <p>The MainApp.java program is as follows:</p>
  
  <p>`public class MainAppAllModules {</p>
  
  <pre><code>public static void main(String args[]){
      ConfigurableApplicationContext context = 
              new ClassPathXmlApplicationContext("Beans-All-Module.xml");
      //ApplicationContext context = new ClassPathXmlApplicationContext(new String[] {"BeansCFAE.xml", "BeansJDBC.xml"});
  
              CustomFileAccessEvent ce = (CustomFileAccessEvent) context.getBean("customFileAccessEvent");
      CustomFileAccessEventPublisher cvp = 
              (CustomFileAccessEventPublisher) context.getBean("customFileAccessEventPublisher");
      cvp.publish(ce);  
      /*ConfigurableApplicationContext context1 = 
              new ClassPathXmlApplicationContext("BeansJDBC.xml");*/  
      JDBCTemplateFileLog flogJDBCTemplate = (JDBCTemplateFileLog) context.getBean("JDBCTemplateFileLog");
      System.out.println("File Log Creation");
      flogJDBCTemplate.create("Sample", "Sample");
  
  
  
  }
  </code></pre>
  
  <p>}`</p>