Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.
In case you prefer using the Java configuration class instead of the XML configuration, Listing 8-56 shows the Spring configuration class.
Listing 8-56. Using the Java Configuration
package com.apress.prospring3.ch8.javaconfig;
import javax.sql.DataSource;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.jdbc.datasource.embedded.EmbeddedDatabase;
import org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseBuilder;
import org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseType;
@Configuration
@ComponentScan(basePackages="com.apress.prospring3.ch8.dao.jdbc.annotation")
public class AppConfig {
@Bean
public DataSource dataSource() {
EmbeddedDatabaseBuilder builder = new EmbeddedDatabaseBuilder();
EmbeddedDatabase db = builder.setType(EmbeddedDatabaseType.H2).
addScript("schema.sql").
addScript("test-data.sql").build();
return db;
}
}