如果我将oss的相关配置配置到nacos注册中心的时候,就会出现以下异常
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'ossClient' defined in class path resource [com/alibaba/alicloud/context/oss/OssContextAutoConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [com.aliyun.oss.OSS]: Factory method 'ossClient' threw exception; nested exception is java.lang.IllegalArgumentException: Oss endpoint can't be empty.
如果我把oss的配置写进本微服务中就不报错,并且可以正常使用,配置如下:
Application.yml:
spring:
cloud:
nacos:
discovery:
server-addr: 127.0.0.1:8848
alicloud:
access-key: LTAI4G5YSzmqTo59nmKXDJaF
secret-key: eFrGA781MwLSK5OJuISeabdvCZD1on
oss:
endpoint: oss-cn-hangzhou.aliyuncs.com
application:
name: grainmall-third-party
server:
port: 30000
Bootstrap.properties
spring.application.name=grainmall-third-party
spring.cloud.nacos.config.server-addr=127.0.0.1:8848
spring.cloud.nacos.config.namespace=e0f78c4e-fa33-4228-b5b0-d9a52d7e6598
#spring.cloud.nacos.config.ext-config[0].data-id=oss.yml
#spring.cloud.nacos.config.ext-config[0].group=DEFAULT_GROUP
#spring.cloud.nacos.config.ext-config[0].refresh=true
nacos:dataId为oss.yml,分组为默认,内容为:
spring:
cloud:
alicloud:
access-key: xxxxxxxxxxxxxxxxxxxx
secret-key: xxxxxxxxxxxxxxxxxxxx
oss:
endpoint: oss-cn-hangzhou.aliyuncs.com
花了2个小时终于解决了这个问题,
解决办法:重启nacos服务就行