nacos升级spring cloud 2020.0无法使用bootstrap.yml的问题

之前用spring cloud整合nacos,需要一个bootstrap.yml作为spring启动的初始化配置
bootstrap.yml内容大概如下:

spring:
  application:
    # 应用名称
    name: xxx
  profiles:
    active: dev
  cloud:
    nacos:
      config:
        file-extension: yml
        server-addr: localhost:8848
        username: nacos
        password: nacos

把spring cloud升级到2020.0.x以后,nacos就读不到bootstrap.yml了
spring官方其实在change note中说明了,在新版中将spring.cloud.bootstrap.enabled默认设置为false不启用:
https://github.com/spring-cloud/spring-cloud-release/wiki/Spring-Cloud-2020.0-Release-Notes#breaking-changes
源码部分如下:

/*
 * Copyright 2013-2020 the original author or authors.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      https://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package org.springframework.cloud.util;

import org.springframework.core.env.Environment;
import org.springframework.util.ClassUtils;

public abstract class PropertyUtils {

	/**
	 * Property name for checking if bootstrap is enabled.
	 */
	public static final String BOOTSTRAP_ENABLED_PROPERTY = "spring.cloud.bootstrap.enabled";

	/**
	 * Property name for spring boot legacy processing.
	 */
	public static final String USE_LEGACY_PROCESSING_PROPERTY = "spring.config.use-legacy-processing";

	/**
	 * Property name for bootstrap marker class name.
	 */
	public static final String MARKER_CLASS = "org.springframework.cloud.bootstrap.marker.Marker";

	/**
	 * Boolean if bootstrap marker class exists.
	 */
	public static final boolean MARKER_CLASS_EXISTS = ClassUtils.isPresent(MARKER_CLASS, null);

	private PropertyUtils() {
		throw new UnsupportedOperationException("unable to instatiate utils class");
	}

	/**
	 * 判断是否启用bootstrap.yml的时候默认设置成了false
	 */
	public static boolean bootstrapEnabled(Environment environment) {
		return environment.getProperty(BOOTSTRAP_ENABLED_PROPERTY, Boolean.class, false) || MARKER_CLASS_EXISTS;
	}

	public static boolean useLegacyProcessing(Environment environment) {
		return environment.getProperty(USE_LEGACY_PROCESSING_PROPERTY, Boolean.class, false);
	}

}

解决方案是在vm启动参数中增加-Dspring.cloud.bootstrap.enabled=true,或者增加spring-cloud-starter-bootstrap依赖,至于spring cloud alibaba nacos后续是否能支持application.yml,目前alibaba官方还没有回复

评论 8
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Wheat_Liu

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值