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

这篇具有很好参考价值的文章主要介绍了解决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>

刷新依赖以后正常运行,配置也读取到了。文章来源地址https://www.toymoban.com/news/detail-795653.html

WebApplicationContext: initialization completed in 681 ms
 _ _   |_  _ _|_. ___ _ |    _ 
| | |\/|_)(_| | |_\  |_)||_|_\ 
     /               |         
                        3.3.1 
2023-08-15 10:37:50.258  WARN 28016 --- [           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-15 10:37:50.310  INFO 28016 --- [           main] o.s.b.w.embedded.tomcat.TomcatWebServer  : Tomcat started on port(s): 100 (http) with context path ''
2023-08-15 10:37:50.317  INFO 28016 --- [           main] c.a.n.p.a.s.c.ClientAuthPluginManager    : [ClientAuthPluginManager] Load ClientAuthService com.alibaba.nacos.client.auth.impl.NacosClientAuthServiceImpl success.
2023-08-15 10:37:50.318  INFO 28016 --- [           main] c.a.n.p.a.s.c.ClientAuthPluginManager    : [ClientAuthPluginManager] Load ClientAuthService com.alibaba.nacos.client.auth.ram.RamClientAuthServiceImpl success.
2023-08-15 10:37:50.445  INFO 28016 --- [           main] c.a.c.n.registry.NacosServiceRegistry    : nacos registry, DEFAULT_GROUP gulimall-coupon 192.168.79.1:100 register finished
2023-08-15 10:37:50.633  INFO 28016 --- [           main] c.a.g.coupon.GulimailCouponApplication   : Started GulimailCouponApplication in 4.133 seconds (JVM running for 4.614)
2023-08-15 10:37:50.640  INFO 28016 --- [           main] c.a.c.n.refresh.NacosContextRefresher    : [Nacos Config] Listening config: dataId=gulimall-coupon, group=dev
2023-08-15 10:37:50.642  INFO 28016 --- [           main] c.a.c.n.refresh.NacosContextRefresher    : [Nacos Config] Listening config: dataId=gulimall-coupon.properties, group=dev
2023-08-15 10:37:50.642  INFO 28016 --- [           main] c.a.c.n.refresh.NacosContextRefresher    : [Nacos Config] Listening config: dataId=other.yml, group=dev
2023-08-15 10:37:50.643  INFO 28016 --- [           main] c.a.c.n.refresh.NacosContextRefresher    : [Nacos Config] Listening config: dataId=datasource.yml, group=dev
2023-08-15 10:37:50.643  INFO 28016 --- [           main] c.a.c.n.refresh.NacosContextRefresher    : [Nacos Config] Listening config: dataId=mybatis-plus.yml, group=dev

到了这里,关于解决No spring.config.import property has been defined,学习笔记三的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处: 如若内容造成侵权/违法违规/事实不符,请点击违法举报进行投诉反馈,一经查实,立即删除!

领支付宝红包 赞助服务器费用

相关文章

觉得文章有用就打赏一下文章作者

支付宝扫一扫打赏

博客赞助

微信扫一扫打赏

请作者喝杯咖啡吧~博客赞助

支付宝扫一扫领取红包,优惠每天领

二维码1

领取红包

二维码2

领红包