spring boot mybatis 能同时用注解或配置吗
展开全部
@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
,
@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
,
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询