Results 1 to 3 of 3

Thread: just start.

  1. #1
    Join Date
    Nov 2008
    Posts
    1

    Default just start.

    Hello guys...

    i just started to learn Spring2. according to the spring2, it looks like the most advantage of spring is 'Dependency Injection'.

    i am reading Spring in action. but i stuck from the first chapter.

    /*
    BeanFactory factory = new XmlBeanFactory(new FileSystemResource("classes/com/test/chap1/knight/knight.xml"));


    // TODO Auto-generated method stub
    Knight knight =
    (Knight) factory.getBean("knight");
    */

    // What's the difference between this and above.
    Knight knight = new KnightOfTheRoundTable("Bedivere");


    the commented line is what is in book. the last line is what i thought and work as same as book.
    what's the difference between book and the last line?

  2. #2
    Join Date
    May 2007
    Location
    Saint Petersburg, Russian Federation
    Posts
    1,189

    Default

    I suggest you just continue reading and at least finish the chapter about dependency injection.

  3. #3
    Join Date
    Aug 2007
    Location
    Brisbane, Australia
    Posts
    33

    Default

    Both do exactly the same thing, just one demonstrates the Spring way.

    Code:
    Knight knight =
    (Knight) factory.getBean("knight");
    Gets an instance of Knight from the configured BeanFactory.

    Code:
    Knight knight = new KnightOfTheRoundTable("Bedivere");
    Returns a Knight as per a stock std instantiation.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •