title: How many ways are there to configure the Spring framework? What are the differences between them technically? (Not pros or cons..)
body: <p>I am studying <a href="https://rads.stackoverflow.com/amzn/click/com/1118892925" rel="noreferrer" rel="nofollow noreferrer">this</a> book (which I would highly recommend), and I am confused about how the authors explain the way Spring framework can be configured.</p>
  <p>You can see some code examples that are used in the book <a href="http://www.wrox.com/WileyCDA/WroxTitle/Beginning-Spring.productCd-1118892925,descCd-DOWNLOAD.html" rel="noreferrer">here</a>. (They are available to anyone..) The code I am referring the will be the code from chapter 2, if you would like to take a look.</p>
  <p>The book states that there are <strong>3 ways to configure the Spring Container</strong>.</p>
  <hr />
  <p><strong>XML - based configuration</strong></p>
  <p>This will require an xml file that resembles something like this:</p>
  <pre><code>&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;
  &lt;beans xmlns=&quot;http://www.springframework.org/schema/beans&quot; ...&gt;
  
      &lt;bean id=&quot;accountService&quot; class=&quot;com.wiley.beginningspring.ch2.AccountServiceImpl&quot;&gt;
          &lt;property name=&quot;accountDao&quot; ref=&quot;accountDao&quot;/&gt;
      &lt;/bean&gt;
      
      &lt;bean id=&quot;accountDao&quot; class=&quot;com.wiley.beginningspring.ch2.AccountDaoInMemoryImpl&quot;&gt;
      &lt;/bean&gt;
  
  &lt;/beans&gt;
  </code></pre>
  <p>And then in order to bootstrap Spring, the code that will be used will be:</p>
  <pre><code>ClassPathXmlApplicationContext applicationContext = new ClassPathXmlApplicationContext(&quot;/com/wiley/beginningspring/ch2/ch2-beans.xml&quot;);
  </code></pre>
  <p>I do not have any confusions at this moment.</p>
  <hr />
  <p><strong>Java Based Configuration</strong></p>
  <p>In this Configuration method, there will be a class for the configuration as follows:</p>
  <pre><code>@Configuration
  public class Ch2BeanConfiguration {
  
      @Bean
      public AccountService accountService() {
          AccountServiceImpl bean = new AccountServiceImpl();
          bean.setAccountDao(accountDao());
          return bean;
      }
      
      @Bean
      public AccountDao accountDao() {
          AccountDaoInMemoryImpl bean = new AccountDaoInMemoryImpl();
          return bean;
      }
  }
  </code></pre>
  <p>and the code that is responsible for bootstrapping Spring looks like:</p>
  <pre><code>ApplicationContext applicationContext
              = new AnnotationConfigApplicationContext(Ch2BeanConfiguration.class);
  </code></pre>
  <p>So up to here, all is clear for me. (Kind of..) I would also like to note that, here we actually have an Annotation which is called @Configuration...</p>
  <hr />
  <p><strong>Annotation Based Configuration</strong></p>
  <p>The last configuration method available, explained in the book is the <strong>Annotation Based Configuration</strong>.</p>
  <p>There is an xml file just like we had in the XML-Based Configuration, however a much smaller one:</p>
  <pre><code>&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;
  &lt;beans xmlns=&quot;http://www.springframework.org/schema/beans&quot; ...&gt;
      &lt;context:component-scan base-package=&quot;com.wiley.beginningspring.ch2&quot;/&gt;
  &lt;/beans&gt;
  </code></pre>
  <p>All the beans have Annotations such as:</p>
  <pre><code>@Component, @Service
  </code></pre>
  <p>etc..</p>
  <p>And all the dependencies have the annotations:</p>
  <pre><code>@Autowired
  </code></pre>
  <p>so that beans can be injected.</p>
  <p>The way Spring framework bootstrapped in this configuration method is as follows:</p>
  <pre><code>ClassPathXmlApplicationContext applicationContext = new ClassPathXmlApplicationContext(&quot;/ch2-beans.xml&quot;);
  </code></pre>
  <hr />
  <p><strong>Here are my questions:</strong></p>
  <p>Why is the (so-called) <strong>Annotation Based Configuration</strong> actually using <strong>ClassPathXmlApplicationContext</strong> but not <strong>AnnotationConfigApplicationContext</strong> above? The latter seems much more appropriate to be used in a Configuration that has the words &quot;Annotation Based&quot; in it, isn 't it?</p>
  <p>The <strong>Java Based Configuration</strong> explained in the book seems like what should be called <strong>Annotation Based Configuration</strong>.?</p>
  <p>And the way Annotation Based Configuration explained in the book actually seems to me something like: XML-Based Configuration with Autowired beans. It does not even have the @Configuration annotation, which the &quot;Java Based Configuration&quot; has..</p>
  <p>How many ways are there to configure Spring framework?</p>