Skip to content
This repository has been archived by the owner on Apr 16, 2024. It is now read-only.

Commit

Permalink
[ch07] Use @import annotation.
Browse files Browse the repository at this point in the history
  • Loading branch information
dhsim86 authored and Dongho Sim committed Oct 28, 2017
1 parent 56c983b commit 21679a2
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 37 deletions.
39 changes: 2 additions & 37 deletions src/main/java/com/AppContext.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,26 +6,20 @@
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;
import org.springframework.jdbc.datasource.DataSourceTransactionManager;
import org.springframework.jdbc.datasource.SimpleDriverDataSource;
import org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseBuilder;
import org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseType;
import org.springframework.oxm.Unmarshaller;
import org.springframework.oxm.jaxb.Jaxb2Marshaller;
import org.springframework.transaction.PlatformTransactionManager;
import org.springframework.transaction.annotation.EnableTransactionManagement;

import com.mysql.jdbc.Driver;

import ch01.springbook.user.dao.UserDao;
import ch07.springbook.sql.OxmSqlService;
import ch07.springbook.sql.SqlService;
import ch07.springbook.sql.registry.EmbeddedDbSqlRegistry;
import ch07.springbook.sql.registry.SqlRegistry;

@Configuration
@EnableTransactionManagement
@ComponentScan(basePackages = "ch01")
@Import(SqlServiceContext.class)
public class AppContext {

@Autowired
Expand All @@ -48,33 +42,4 @@ public PlatformTransactionManager transactionManager() {
transactionManager.setDataSource(dataSource());
return transactionManager;
}

@Bean
public SqlService sqlService() {
OxmSqlService oxmSqlService = new OxmSqlService();
oxmSqlService.setUnmarshaller(unmarshaller());
oxmSqlService.setSqlRegistry(sqlRegistry());
return oxmSqlService;
}

@Bean
public Unmarshaller unmarshaller() {
Jaxb2Marshaller jaxb2Marshaller = new Jaxb2Marshaller();
jaxb2Marshaller.setContextPath("ch07.springbook.sql.reader.jaxb");
return jaxb2Marshaller;
}

@Bean
public SqlRegistry sqlRegistry() {
EmbeddedDbSqlRegistry embeddedDbSqlRegistry = new EmbeddedDbSqlRegistry();
embeddedDbSqlRegistry.setDataSource(embeddedDatabase());
return embeddedDbSqlRegistry;
}

@Bean
public DataSource embeddedDatabase() {
return new EmbeddedDatabaseBuilder().setType(EmbeddedDatabaseType.HSQL)
.addScript("classpath:sql/embedded/schema.sql")
.build();
}
}
47 changes: 47 additions & 0 deletions src/main/java/com/SqlServiceContext.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package com;

import javax.sql.DataSource;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseBuilder;
import org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseType;
import org.springframework.oxm.Unmarshaller;
import org.springframework.oxm.jaxb.Jaxb2Marshaller;

import ch07.springbook.sql.OxmSqlService;
import ch07.springbook.sql.SqlService;
import ch07.springbook.sql.registry.EmbeddedDbSqlRegistry;
import ch07.springbook.sql.registry.SqlRegistry;

@Configuration
public class SqlServiceContext {
@Bean
public SqlService sqlService() {
OxmSqlService oxmSqlService = new OxmSqlService();
oxmSqlService.setUnmarshaller(unmarshaller());
oxmSqlService.setSqlRegistry(sqlRegistry());
return oxmSqlService;
}

@Bean
public Unmarshaller unmarshaller() {
Jaxb2Marshaller jaxb2Marshaller = new Jaxb2Marshaller();
jaxb2Marshaller.setContextPath("ch07.springbook.sql.reader.jaxb");
return jaxb2Marshaller;
}

@Bean
public SqlRegistry sqlRegistry() {
EmbeddedDbSqlRegistry embeddedDbSqlRegistry = new EmbeddedDbSqlRegistry();
embeddedDbSqlRegistry.setDataSource(embeddedDatabase());
return embeddedDbSqlRegistry;
}

@Bean
public DataSource embeddedDatabase() {
return new EmbeddedDatabaseBuilder().setType(EmbeddedDatabaseType.HSQL)
.addScript("classpath:sql/embedded/schema.sql")
.build();
}
}

0 comments on commit 21679a2

Please sign in to comment.