1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package examples.spring;
17
18 import javax.sql.DataSource;
19
20 import org.mybatis.dynamic.sql.util.spring.NamedParameterJdbcTemplateExtensions;
21 import org.springframework.context.annotation.Bean;
22 import org.springframework.context.annotation.Configuration;
23 import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate;
24 import org.springframework.jdbc.datasource.DataSourceTransactionManager;
25 import org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseBuilder;
26 import org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseType;
27 import org.springframework.transaction.PlatformTransactionManager;
28
29 @Configuration
30 public class SpringConfiguration {
31 @Bean
32 public DataSource datasource() {
33 return new EmbeddedDatabaseBuilder()
34 .setType(EmbeddedDatabaseType.HSQL)
35 .generateUniqueName(true)
36 .addScript("classpath:/examples/simple/CreateSimpleDB.sql")
37 .build();
38 }
39
40 @Bean
41 public NamedParameterJdbcTemplate template(DataSource dataSource) {
42 return new NamedParameterJdbcTemplate(dataSource);
43 }
44
45 @Bean
46 public PlatformTransactionManager transactionManager(DataSource dataSource) {
47 return new DataSourceTransactionManager(dataSource);
48 }
49
50 @Bean
51 public NamedParameterJdbcTemplateExtensions templateExtensions(NamedParameterJdbcTemplate template) {
52 return new NamedParameterJdbcTemplateExtensions(template);
53 }
54 }