| | |
| | | import org.mybatis.spring.annotation.MapperScan; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.boot.autoconfigure.jdbc.DataSourceProperties; |
| | | import org.springframework.boot.context.properties.ConfigurationProperties; |
| | | import org.springframework.context.annotation.Bean; |
| | | import org.springframework.context.annotation.Configuration; |
| | | |
| | |
| | | return interceptor; |
| | | } |
| | | |
| | | @Resource |
| | | private DataSourceProperties dataSourceProperties; |
| | | |
| | | |
| | | @ConfigurationProperties(prefix="spring.datasource.dynamic.datasource.hangzhoumes") |
| | | @Bean(name = "dataSource") |
| | | public DataSource dataSource() { |
| | | |
| | | DruidDataSource dataSource = new DruidDataSource(); |
| | | dataSource.setUrl(dataSourceProperties.getUrl()); |
| | | dataSource.setDriverClassName(dataSourceProperties.getDriverClassName()); |
| | | dataSource.setUsername(dataSourceProperties.getUsername()); |
| | | dataSource.setPassword(dataSourceProperties.getPassword()); |
| | | |
| | | return dataSource; |
| | | |
| | | } |
| | | |
| | | public SqlSessionFactory sqlSessionFactory() throws Exception { |
| | | SqlSessionFactoryBean sqlSessionFactoryBean = new SqlSessionFactoryBean(); |
| | | sqlSessionFactoryBean.setDataSource(dataSource()); |
| | | return sqlSessionFactoryBean.getObject(); |
| | | } |
| | | |
| | | } |