开发者社区> 问答> 正文

求教Springboot+mybatis的配置 :报错

官方木有springboot+mybatis的配置

只有JPA的,JPA不想用,表关联查询太纠结。

有没有配置过springboot+mybatis的求参考。

或者如何在springboot下,添加原生的配置方法也行

在线等,求大神

展开
收起
kun坤 2020-06-14 18:16:43 614 0
1 条回答
写回答
取消 提交回答
  • http://my.oschina.net/ericliuandhisfriends/blog/468466

    小弟写的一个Demo,mybatis和Spring-Boot整合

    ######

    很简单的....

    @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();
    	}
    
    }



    ######回复 @程序员V : 你直接上github 搜索 spring boot mybatis 也是有一堆例子的.######回复 @程序员V : 不好意思..公司不能上扣扣..oschina 和github 基本是唯一能上的少数网站了...######留下QQ....详细问下。才研究Spring不久######

    ??

    mapper注入不就行了

    ######能详细点吗?
    2020-06-14 18:16:50
    赞同 展开评论 打赏
问答排行榜
最热
最新

相关电子书

更多
Java Spring Boot开发实战系列课程【第6讲】:Spring Boot 2.0实战MyBatis与优化(Java面试题) 立即下载
使用Spring.Initializr定制工程脚手架 立即下载
陈曦:使用Spring.Initializr定制工程脚手架 立即下载

相关实验场景

更多