Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
316 views
in Technique[技术] by (71.8m points)

java - Java类扩展了@Configuration注释的Spring Bean(Java Class extends @Configuration annotated Spring Bean)

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
等待大神答复

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

2.1m questions

2.1m answers

60 comments

57.0k users

...