当前位置:   article > 正文

java.lang.IllegalStateException: Cannot decrypt: key=spring.datasource.password

java.lang.illegalstateexception: cannot decrypt: key=

问题描述:

Spring Cloud Config Client 客户端服务启动报错,如下所示:

  1. 2020-04-25 10:10:22.089 INFO 4028 --- [ main] s.c.a.AnnotationConfigApplicationContext : Refreshing org.springframework.context.annotation.AnnotationConfigApplicationContext@26275bef: startup date [Sat Apr 25 10:10:22 CST 2020]; root of context hierarchy
  2. 2020-04-25 10:10:22.330 INFO 4028 --- [ main] trationDelegate$BeanPostProcessorChecker : Bean 'configurationPropertiesRebinderAutoConfiguration' of type [class org.springframework.cloud.autoconfigure.ConfigurationPropertiesRebinderAutoConfiguration$$EnhancerBySpringCGLIB$$ec992a79] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
  3. . ____ _ __ _ _
  4. /\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \
  5. ( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
  6. \\/ ___)| |_)| | | | | || (_| | ) ) ) )
  7. ' |____| .__|_| |_|_| |_\__, | / / / /
  8. =========|_|==============|___/=/_/_/_/
  9. :: Spring Boot :: (v1.4.4.RELEASE)
  10. 2020-04-25 10:10:23.854 INFO 4028 --- [ main] c.c.c.ConfigServicePropertySourceLocator : Fetching config from server at: http://localhost:8888
  11. 2020-04-25 10:10:33.699 INFO 4028 --- [ main] c.c.c.ConfigServicePropertySourceLocator : Located environment: name=licensingservice, profiles=[default], label=master, version=56d63a8c0c3dcb0c5c93db1f00cf71856371db8b, state=null
  12. 2020-04-25 10:10:33.699 INFO 4028 --- [ main] b.c.PropertySourceBootstrapConfiguration : Located property source: CompositePropertySource [name='configService', propertySources=[MapPropertySource [name='configClient'], MapPropertySource [name='https://github.com/carnellj/config-repo/licensingservice/licensingservice.yml']]]
  13. 2020-04-25 10:10:33.711 WARN 4028 --- [ main] o.s.boot.SpringApplication : Error handling failed (ApplicationEventMulticaster not initialized - call 'refresh' before multicasting events via the context: org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext@4bff64c2: startup date [Thu Jan 01 08:00:00 CST 1970]; parent: org.springframework.context.annotation.AnnotationConfigApplicationContext@26275bef)
  14. 2020-04-25 10:10:33.711 ERROR 4028 --- [ main] o.s.boot.SpringApplication : Application startup failed
  15. java.lang.IllegalStateException: Cannot decrypt: key=spring.datasource.password
  16. at org.springframework.cloud.bootstrap.encrypt.EnvironmentDecryptApplicationInitializer.decrypt(EnvironmentDecryptApplicationInitializer.java:201) ~[spring-cloud-context-1.1.7.RELEASE.jar:1.1.7.RELEASE]
  17. at org.springframework.cloud.bootstrap.encrypt.EnvironmentDecryptApplicationInitializer.decrypt(EnvironmentDecryptApplicationInitializer.java:165) ~[spring-cloud-context-1.1.7.RELEASE.jar:1.1.7.RELEASE]
  18. at org.springframework.cloud.bootstrap.encrypt.EnvironmentDecryptApplicationInitializer.initialize(EnvironmentDecryptApplicationInitializer.java:95) ~[spring-cloud-context-1.1.7.RELEASE.jar:1.1.7.RELEASE]
  19. at org.springframework.boot.SpringApplication.applyInitializers(SpringApplication.java:636) [spring-boot-1.4.4.RELEASE.jar:1.4.4.RELEASE]
  20. at org.springframework.boot.SpringApplication.prepareContext(SpringApplication.java:350) [spring-boot-1.4.4.RELEASE.jar:1.4.4.RELEASE]
  21. at org.springframework.boot.SpringApplication.run(SpringApplication.java:314) [spring-boot-1.4.4.RELEASE.jar:1.4.4.RELEASE]
  22. at org.springframework.boot.SpringApplication.run(SpringApplication.java:1187) [spring-boot-1.4.4.RELEASE.jar:1.4.4.RELEASE]
  23. at org.springframework.boot.SpringApplication.run(SpringApplication.java:1176) [spring-boot-1.4.4.RELEASE.jar:1.4.4.RELEASE]
  24. at com.thoughtmechanix.licenses.Application.main(Application.java:12) [classes/:na]
  25. Caused by: java.lang.UnsupportedOperationException: No decryption for FailsafeTextEncryptor. Did you configure the keystore correctly?
  26. at org.springframework.cloud.bootstrap.encrypt.EncryptionBootstrapConfiguration$FailsafeTextEncryptor.decrypt(EncryptionBootstrapConfiguration.java:152) ~[spring-cloud-context-1.1.7.RELEASE.jar:1.1.7.RELEASE]
  27. at org.springframework.cloud.bootstrap.encrypt.EnvironmentDecryptApplicationInitializer.decrypt(EnvironmentDecryptApplicationInitializer.java:193) ~[spring-cloud-context-1.1.7.RELEASE.jar:1.1.7.RELEASE]
  28. ... 8 common frames omitted

解决办法:

1、在本地安装Postgres数据库;

2、修改Spring Cloud Config Server 服务端 Postgres数据库连接配置文件licensingservice-dev.yml,如下所示:

  1. spring.jpa.database: "POSTGRESQL"
  2. spring.datasource.platform: "postgres"
  3. spring.jpa.show-sql: "false"
  4. spring.database.driverClassName: "org.postgresql.Driver"
  5. # spring.datasource.url: "jdbc:postgresql://database:5432/eagle_eye_dev"
  6. spring.datasource.url: "jdbc:postgresql://localhost:5432/eagle_eye_dev"
  7. # spring.datasource.username: "postgres_dev"
  8. spring.datasource.username: "postgres"
  9. # spring.datasource.password: "{cipher}d495ce8603af958b2526967648aa9620b7e834c4eaff66014aa805450736e119"
  10. spring.datasource.password: "{cipher}2c644c00b51dbdd03116edd77be62774fc94b3c646f1c553015102680e1d1868"
  11. spring.datasource.testWhileIdle: "true"
  12. spring.datasource.validationQuery: "SELECT 1"
  13. spring.jpa.properties.hibernate.dialect: "org.hibernate.dialect.PostgreSQLDialect"
  14. redis.server: "redis"
  15. redis.port: "6379"
  16. signing.key: "345345fsdfsf5345"

3、修改Spring Cloud Config Server 服务端属性配置文件application.yml,如下所示:

  1. #
  2. # This is the core configuration for a configuration service. I have two examples here:
  3. #
  4. # - A configuration service which completelty loads the configuration for the services
  5. # from the local file server of the config service. This should only be used for
  6. # demonstration purposes or for a small application with a limited number of services.
  7. #
  8. # - A configuraton service that uses a git-based repository to read the files from
  9. #
  10. ####################################
  11. # server:
  12. # port: 8888
  13. # spring:
  14. # cloud:
  15. # config:
  16. # server:
  17. # encrypt.enabled: false
  18. # git:
  19. # uri: https://github.com/carnellj/config-repo/
  20. # searchPaths: licensingservice,organizationservice
  21. # username: native-cloud-apps
  22. # password: 0ffended
  23. ####
  24. #Classpath and file-based solution
  25. ####
  26. server:
  27. port: 8888
  28. spring:
  29. profiles:
  30. active: native
  31. cloud:
  32. config:
  33. server:
  34. encrypt:
  35. enabled: false
  36. native:
  37. # searchLocations: file://<chapter 3>/confsvr/src/main/resources/config/licensingservice,
  38. # file://<chapter 3>confsvr/src/main/resources/config/organizationservice
  39. searchLocations: classpath:config/,classpath:config/licensingservice

4、修改Spring Cloud Config Server 服务端属性配置文件bootstrap.yml,如下所示:

  1. spring:
  2. application:
  3. name: configserver
  4. encrypt:
  5. key: IMSYMMETRIC

5、修改Spring Cloud Config Client 客户端属性配置文件bootstrap.yml,如下所示:

  1. spring:
  2. application:
  3. name: licensingservice
  4. profiles:
  5. active:
  6. dev
  7. cloud:
  8. config:
  9. uri: http://localhost:8888

6、访问http://localhost:8888/licensingservice/dev,返回结果如下所示:

  1. {
  2. "name": "licensingservice",
  3. "profiles": [
  4. "dev"
  5. ],
  6. "label": null,
  7. "version": null,
  8. "state": null,
  9. "propertySources": [
  10. {
  11. "name": "classpath:config/licensingservice/licensingservice-dev.yml",
  12. "source": {
  13. "spring.jpa.database": "POSTGRESQL",
  14. "spring.datasource.platform": "postgres",
  15. "spring.jpa.show-sql": "false",
  16. "spring.database.driverClassName": "org.postgresql.Driver",
  17. "spring.datasource.url": "jdbc:postgresql://localhost:5432/eagle_eye_dev",
  18. "spring.datasource.username": "postgres",
  19. "spring.datasource.password": "{cipher}2c644c00b51dbdd03116edd77be62774fc94b3c646f1c553015102680e1d1868",
  20. "spring.datasource.testWhileIdle": "true",
  21. "spring.datasource.validationQuery": "SELECT 1",
  22. "spring.jpa.properties.hibernate.dialect": "org.hibernate.dialect.PostgreSQLDialect",
  23. "redis.server": "redis",
  24. "redis.port": "6379",
  25. "signing.key": "345345fsdfsf5345"
  26. }
  27. },
  28. {
  29. "name": "classpath:config/licensingservice/licensingservice.yml",
  30. "source": {
  31. "example.property": "I AM IN THE DEFAULT",
  32. "spring.jpa.database": "POSTGRESQL",
  33. "spring.datasource.platform": "postgres",
  34. "spring.jpa.show-sql": "true",
  35. "spring.database.driverClassName": "org.postgresql.Driver",
  36. "spring.datasource.url": "jdbc:postgresql://database:5432/eagle_eye_local",
  37. "spring.datasource.username": "postgres",
  38. "spring.datasource.password": "{cipher}4788dfe1ccbe6485934aec2ffeddb06163ea3d616df5fd75be96aadd4df1da91",
  39. "spring.datasource.testWhileIdle": "true",
  40. "spring.datasource.validationQuery": "SELECT 1",
  41. "spring.jpa.properties.hibernate.dialect": "org.hibernate.dialect.PostgreSQLDialect",
  42. "redis.server": "redis",
  43. "redis.port": "6379",
  44. "signing.key": "345345fsdfsf5345"
  45. }
  46. }
  47. ]
  48. }

参考:https://blog.csdn.net/daqiang012/article/details/105465230

本文内容由网友自发贡献,转载请注明出处:【wpsshop博客】
推荐阅读
相关标签
  

闽ICP备14008679号