解决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.***/

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

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

WebApplicationContext: initialization ***pleted 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 re***mended 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 ***.alibaba.nacos.client.auth.impl.NacosClientAuthServiceImpl su***ess.
2023-08-15 10:37:50.318  INFO 28016 --- [           main] c.a.n.p.a.s.c.ClientAuthPluginManager    : [ClientAuthPluginManager] Load ClientAuthService ***.alibaba.nacos.client.auth.ram.RamClientAuthServiceImpl su***ess.
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

转载请说明出处内容投诉
CSS教程_站长资源网 » 解决No spring.config.import property has been defined,学习笔记三

发表评论

欢迎 访客 发表评论

一个令你着迷的主题!

查看演示 官网购买