springboot2.2.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", …));
    };
})
评论 5
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值