I wrote the follow piece of code and It works but i'm not sure why.
(我写了下面的代码,它可以工作,但是我不确定为什么。)
What I wanted is to customize the jdbc configuration of spring-data-jdbc and I extended the configuration with another, what really happen in the IoC Container? (我想要的是自定义spring-data-jdbc的jdbc配置,然后用另一个扩展配置,在IoC容器中到底发生了什么?)
JdbcConfiguration
is @Configuration
annotated bean that instantiates a JdbcCustomConversions
and i'm able to override this behavior subclassing the whole configuration and specifying ma own method, but i'm not really sure why.
(JdbcConfiguration
是@Configuration
注释的Bean,它实例化了JdbcCustomConversions
,我可以重写此行为,将整个配置子类化,并指定自己的方法,但我不确定为什么。)
@Configuration
public class CustomJdbcConfiguration extends JdbcConfiguration{
@Override
protected JdbcCustomConversions jdbcCustomConversions() {
return new JdbcCustomConversions(Collections.singletonList(CLobToStringConverter.INSTANCE));
}
@ReadingConverter
enum CLobToStringConverter implements Converter<Clob, String>{
INSTANCE;
@Override
public String convert(Clob source) {
try {
return IOUtils.toString(source.getCharacterStream());
} catch (IOException | SQLException e) {
throw new RuntimeException(e);
}
}
}
}
ask by Griso translate from so 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…