Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SqlHelper.sqlSessionFactory(Class<?> clazz)的替代方案 #5950

Open
hieastz opened this issue Jan 31, 2024 · 3 comments
Open

SqlHelper.sqlSessionFactory(Class<?> clazz)的替代方案 #5950

hieastz opened this issue Jan 31, 2024 · 3 comments

Comments

@hieastz
Copy link

hieastz commented Jan 31, 2024

当前使用版本(必填,否则不予处理)

3.5.5

该问题是如何引起的?(确定最新版也有问题再提!!!)

升级到最新版本3.5.5,该方法被废弃。需要官方提供替代方案。

因项目中需要,封装了批量执行方法,老版本一直使用SqlHelper.sqlSessionFactory(Class<?> clazz),根据实体获取sqlSessionFactory,运行良好。新版本被标记为废弃,但没有提供替代方案。 模拟的serviceImpl的批量方案,入参没有mapper,需要提供根据实体获取sqlSessionFactory的方法。

重现步骤(如果有就写完整)

升级到最新版本3.5.5,该方法被废弃

报错信息

升级到最新版本3.5.5,该方法被废弃,需求提供替代方案。

@initchen
Copy link

initchen commented Feb 4, 2024

有个SqlHelper.execute方法

@hieastz
Copy link
Author

hieastz commented Feb 4, 2024

有个SqlHelper.execute方法

这个里面也是使用的过时方法

@keithJackTjk
Copy link

@configuration
@MapperScan("com.example.mapper") // 扫描 Mapper 接口所在的包
public class MyBatisConfig {

@Bean
public SqlSessionFactory sqlSessionFactory(DataSource dataSource) throws Exception {
    SqlSessionFactoryBean sessionFactory = new SqlSessionFactoryBean();
    sessionFactory.setDataSource(dataSource);

    // 设置 MyBatis 配置文件路径,可以是 classpath 下的路径或者绝对路径
    sessionFactory.setConfigLocation(new ClassPathResource("mybatis-config.xml"));

    return sessionFactory.getObject();
}

}
你可以直接在代码中通过 @Autowired 或者 @resource 注解来引用 SqlSessionFactory 对象。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants