Skip to content

Chapter 4 Lab

David Zemon edited this page Feb 6, 2017 · 2 revisions

Migration to Java Config

The purpose of this lab is to teach you how to use Spring's Java Configuration. One bean has already been converted for you. Convert the remaining beans to Java Config and delete the XML.

Instructions

  1. Add the beans listed below to MainConfig.java.
    • scanner
    • randomNumberGenerator
    • pokemonDao
    • pokemonLocationDao
    • pokemonFactory
    • gameBoard
      • This bean requires a size to be imported from our properties file.
      • Use @Value("${default-map-size}") final int size as a parameter to the gameBoard() method
      • Import properties by adding @PropertySource("...") where the argument to the annotation is the path to your properties file. Note that, in the case of multiple properties file, an array of Strings can be used.
  2. Remove the XML configuration file its reference
    • Remove the @ImportResource("classpath:spring-context.xml")
    • Delete the XML file.
  3. Test your application
    • Run MainConfig.java and fix any issues that might come up.

Clone this wiki locally