GenericScope.java 文件源码

java
阅读 29 收藏 0 点赞 0 评论 0

项目:configx 作者:
/**
 * If the bean factory is a DefaultListableBeanFactory then it can serialize scoped
 * beans and deserialize them in another context (even in another JVM), as long as the
 * ids of the bean factories match. This method sets up the serialization id to be
 * either the id provided to the scope instance, or if that is null, a hash of all the
 * bean names.
 *
 * @param beanFactory the bean factory to configure
 */
private void setSerializationId(ConfigurableListableBeanFactory beanFactory) {

    if (beanFactory instanceof DefaultListableBeanFactory) {

        String id = this.id;
        if (id == null) {
            List<String> list = new ArrayList<>(
                    Arrays.asList(beanFactory.getBeanDefinitionNames()));
            Collections.sort(list);
            String names = list.toString();
            logger.debug("Generating bean factory id from names: " + names);
            id = UUID.nameUUIDFromBytes(names.getBytes()).toString();
        }

        logger.info("BeanFactory id=" + id);
        ((DefaultListableBeanFactory) beanFactory).setSerializationId(id);

    } else {
        logger.warn("BeanFactory was not a DefaultListableBeanFactory, so RefreshScope beans "
                + "cannot be serialized reliably and passed to a remote JVM.");
    }

}
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号