nacos-spring-boot-project
nacos-spring-boot-project copied to clipboard
server端1.2.0版本 开启身份验证 有时候报 token expired! 403拒绝访问
开发的项目springboot版本:2.1.1.RELEASE jdk版本:1.8.0_201 系统:windows 10
Service端 nacos版本:1.2.0 服务器版本说明: Linux version 3.10.0-229.el7.x86_64 ([email protected]) (gcc version 4.8.2 20140120 (Red Hat 4.8.2-16) (GCC) ) #1 SMP Fri Mar 6 11:36:42 UTC 2015
开启权限验证
nacos.core.auth.enabled=true client端 maven 版本:0.2.7 只使用配置中心 没有使用注册中心 springboot项目启动非必显错误(重要的事情说三遍,非必显) 项目中application.properties增加如下配置:
nacos.config.username=xxx nacos.config.password=xxxx
项目启动后application.properties里面配置引入的nacos配置文件能读取到,并且可以快照到本地磁盘中,使用@NacosConfigurationProperties注解引入的nacos配置 非必显报错:token expired! 使用@NacosConfigurationProperties注解引入配置的代码片段:
@Data @ToString @NacosConfigurationProperties(prefix = "ymoil", dataId = "oil-ymoil.properties",groupId = "oil",type = ConfigType.PROPERTIES, autoRefreshed = true) public class YmoilConfig {
有时候可以正常启动,快照文件也能快照到本地。 如果项目启动提示报:token expired!错误的时候,idea clean下项目,并且删除快照文件,文件路径:C:\Users\Administrator\nacos\config 通过上述操作偶尔可以解决启动报错的问题,错误日志如下: ERROR 19268 --- [ main] c.alibaba.nacos.spring.util.NacosUtils : Can't get content from dataId : oil-ymoil.properties , groupId : oil
com.alibaba.nacos.api.exception.NacosException:
Whitelabel Error Page
This application has no explicit mapping for /error, so you are seeing this as a fallback.
2020-03-28 19:58:46.906 INFO 19268 --- [ main] c.a.b.n.config.util.NacosConfigLoader : load config from nacos, data-id is : oil-ymoil.properties, group is : oil 2020-03-28 19:58:47.082 ERROR 19268 --- [ main] o.s.b.d.LoggingFailureAnalysisReporter :
APPLICATION FAILED TO START
Description:
server error: no right.
Whitelabel Error Page
This application has no explicit mapping for /error, so you are seeing this as a fallback.
Action:
please check server status
Disconnected from the target VM, address: '127.0.0.1:50832', transport: 'socket'
Process finished with exit code 1