For some reason, lately I've been picking on Spring In Action, Second Edition. This is due in large part to it being the primary book that I've been reading. I would like to set the record straight before continuing with this next post and say that I like this second edition of Spring In Action by Craig Walls and Ryan Breidenbach. I would go so far as to say that I like it a lot. I've used it for many things, first and foremost for giving me a deeper understanding of the Spring framework. And a natural extension of that has been professionally at work.
That being said, I do want to point out that there is a typo on p.345, Section 9.1, paragraph 1, last sentence in the paragraph reads:
"It might be easier to answer that question by first talking about their antithesis: contact-last web services."
This should read:
"It might be easier to answer that question by first talking about their antithesis: contract-last web services."
I think I've potentially missed my calling as a nit-picky book editor. Perhaps I need to make myself useful and point this out to the book's publisher (Manning Publications)in case they care to correct it.
Randomized blog around Software Development and it's place in my life (may include drink recipes).
It's hard to beat a person who never gives up.
~ Babe Ruth
Showing posts with label books. Show all posts
Showing posts with label books. Show all posts
Monday, August 31, 2009
Friday, July 3, 2009
Spring In Action - KnightApp modification
I'm currently reading Spring In Action by Craig Walls and Ryan Breidenbach from Manning Publications. Let me first thank them for writing this book as it's a reference that I've used both professionally and personally. I like the Manning "* In Action" series of books as they tend to get to the point with doing things through examples. However, I believe that the examples could have been a little better worked out, which I will point out here in a minute. Like any good technical author, though, they did include their source code for each of their examples.
In Chapter 1 they begin walking you through core Spring via the characteristic Hello World app pointing out Dependency Injection, and it's benefits. Their second example walks through a Knight application, and is used to demonstrate both dependency injection and Aspect Oriented Programming (AOP). I'm looking forward to seeing how Spring facilitates AOP.
They describe AOP as a technique that "promotes separation of concerns within a software system." It looks like the intention is to remove from application code those items that all portions of a system need to concern themselves with, such as logging, transaction management, and security. All classes in a system shouldn't have to concern themselves with these items as part of their application/business logic as they are concerns for the entire system being developed. I'll probably have more to post on AOP once I become more familiar with it's cross cutting domain and how this paradigm addresses them. The intention of this particular post is to point out a change you will need to make to one of your classes in this example or else it will not work.
While walking through dependency injection Walls and Breidenbach write a driver class to kick of the application called KnightApp.java. Their main in KnightApp.java is coded as follows:
-- KnightApp --
(Click for source)
As you move from using the Knight application from looking at dependancy injection to looking at AOP, they don't mention that the driver application KnightApp.java needs to be updated to no longer load the spring config file using BeanFactory and XmlBeanFactory to using ApplicationContext and ClassPathXmlApplicationContext, as shown below.
-- KnightAppModified --
(Click for source)
As I mentioned earlier, like any good technical authors they included the working source code for their examples, as this is how I discovered what needed to be changed. But it does tend to be tedious to track down. I'm not entirely sure of the need for the change yet, but intend on discovering it as I go through more of the book.
In Chapter 1 they begin walking you through core Spring via the characteristic Hello World app pointing out Dependency Injection, and it's benefits. Their second example walks through a Knight application, and is used to demonstrate both dependency injection and Aspect Oriented Programming (AOP). I'm looking forward to seeing how Spring facilitates AOP.
They describe AOP as a technique that "promotes separation of concerns within a software system." It looks like the intention is to remove from application code those items that all portions of a system need to concern themselves with, such as logging, transaction management, and security. All classes in a system shouldn't have to concern themselves with these items as part of their application/business logic as they are concerns for the entire system being developed. I'll probably have more to post on AOP once I become more familiar with it's cross cutting domain and how this paradigm addresses them. The intention of this particular post is to point out a change you will need to make to one of your classes in this example or else it will not work.
While walking through dependency injection Walls and Breidenbach write a driver class to kick of the application called KnightApp.java. Their main in KnightApp.java is coded as follows:
-- KnightApp --
(Click for source)
package com.springinaction.chapter01.knight;
import org.springframework.beans.factory.BeanFactory;
import org.springframework.beans.factory.xml.XmlBeanFactory;
import org.springframework.core.io.FileSystemResource;
public class KnightApp {
public static void main(String[] args) throws Exception{
BeanFactory factory =
new XmlBeanFactory(new FileSystemResource("resources/knight.xml"));
Knight knight = (Knight) factory.getBean("knight");
knight.embarkOnQuest();
}
}
As you move from using the Knight application from looking at dependancy injection to looking at AOP, they don't mention that the driver application KnightApp.java needs to be updated to no longer load the spring config file using BeanFactory and XmlBeanFactory to using ApplicationContext and ClassPathXmlApplicationContext, as shown below.
-- KnightAppModified --
(Click for source)
package com.springinaction.chapter01.knight;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
public class KnightApp {
public static void main(String[] args) throws Exception {
ApplicationContext ctx =
new ClassPathXmlApplicationContext(
"com/springinaction/chapter01/knight/knight.xml");
Knight knight =
(Knight) ctx.getBean("knight");
knight.embarkOnQuest();
}
}
As I mentioned earlier, like any good technical authors they included the working source code for their examples, as this is how I discovered what needed to be changed. But it does tend to be tedious to track down. I'm not entirely sure of the need for the change yet, but intend on discovering it as I go through more of the book.
Subscribe to:
Posts (Atom)