spring boot mybatis 能同时用注解或配置吗
发布网友
发布时间:2022-04-20 00:37
我来回答
共1个回答
热心网友
时间:2023-09-09 05:18
@Configuration
@EnableTransactionManagement
@MapperScan("com.*.*.mapper")
public class DataBaseConfig {
private final Logger log = LoggerFactory.getLogger(DataBaseConfig.class);
@Bean
@Primary
@ConfigurationProperties(prefix = "datasource.primary")
public DataSource dataSource() {
log.debug("Configuring Datasource");
return new DruidDataSource();
}
@Bean
public PlatformTransactionManager txManager() {
return new DataSourceTransactionManager(dataSource());
}
@Bean
public SqlSessionFactory sqlSessionFactoryBean() throws Exception {
SqlSessionFactoryBean sqlSessionFactoryBean = new SqlSessionFactoryBean();
sqlSessionFactoryBean.setDataSource(dataSource());
PathMatchingResourcePatternResolver resolver = new PathMatchingResourcePatternResolver();
sqlSessionFactoryBean.setMapperLocations(resolver
.getResources("classpath:/mapper/*.xml"));
return sqlSessionFactoryBean.getObject();
26
27
28
29
30
31
32
33
34
,