Skip to content

Commit 940d0e4

Browse files
author
zhangtao
committed
修改了部分代码
1 parent ed277e6 commit 940d0e4

File tree

1 file changed

+43
-0
lines changed

1 file changed

+43
-0
lines changed
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
package com.xiaour.spring.boot.config;
2+
3+
import com.alibaba.druid.pool.DruidDataSource;
4+
import org.apache.ibatis.session.SqlSessionFactory;
5+
import org.mybatis.spring.SqlSessionFactoryBean;
6+
import org.springframework.beans.factory.annotation.Autowired;
7+
import org.springframework.boot.autoconfigure.jdbc.DataSourceProperties;
8+
import org.springframework.context.annotation.Bean;
9+
import org.springframework.context.annotation.Configuration;
10+
11+
12+
/**
13+
* @Date: 2018-12-26 12:05
14+
* @version: v1.0
15+
* @Description: mybatis stater从某个版本后去掉了自动配置,需要用config配置
16+
*/
17+
@Configuration
18+
public class MyBatisConfig {
19+
20+
@Autowired
21+
private DataSourceProperties dataSourceProperties;
22+
23+
24+
@Bean(name = "dataSource")
25+
public DruidDataSource dataSource() {
26+
DruidDataSource dataSource = new DruidDataSource();
27+
dataSource.setUrl(dataSourceProperties.getUrl());
28+
29+
dataSource.setDriverClassName(dataSourceProperties.getDriverClassName());
30+
dataSource.setUsername(dataSourceProperties.getUsername());
31+
dataSource.setPassword(dataSourceProperties.getPassword());
32+
33+
return dataSource;
34+
35+
}
36+
37+
@Bean
38+
public SqlSessionFactory sqlSessionFactory() throws Exception {
39+
SqlSessionFactoryBean sqlSessionFactoryBean = new SqlSessionFactoryBean();
40+
sqlSessionFactoryBean.setDataSource(dataSource());
41+
return sqlSessionFactoryBean.getObject();
42+
}
43+
}

0 commit comments

Comments
 (0)