0


解决No spring.config.import property has been defined,学习笔记三

解决No spring.config.import property has been defined

在学习Nacos组件,加载多配置集时遇到问题,希望微服务在读取配置文件之前先去nacos中读取配置文件优先于本地配置。配置了

bootstrap.properties

后启动项目报错:

Description:

No spring.config.import property has been defined

Action:

Add a spring.config.import=nacos: property to your configuration.
    If configuration is not required add spring.config.import=optional:nacos: instead.
    To disable this check,set spring.cloud.nacos.config.import-check.enabled=false.

Process finished with exit code 1

后续找解决方案发现是因为在springcloud 2020.0.2版本中把bootstrap的相关依赖从spring-cloud-starter-config中移除了,所以现在在2020.02 以后需要单独引入spring-cloud-starter-bootstrap 依赖。版本对应网站:https://mvnrepository.com/

<dependency><groupId>org.springframework.cloud</groupId><artifactId>spring-cloud-starter-bootstrap</artifactId><version>3.0.3</version></dependency>

刷新依赖以后正常运行,配置也读取到了。

WebApplicationContext: initialization completed in681 ms
 _ _   |_  _ _|_. ___ _ |    _ 
|||\/|_)(_|||_\  |_)||_|_\ 
     /|3.3.12023-08-1510:37:50.258WARN28016---[           main] iguration$LoadBalancerCaffeineWarnLogger : Spring Cloud LoadBalancer is currently working with the default cache. While this cache implementation is useful for development and tests, it's recommended to use Caffeine cache in production.You can switch to using Caffeine cache, by adding it and org.springframework.cache.caffeine.CaffeineCacheManager to the classpath.2023-08-1510:37:50.310INFO28016---[           main] o.s.b.w.embedded.tomcat.TomcatWebServer  : Tomcat started on port(s):100(http)with context path ''2023-08-1510:37:50.317INFO28016---[           main] c.a.n.p.a.s.c.ClientAuthPluginManager    :[ClientAuthPluginManager] Load ClientAuthService com.alibaba.nacos.client.auth.impl.NacosClientAuthServiceImpl success.2023-08-1510:37:50.318INFO28016---[           main] c.a.n.p.a.s.c.ClientAuthPluginManager    :[ClientAuthPluginManager] Load ClientAuthService com.alibaba.nacos.client.auth.ram.RamClientAuthServiceImpl success.2023-08-1510:37:50.445INFO28016---[           main] c.a.c.n.registry.NacosServiceRegistry    : nacos registry,DEFAULT_GROUP gulimall-coupon 192.168.79.1:100 register finished
2023-08-1510:37:50.633INFO28016---[           main] c.a.g.coupon.GulimailCouponApplication   : Started GulimailCouponApplication in4.133seconds(JVM running for4.614)2023-08-1510:37:50.640INFO28016---[           main] c.a.c.n.refresh.NacosContextRefresher    :[Nacos Config] Listening config: dataId=gulimall-coupon, group=dev
2023-08-1510:37:50.642INFO28016---[           main] c.a.c.n.refresh.NacosContextRefresher    :[Nacos Config] Listening config: dataId=gulimall-coupon.properties, group=dev
2023-08-1510:37:50.642INFO28016---[           main] c.a.c.n.refresh.NacosContextRefresher    :[Nacos Config] Listening config: dataId=other.yml, group=dev
2023-08-1510:37:50.643INFO28016---[           main] c.a.c.n.refresh.NacosContextRefresher    :[Nacos Config] Listening config: dataId=datasource.yml, group=dev
2023-08-1510:37:50.643INFO28016---[           main] c.a.c.n.refresh.NacosContextRefresher    :[Nacos Config] Listening config: dataId=mybatis-plus.yml, group=dev
标签: spring 学习 笔记

本文转载自: https://blog.csdn.net/cyue07/article/details/132293652
版权归原作者 佚名菌 所有, 如有侵权,请联系我们删除。

“解决No spring.config.import property has been defined,学习笔记三”的评论:

还没有评论