关于springboot中对sqlSessionFactoryBean的自定义

网友投稿 829 2022-11-14

关于springboot中对sqlSessionFactoryBean的自定义

关于springboot中对sqlSessionFactoryBean的自定义

目录springboot sqlSessionFactoryBean自定义代码如下以上配置也可以通过properties文件配置springboot启动报找不到sqlSessionFactory

springboot sqlSessionFactoryBean自定义

1.新建一个配置类,加上configuration注解

2.定制化SqlSessionFactoryBean,然后交给容器管理

代码如下

@Configuration

public class MybatisConfig {

@Value("${mybatis.mapper-locations}")

private String mapperLocations;

@Bean

public SqlSessionFactoryBean configSqlSessionFactoryBean(DataSource dataSource) throws IOException {

SqlSessionFactoryBean sqlSessionFactoryBean = new SqlSessionFactoryBean();

org.apache.ibatis.session.Configuration configuration = new org.apache.ibatis.session.Configuration();

// configuration.setLogImpl(StdOutImpl.class);//标准输出日志

http:// configuration.setLogImpl(NoLoggingImpl.class);// 不输出日志()

configuration.setMapUnderscoreToCamelCase(true);// 开启驼峰命名

configuration.setCallSettersOnNulls(true);// 开启在属性为null也调用setter方法

sqlSessionFactoryBean.setConfiguration(configuration);

sqlSessionFactoryBean.setDataSource(dataSource);

ResourcePatternResolver resolver = new PathMatchingResourcePatternResolver();

sqlSessionFactoryBean.setMapperLocations(resolver.getResources(mapperLocations));// 设置mapper文件扫描路径

return sqlSessionFactoryBean;

}

以上配置也可以通过properties文件配置

如:

mybatis.mapper-locations=classpath:mapper/*.xml

mybatis.configuration.log-impl=org.apache.ibatis.logging.stdout.StdOutImpl

mybatis.configuration.mapUnderscoreToCamelCase=true

mybatis.configuration.call-setters-on-nulls=true

springboot启动报找不到sqlSessionFactory

GDSoVCaused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name ‘sqlSessionFactory' defined in class path resource [com/baomidou/mybatisplus/spring/boot/starter/MybatisPlusAutoConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.apache.ibatis.session.SqlSessionFactory]: Factory method ‘sqlSessionFactory' threw exception; nested exception is com.baomidou.mybatisplus.exceptions.MybatisPlusException: Error: GlobalConfigUtils setMetaData Fail ! Cause:java.sql.SQLException: oracle.jdbc.OracleDriver

原因是这个电脑 ,这个项目第一次启动,项目链接的是Oracle的数据GDSoV库,Oracle没把自己jar包放在maven库,要自己安装

在maven仓库目录下 放置Oracle的jar包

再在cmd中切换到 这个目录下运行命令:

mvn install:install-file -DgroupId=cGDSoVom.oracle -DartifactId=ojdbc14 -Dversion=10.2.0.4.0 -Dpackaging=jar -Dfile=ojdbc14.jar

版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。

上一篇:小程序和小程序之间的跳转,小程序如何跳转到其他小程序
下一篇:我的7年工控生涯
相关文章

 发表评论

暂时没有评论,来抢沙发吧~