File tree Expand file tree Collapse file tree 1 file changed +43
-0
lines changed
SpringBootDemo/src/main/java/com/xiaour/spring/boot/config Expand file tree Collapse file tree 1 file changed +43
-0
lines changed Original file line number Diff line number Diff line change 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+ }
You can’t perform that action at this time.
0 commit comments