MybatisConfig类中配置了sqlSessionFactoryBean, MybatisMapperScannerConfig类中配置了MapperScannConfigure ,注解也加了AutoConfigureAfter(MybatisConfig.class),但是debug的时候还是一直先执行MybatisMapperScannerConfig,求大神指教?
你看看MapperScannerConfigurer继承和实现类就知道了,你在用注解时是无效的,但这个在使用xml配置时就有的问题,MapperScannerConfigurerConfig内不能@Value等注解,会无法注入。不要配置sqlSessionFactory,应使用sqlSessionFactoryName######MapperScannerConfigurer有两个属性,sqlSessionFactory和sqlSessionFactoryName######回复 @youngkun : 我原来SSM项目用的就是sqlSessionFactory,你说的sqlSessionFactoryName这个是什么东西,怎么配置呢?######可以啊,就这种配置就可以啊######我网上查了很多资料都是利用这种方法,不想使用引用mybatis.xml的方法,难道这种方法不行了?###### pom.xml
<dependency> <groupId>org.mybatis.spring.boot</groupId> <artifactId>mybatis-spring-boot-starter</artifactId> </dependency>applicationyml
#mybaits mybatis: mapper-locations: classpath:cn/aaa/member/dao/**/*.xml type-aliases-package: cn.aaa.common config-location: classpath:mybatis-config.xmlmybatis-config.xml 这个就不用提供了吧######回复 @菜鸡一枚 : 那你关注一下 MybatisAutoConfiguration.class spring-boot 有关于这个累的使用~######我知道这种方法 的,我是想用纯的java方式,不想引用mybatis-config.xml######<!-- 配置依赖关系 --> <dependencies> <!-- 配置Web启动器 --> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency> <!-- 配置启动热部署 --> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-devtools</artifactId> </dependency> <!-- 配置mybatis启动器 --> <dependency> <groupId>org.mybatis.spring.boot</groupId> <artifactId>mybatis-spring-boot-starter</artifactId> <version>1.3.0</version> </dependency> <!-- 配置mysql驱动 --> <dependency> <groupId>mysql</groupId> <artifactId>mysql-connector-java</artifactId> </dependency> <!-- 配置c3p0 --> <dependency> <groupId>com.mchange</groupId> <artifactId>c3p0</artifactId> <version>0.9.5.2</version> </dependency> <!-- 配置tomcat启动器(由于我们用自己的tomcat所以不需要内嵌tomcat) --> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-tomcat</artifactId> <scope>provided</scope> </dependency> </dependencies>######类配置的方式,我到是配置成功了,但问题是MapperScannConfigure 依然优先执行,但是没报错,也能正常运行,没懂...你知道为啥不报错不?
版权声明:本文内容由阿里云实名注册用户自发贡献,版权归原作者所有,阿里云开发者社区不拥有其著作权,亦不承担相应法律责任。具体规则请查看《阿里云开发者社区用户服务协议》和《阿里云开发者社区知识产权保护指引》。如果您发现本社区中有涉嫌抄袭的内容,填写侵权投诉表单进行举报,一经查实,本社区将立刻删除涉嫌侵权内容。