一 代码位置
https://github.com/cakin24/spring-cloud-code/tree/master/ch12-7
二 测试认证通过
1 客户端配置
spring:
cloud:
config:
label: master
uri: http://localhost:9090
name: config-info
profile: dev
username: root
password: 123
enabled: false
endpoint: http://localhost:9090/auth
2 服务端配置
spring:
cloud:
config:
server:
git:
uri: https://gitee.com/cakin24/spring-cloud-config.git
search-paths: SC-BOOK-CONFIG
force-pull: true
application:
name: ch12-7-config-server-auth-jwt
security:
user:
name: root
password: 123
server:
port: 9090
3 启动服务端 config-server-auth-jwt
4 启动客户端 config-client-auth-jwt
5 浏览器输入 http://localhost:9014/configConsumer/getConfigInfo
三 测试认证不通过
1 客户端配置
spring:
cloud:
config:
label: master
uri: http://localhost:9090
name: config-info
profile: dev
username: root
password: 124
enabled: false
endpoint: http://localhost:9090/auth
2 启动客户端 config-client-auth-jwt
2019-11-21 19:21:51.387 INFO 21420 --- [ main] s.c.a.AnnotationConfigApplicationContext : Refreshing org.springframework.context.annotation.AnnotationConfigApplicationContext@7770f470: startup date [Thu Nov 21 19:21:51 CST 2019]; root of context hierarchy
2019-11-21 19:21:51.575 INFO 21420 --- [ main] o.s.b.f.s.DefaultListableBeanFactory : Overriding bean definition for bean 'configClientProperties' with a different definition: replacing [Root bean: class [null]; scope=; abstract=false; lazyInit=false; autowireMode=3; dependencyCheck=0; autowireCandidate=true; primary=false; factoryBeanName=configServiceBootstrapConfiguration; factoryMethodName=configClientProperties; initMethodName=null; destroyMethodName=(inferred); defined in org.springframework.cloud.config.client.ConfigServiceBootstrapConfiguration] with [Root bean: class [null]; scope=; abstract=false; lazyInit=false; autowireMode=3; dependencyCheck=0; autowireCandidate=true; primary=false; factoryBeanName=configClientBootstrapConfiguration; factoryMethodName=configClientProperties; initMethodName=null; destroyMethodName=(inferred); defined in cn.springcloud.book.config.jwt.config.ConfigClientBootstrapConfiguration]
2019-11-21 19:21:51.760 INFO 21420 --- [ main] trationDelegate$BeanPostProcessorChecker : Bean 'configurationPropertiesRebinderAutoConfiguration' of type [org.springframework.cloud.autoconfigure.ConfigurationPropertiesRebinderAutoConfiguration$$EnhancerBySpringCGLIB$$dff1a320] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
org.springframework.web.client.HttpClientErrorException: 401 null
无法启动,因为密码不匹配。