View Javadoc
1   /*
2    *    Copyright 2016-2025 the original author or authors.
3    *
4    *    Licensed under the Apache License, Version 2.0 (the "License");
5    *    you may not use this file except in compliance with the License.
6    *    You may obtain a copy of the License at
7    *
8    *       https://www.apache.org/licenses/LICENSE-2.0
9    *
10   *    Unless required by applicable law or agreed to in writing, software
11   *    distributed under the License is distributed on an "AS IS" BASIS,
12   *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   *    See the License for the specific language governing permissions and
14   *    limitations under the License.
15   */
16  package examples.column.comparison;
17  
18  import javax.sql.DataSource;
19  
20  import org.apache.ibatis.session.SqlSessionFactory;
21  import org.mybatis.spring.SqlSessionFactoryBean;
22  import org.mybatis.spring.annotation.MapperScan;
23  import org.springframework.context.annotation.Bean;
24  import org.springframework.context.annotation.Configuration;
25  import org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseBuilder;
26  import org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseType;
27  
28  @Configuration
29  @MapperScan("examples.column.comparison")
30  public class ColumnComparisonConfiguration {
31      @Bean
32      public DataSource datasource() {
33          return new EmbeddedDatabaseBuilder()
34                  .setType(EmbeddedDatabaseType.HSQL)
35                  .generateUniqueName(true)
36                  .addScript("classpath:/examples/column/comparison/CreateDB.sql")
37                  .build();
38      }
39  
40      @Bean
41      public SqlSessionFactory sqlSessionFactory(DataSource dataSource) throws Exception {
42          SqlSessionFactoryBean factoryBean = new SqlSessionFactoryBean();
43          factoryBean.setDataSource(dataSource);
44          return factoryBean.getObject();
45      }
46  }