반응형
환경 - springboot 2.0 이상, 마리아DB는 버전 상관없음
해당 블로그에 자세히 나옴
결론적으로, 마리아db가 Mysql 이랑 똑같기 때문에 어렵지 않게 연결가능
아래 코드는 기존 MSsql커넥션 코드와 똑같음. rdb는 차이가 없을듯함
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
|
package io.swagger.configuration;
import javax.sql.DataSource;
import org.apache.ibatis.session.SqlSessionFactory;
import org.mybatis.spring.SqlSessionFactoryBean;
import org.mybatis.spring.SqlSessionTemplate;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.boot.jdbc.DataSourceBuilder;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.io.ClassPathResource;
import org.springframework.core.io.support.PathMatchingResourcePatternResolver;
import org.springframework.jdbc.datasource.DataSourceTransactionManager;
import org.springframework.transaction.annotation.EnableTransactionManagement;
@Configuration
@EnableTransactionManagement
public class MariaDBConfiguration {
final String mapperlocation = "classpath:mapper/*.xml";
final String packagelocation = "io.swagger.service.model";
final String mybatisconfig = "mybatis-configuration.xml";
@Bean(name="mariaContentDataSource")
@ConfigurationProperties(prefix="maria.content.datasource")
public DataSource memberDataScource() {
return DataSourceBuilder.create().build();
}
@Bean(name="mariaContentSqlSessionFactory")
public SqlSessionFactory memberSqlSessionFactory(@Qualifier("mariaContentDataSource") DataSource dataSource) throws Exception {
final SqlSessionFactoryBean sessionFactory = new SqlSessionFactoryBean();
sessionFactory.setDataSource(dataSource);
PathMatchingResourcePatternResolver resolver = new PathMatchingResourcePatternResolver();
sessionFactory.setMapperLocations(resolver.getResources(mapperlocation));
sessionFactory.setTypeAliasesPackage(packagelocation);
sessionFactory.setConfigLocation(new ClassPathResource(mybatisconfig));
return sessionFactory.getObject();
}
@Bean(name = "mariaContentSqlSessionTemplate")
public SqlSessionTemplate memberSqlSessionTemplate(@Qualifier("mariaContentSqlSessionFactory") SqlSessionFactory sqlSessionFactory) throws Exception {
final SqlSessionTemplate sqlSessionTemplate = new SqlSessionTemplate(sqlSessionFactory);
return sqlSessionTemplate;
}
@Bean(name = "mariaContentDataSourceTransactionManager")
public DataSourceTransactionManager membertransactionManager (@Qualifier("mariaContentDataSource") DataSource dataSource){
DataSourceTransactionManager transactionManager = new DataSourceTransactionManager(dataSource);
return transactionManager;
}
}
|
cs |
반응형
'DB > MYSQL MariaDB' 카테고리의 다른 글
MySQL : 원격 접속이 안될 때[출처] MySQL : 원격 접속이 안될 때 (0) | 2020.05.14 |
---|---|
mysql error - unable to bind to tcp-socket - Permission denied (0) | 2020.05.14 |
[mysql] 쿼리 조건문 if, case, ifnull (0) | 2019.09.18 |
MySQL의 IN() v.s. EXISTS v.s. INNER JOIN 성능 비교 (0) | 2018.10.23 |
Mysql에서 지원하는 데이터 암호화 기법 (0) | 2018.05.24 |
댓글