2 回答

TA貢獻(xiàn)1784條經(jīng)驗(yàn) 獲得超7個(gè)贊
在使用的時(shí)候,根據(jù)場景,需要使用 SqlSessionTemplate 默認(rèn)構(gòu)造器進(jìn)行實(shí)例化,有時(shí)候需要SqlSessionTemplate 帶參數(shù)的構(gòu)筑器進(jìn)行實(shí)例化。
你的需求應(yīng)該是在實(shí)例化 SqlSessionTemplate Bean 之前, 可以根據(jù)不同的需求來使用相應(yīng)的構(gòu)造器吧?
那么可以使用Spring Java Config 的方式來配置 Bean, 例如:
@Configuration
public class AppConfig {
@Bean
public SqlSessionTemplate sqlSessionTemplate() {
if (someCondition) {
return new SqlSessionTemplate();
} else {
return new SqlSessionTemplate(args);
}
}
}
使用 Spring Java Config , 就可以根據(jù)條件控制如何生成 Bean 的.

TA貢獻(xiàn)1862條經(jīng)驗(yàn) 獲得超6個(gè)贊
添加回答
舉報(bào)