Errata

Spring: A Developer's Notebook

Errata for Spring: A Developer's Notebook

Submit your own errata for this product.

The errata list is a list of errors and their corrections that were found after the product was released. If the error was corrected in a later version or reprint the date of the correction will be displayed in the column titled "Date Corrected".

The following errata were submitted by our customers and approved as valid errors by the author or editor.

Color key: Serious technical mistake Minor technical mistake Language or formatting error Typo Question Note Update

Version Location Description Submitted By Date submitted Date corrected
Printed
Page 6
second to last sentence;

should read:
We'll rename the RentABike file, class definition and constructor to
ArrayListRentABike (Example 1-4)...

Anonymous   
Printed
Page 7
Example 1-4

add the following inside the class definition

private String name;

public ArrayListRentABike() {}
public void setStoreName(String name) { this.name = name; }
public String getStoreName() { return this.name; }

Anonymous   
Printed
Page 7
How do i do that?

Errata to the Example 1-4 Errata

You say to add the following:

public ArrayListRentABike() {}

Although this will compile and run it will not produce the correct output. One has
to add the inventory to the bike list. So adding the following will produce the
correct output:

public ArrayListRentABike() {

bikes.add(new Bike("Shimano", "Roadmaster", 20, "11111", 15, "Fair"));
bikes.add(new Bike("Cannondale", "F2000 XTR", 18, "22222", 12, "Excellent"));
bikes.add(new Bike("Trek", "6000", 19, "33333", 12.4, "Fair"));
}

Then one should change the old constructor as follows:

public ArrayListRentABike(String storeName) {
ArrayListRentABike();
this.storeName = storeName;

}

Also for chapter one you don't say which jars to include. I added the following to
get it to work:

spring.jar
commons-logging.jar
log4j-1.2.9.jar

And I added the following log4j.properties file:

log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern=[%5p] %d{HH:mm:ss} %c{1} - %m%n

log4j.appender.daily=org.apache.log4j.DailyRollingFileAppender
log4j.appender.daily.layout=org.apache.log4j.PatternLayout
log4j.appender.daily.layout.ConversionPattern=[%5p] %d{HH:mm:ss} %c{1} - %m%n
log4j.appender.daily.File=@logfile.path@
log4j.appender.daily.DatePattern='.'yyyy-MM-dd

log4j.rootLogger=WARN,stdout,daily

log4j.category.com.springinaction=DEBUG
log4j.category.org.springframework=WARN
log4j.category.net.sf.hibernate=WARN
log4j.category.net.sf.acegisecurity=DEBUG

Anonymous   
Printed
Page 13
Examples 1-9 and 1-10

In example 1-9 a configuration file is created named RentABike-context.xml but in
example 1-10 it is referred to as RentABikeApp-context.xml (note the extra 'App' that
has been included in the name).

Anonymous   
Printed
Page 22
Example 2-6

Example 2-6 should be labeled bikes.jsp, not editBike.jsp

Anonymous   
Printed
Page 27
Example 2-11

should include the following taglib definition

<taglib>
<taglib-uri>http://java.sun.com/jstl/core</taglib-uri>
<taglib-location>/WEB-INF/lib/c.tld</taglib-location>
</taglib>

In Chapter 2, Exercise 2;
The code requires the addition of the /WEB-INF/lib folder, with the following
contents: c.tld, standard.jar, jstl.jar and all the Spring jars.

Anonymous   
Printed
Page 27
Figure 2-2

The URL in Figure 2-2 should have /bikes.bikes as the URL in the address
bar, not bikes.htm

Anonymous   
Printed
Page 29
2nd-to-last paragraph

"alternate path"
should read:
"alternative path"

Anonymous   
Printed
Page 34
Example 2-17

This change (the addition of the editBikeForm bean) means
that the UrlMapper originally shown in example originally shown in example 2-12
should now point the url /editBike.bikes to editBikeForm, not editBikeController

-- The changes in Exercise 3 require the following addition to web.xml:
<taglib>
<taglib-uri>/spring</taglib-uri>
<taglib-location>/WEB-INF/lib/spring.tld</taglib-location>
</taglib>

Anonymous   
Printed
Page 58
2nd paragraph

"... and, if you are a consientious developer, implementing a test class that tests your action."
should be:
"... and, if you are a conscientious developer, implementing a test class that tests your action."

-- Page 61, example 4-3, requires that the System Property "jdbc.drivers" be set to
"com.mysql.jdbc.Driver" and the appropriate jar file containing the driver exist in
the /lib folder. That system property can be set from the command line, from the IDE,
or in code, such as:

System.setProperty("jdbc.drivers", "com.mysql.jdbc.Driver");

-- At the end of exercise 1, page 61, we say we "Then, you created a new Ant task,
and ran the task to create a database and some sample data. ", but the Ant task is
never shown. Here it is:

<path id="mysql.class.path">
<pathelement location="${war.dir}/WEB-INF/lib/mysql-connector-java-3.0.14-
production-bin.jar"/>
</path>

<target name="create.tables">
<sql driver="com.mysql.jdbc.Driver"
url="${database.url}"
userid="${database.username}"
password="">
<classpath>
<path refid="mysql.class.path"/>
</classpath>
<fileset dir="${db.dir}">
<include name="rentabike.sql"/>
</fileset>
</sql>
</target>

-- Exercise 3, example 4-7 (pages 67 and 68): drop the line
"template.setDataSource(this.dataSource)" both places it appears in the sample.

-- Exercise 4, starting on page 68, we begin showing the use of two new classes,
Reservation and Customer. Those classes are shown below:

Reservation.java -

package com.springbook;

import java.util.Date;

public class Reservation {
private int reservationId;
private Date reservationDate;
private Bike bike;
private Customer customer;

public Reservation() {

}

public int getReservationId() {
return reservationId;
}

public void setReservationId(int reservationId) {
this.reservationId = reservationId;
}

public Date getReservationDate() {
return reservationDate;
}

public void setReservationDate(Date reservationDate) {
this.reservationDate = reservationDate;
}

public Bike getBike() {
return bike;
}

public void setBike(Bike bike) {
this.bike = bike;
}

public Customer getCustomer() {
return customer;
}

public void setCustomer(Customer customer) {
this.customer = customer;
}

public Reservation(int id, Bike bike, Customer customer, Date date) {
this.reservationId = id;
this.bike = bike;
this.customer = customer;
this.reservationDate = date;
}

public String toString() {
return "Reservation : " +
"reservationId -- " + reservationId +
"
: reservationDate -- " + reservationDate +
"
: bike -- " + bike +
"
: customer -- " + customer +
".
";
}

}

Customer.java -

package com.springbook;

import java.util.Set;

public class Customer {
private int custId;
private String firstName;
private String lastName;
private Set reservations;

public Set getReservations() {
return reservations;
}

public void setReservations(Set reservations) {
this.reservations = reservations;
}

public int getCustId() {
return custId;
}

public void setCustId(int custId) {
this.custId = custId;
}

public String getFirstName() {
return firstName;
}

public void setFirstName(String firstName) {
this.firstName = firstName;
}

public String getLastName() {
return lastName;
}

public void setLastName(String lastName) {
this.lastName = lastName;
}

public Customer(int custId, String firstName, String lastName) {
this.custId = custId;
this.firstName = firstName;
this.lastName = lastName;
}

public Customer() {
}

public String toString() {
return "Customer : " +
"custId -- " + custId +
"
: firstName -- " + firstName +
"
: lastName -- " + lastName +
".
";
}

}

Anonymous   
Printed
Page 71
-Example 4-8

Change
JdcbTemplate template = new JdcbTemplate();
to
JdbcTemplate template = getJdbcTemplate();

-- In Exercise 5, example 4-10, page 72, the line MockControl controlConnection =
MockControl.createControl(Connection.class); should be changed to use the
createNiceControl method instead.

-- In Exercise 1, there is a new dependency on jdom.jar which should go in the /WEB-
INF/lib folder.

-- in Exercise 2, the build file should be updated to add the new dependencies to the
bikestore.class.path.

-- in Exercise 3, example 5-14, page 91, the first property is missing the opening
"<"

-- in Exercise 1, we show the new logger intercepter using the LogEvent class, but
never show the class itself or its mapping. They are shown below:

LogEvent.java -

package com.springbook;

import java.util.Date;

/**
* Replace
*
* @author Justin Gehtland
* @version $Revision: 1.1 $ $Date: 2004/10/15 21:21:41 $
*/
public class LogEvent {
private int eventId;
private String methodName;
private Date dateTime;
private String message;

public LogEvent() {

}

public LogEvent(String methodName, Date date, String message) {
this.eventId = -1;
this.methodName = methodName;
this.dateTime = date;
this.message = message;
}
public LogEvent(String methodName, Date date) {
this(methodName, date, "");
}

public String getMessage() {
return message;
}

public void setMessage(String message) {
this.message = message;
}

public int getEventId() {
return eventId;
}

public void setEventId(int eventId) {
this.eventId = eventId;
}

public String getMethodName() {
return methodName;
}

public void setMethodName(String methodName) {
this.methodName = methodName;
}

public Date getDateTime() {
return dateTime;
}

public void setDateTime(Date dateTime) {
this.dateTime = dateTime;
}
}

LogEvent.hbm.xml -

<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD//EN"
"http://hibernate.sf.net/hibernate-mapping-2.0.dtd">

<hibernate-mapping>
<class name="com.springbook.LogEvent" table="eventlog">
<id name="eventId" column="eventId" type="java.lang.Integer" unsaved-value="-1">
<generator class="native"></generator>
</id>
<property name="methodName" column="methodname" type="string"/>
<property name="dateTime" column="datetime" type="date"/>
<property name="message" column="message" type="string"/>
</class>
</hibernate-mapping>

-- in Exercise 2, example 6-3, page 103, at the end of the example (after the closing
</beans> tag) there is another datasource bean defined. This bean is actually defined
in the file (in the portion elided in the example, where the <!-- etc. --> comment
is). If a read were to copy and paste the code as shown, it would not be valid XML.

-- in Exercise 6, examples 6-16 and 6-18 (pages 111 and 112) should be labeled
MockInterceptorTest.java, not ControllerTest.java

-- in Exercise 6, example 6-18, page 113, the second appearance of the line
"sessionControl.setMatcher(MockControl.ALWAYS_MATCHER);" should be removed.

-- Exercise 3, starting on page 121. This entire section (multiple databases)
requires that your application be running in a J2EE container environment, and that
the appropriate JNDI system properties are set (javax.naming.factory.initial, etc.).
The JTATransactionManager does not work without a JTA provider to back it. We do not
mention this directly in the text, and should.

-- In Exercise 4, example 7-18, page 130, the *.htm should be changed to *.bikes. In
addition, we need to add the following line at the end of the example to include
ACEGI's Auto Integration Filter: <bean id="autoIntegrationFilter"
class="net.sf.acegisecurity.ui.AutoIntegrationFilter"></bean>

-- in Exercise 2, example 8-7, page 146, need to change the serviceURL to
yourhost:8080/rentaBike/remoting/RentABike. Also, in web.xml (ex. 8-5), need to add
a new servlet-mapping.

<servlet-mapping>
<servlet-name>remoting</servlet-name>
<url-pattern>/remoting/*</url-pattern>
</servlet-mapping>

-- in Exercise 3, we should mention that the standalone listener (example 8-15, page
150) requires a JNDI lookup for the JMS provider. ActiveMQ comes with a non-JNDI test
consumer called Consumer, available in the /example directory of the ActiveMQ
install.

-- exercise 4, example 8-16, page 153, the file is missing its last "}"

-- exercise 4, example 8-18, page 154, the line "assertEquals("La Bruja",
b.getManufacturer());" should be "assertEquals("La Bruja", b.getModel());"

Anonymous   
Printed
Page 157
2nd paragraph

"You'll then want a simple main driver to kick of loading..."
should read:
"...kick off..."

Anonymous   
Printed
Page 157
Example 9-3 caption

"RentABikeLauncher.xml"
should read:
"RentABikeLauncher.java"

Anonymous