|
Replies:
2
-
Pages:
1
-
Last Post:
Sep 5, 2005 9:32 PM
by: phillips1021
|
Threads:
[
Previous
|
Next
]
|
|
Posts:
9
Registered:
7/9/05
|
|
|
|
FileInputStream vs. FileSystemResource p. 15
Posted:
Jul 9, 2005 12:52 PM
|
|
For the version of Spring I downloaded (1.2.2), the XmlBeanFactory constructor needs a FileSystemResource instead of a FileInputStream. I suppose that changed in Spring since publication, but it was a bit frustrating to have a build failure on the "hello world" on p. 15
|
|
Posts:
258
Registered:
12/21/03
|
|
|
|
Re: FileInputStream vs. FileSystemResource p. 15
Posted:
Jul 9, 2005 6:08 PM
in response to:
lojic
|
|
That's right...that changed somewhere around Spring 1.2. Unfortunately the book went to print before we found out about that.
|
|
Posts:
50
Registered:
9/5/05
|
|
|
|
Re: FileInputStream vs. FileSystemResource p. 15
Posted:
Sep 5, 2005 9:32 PM
in response to:
habuma
|
|
It would be helpful to post an errata on the books website to point out the changes in the code necessary for the examples to work in the latest version of Spring.
In addition to the new XMLBeansFactory constructor, I also had to have commons-logging.jar from Jakarta-Apache in my class library path to get this class to run correctly.
Here is the HelloApp.java I used to get the first example (chapter 1) to work correctly:
package com.springinaction.chapter01.hello;
/**
* Title: HelloApp.java
*
* Description: Loads the Spring container and uses
* it to retrieve the greeting service. Then has the
* greeting service object call its sayGreeting method.
* From page 14-15 of Spring in Action
*
*You must complile this class with the following jar
* files in your class library path: spring-beans.jar
* (from www.springframework.org) and
* commons-logging.jar from Jakarta-Apache
*
* Date: Sept 2005
*
* @author Bruce Phillips
* @version 1.0
*/
//these are from the spring-beans jar
import org.springframework.beans.factory.BeanFactory;
import org.springframework.beans.factory.xml.XmlBeanFactory;
//this is from the spring-core.jar
import org.springframework.core.io.FileSystemResource;
public class HelloApp {
public static void main(String[] args) {
//create FileSystemResource Object using the XML configuration file
//hello.xml is stored in the project folder
//see page 14 of Spring in Action to read what
//hello.xml does
FileSystemResource configurationXMLFile =
new FileSystemResource("hello.xml");//hello.xml is in the project folder
//Start the Spring container
//using the FileSystemResource object for configuration
//The fileSystemResource object (built above using
//hello.xml file) tells the container to create an object of
//the GreetingServiceImpl class and then to call
//its setGreeting method to set the value of the greeting
//instance field
BeanFactory factory = new XmlBeanFactory( configurationXMLFile ) ;
//using the factory object created above
//get a reference to an object of the class
// that implements the GreetingService
//interface which mandates that the object have
//a fully defined sayGreeting method
//note the cast to a GreetingService object
GreetingService aGreetingService = (GreetingService)
factory.getBean("greetingService") ;
aGreetingService.sayGreeting();
}//end main method
} //end class HelloApp
|
|
|
Legend
|
|
Gold: 300
+
pts
|
|
Silver: 100
- 299
pts
|
|
Bronze: 25
- 99
pts
|
|
Manning Author
|
|
Manning Staff
|
|