When using it, depending on the scenario, you need to use the SqlSessionTemplate default constructor for instantiation. Sometimes you need the SqlSessionTemplate constructor with parameters for instantiation.
Your requirement should be that before instantiating the SqlSessionTemplate Bean, you can use the corresponding constructor according to different needs? Then you can use Spring Java Config to configure the Bean, for example:
@Configuration
public class AppConfig {
@Bean
public SqlSessionTemplate sqlSessionTemplate() {
if (someCondition) {
return new SqlSessionTemplate();
} else {
return new SqlSessionTemplate(args);
}
}
}
Using Spring Java Config, you can control how to generate beans based on conditions.
I think you can write multiple inheritancesSqlSessionTemplate的类,然后用@Component("Your_Bean_Name")来指定不同实现的Bean名称,最后在注入的地方用@Qulifiler("The_Bean_Name") to specify the beans to be injected!
Your requirement should be that before instantiating the SqlSessionTemplate Bean, you can use the corresponding constructor according to different needs?
Then you can use Spring Java Config to configure the Bean, for example:
Using Spring Java Config, you can control how to generate beans based on conditions.
I think you can write multiple inheritances
SqlSessionTemplate
的类,然后用@Component("Your_Bean_Name")
来指定不同实现的Bean名称,最后在注入的地方用@Qulifiler("The_Bean_Name")
to specify the beans to be injected!