美文网首页
springboot2.2.0升级过程

springboot2.2.0升级过程

作者: 谁在烽烟彼岸 | 来源:发表于2019-10-24 18:03 被阅读0次

项目升级,springboot由1.5升级到2.2

一、SpringBootRedis

在springboot2.0之后, springbootredis默认使用Lettuce, springbootredis1.0使用jedis
详情可见SpringBoot2.0Redis配置

netty

在升级之后redis和elastic都使用了netty,区别于之前的1.5,
1.注意版本的统一,如有问题,可添加该属性设置

System.setProperty("es.set.netty.runtime.available.processors", "false");

2.在关闭项目的时候,netty关闭将由单独的线程来完成,将晚于主线程关闭

二、SpringBootElasticsearch

在设置时要采用netty4的方式,且要注意Elasticseearch服务器是否包含netty4的插件

   public TransportClient client() {
        TransportClient client = null;
        Settings settings = Settings.builder()
                .put("cluster.name", clusterName)
                .put("transport.type", "netty4")
                .put("http.type", "netty4")
                .put("http.enabled", "true")
                .build();
        try {
               client = new PreBuiltTransportClient(settings)
                        .addTransportAddress(new TransportAddress(InetAddress.getByName(host), port));
            
            logger.info("The es client create successful" + "host = " + host + ",port = " + port);
        } catch (UnknownHostException e) {
            logger.error("The es client create failure");
            e.printStackTrace();
        }

        return client;
    }

三、SpringBootMongodb

官方文档

api的变化

1.save(List list) => saveAll(List list)
2.delete(String id) => deleteById(String id)
3.findOne(String id) => findById(String id) 返回结果由<T>转为Optional<T>

提示自动创建index将不再被推荐使用,请大家多注意

    Automatic index creation will be turned OFF by default with the release of 3.x. We recommend index creation to happen either out of band or as part of the application startup using IndexOperations.
[WARN ] o.s.d.m.c.index.MongoPersistentEntityIndexCreator - Automatic index creation will be disabled by default as of Spring Data MongoDB 3.x.
    Please use 'MongoMappingContext#setAutoIndexCreation(boolean)' or override 'MongoConfigurationSupport#autoIndexCreation()' to be explicit.
    However, we recommend setting up indices manually in an application ready block. You may use index derivation there as well.

    > -----------------------------------------------------------------------------------------
    > @EventListener(ApplicationReadyEvent.class)
    > public void initIndicesAfterStartup() {
    >
    >     IndexOperations indexOps = mongoTemplate.indexOps(DomainType.class);
    >
    >     IndexResolver resolver = new MongoPersistentEntityIndexResolver(mongoMappingContext);
    >     resolver.resolveIndexFor(DomainType.class).forEach(indexOps::ensureIndex);
    > }
    > -----------------------------------------------------------------------------------------

链接

SimpleMongoDbFactory类已经失效,被SimpleMongoClientDbFactory。

 @Bean
    public MongoDbFactory secondaryFactory() throws Exception {
        ConnectionString connectionString = new ConnectionString("mongodb://name:password@uri/database2?authSource=admin&authMechanism=SCRAM-SHA-1");
        return new SimpleMongoClientDbFactory(connectionString);
    }

对于事务的支持

@Service
public class StateService {

    @Transactional
    Mono<UpdateResult> someBusinessFunction(Step step) {                                  

        return template.insert(step)
            .then(process(step))
            .then(template.update(Step.class).apply(Update.set("state", …));
    };
})

相关文章

  • springboot2.2.0升级过程

    项目升级,springboot由1.5升级到2.2 一、SpringBootRedis 在springboot2....

  • alibaba微服务框架

    springboot2.2.0 nacos-1.2 sentinel-1.7.1 seata-1.2.0 dubb...

  • 升级过程

    说起买房,买房有一个升级的过程。就跟我们玩游戏打怪兽一样,一开始不能去打BOSS,打两下就死了。所以一开始要去打一...

  • SpringBoot 2.2和2.3异常处理的一个小变化

    先看个有意思的现象: 在springboot2.2.0的时候,浏览器访问http://localhost:8080...

  • 认知升级过程

    一直追求着思维深度,想找到那些事物的背后底层逻辑,想抓住那么一根线,那么一根可靠的线在世理中稳住脚。从道理开始到心...

  • 锁升级过程

    升级过程 无锁 偏向锁 轻量级锁 重量级锁 保证多线程环境下共享的、可修改的状态的正确性(这里的状态指的是程序...

  • 升级的过程

    会回来吗,或许不会了,那个曾经鄙视iPhone的女孩,现在也用起了iPhone,或许在大学的时光改变了你。你去了重...

  • Elasticsearch 升级记录

    前言 本文记录的是 ES 1.5.0 升级到 ES 2.3.3 的过程。包括升级要考虑的要点以及升级过程中遇到的问...

  • Elasticsearch 升级 7.x 版本后,我感觉掉坑里了

    最近想把我的mall项目升级下,支持SpringBoot 2.3.0 版本。升级过程中发现需要升级Elastics...

  • Elasticsearch 升级 7.x 版本后,我感觉掉坑里了

    最近想把我的mall项目升级下,支持SpringBoot 2.3.0 版本。升级过程中发现需要升级Elastics...

网友评论

      本文标题:springboot2.2.0升级过程

      本文链接:https://www.haomeiwen.com/subject/tcydvctx.html