带有Jasypt加密的Spring Boot嵌入式tomcat配置

时间:2019-01-23 01:26:31

标签: spring-boot tomcat jasypt

尝试在Spring Boot 2.0中使用嵌入式tomcat。我在yaml中定义了ssl配置,并为密钥库密码提供了一个加密属性。 我在应用程序配置中定义了jasypt加密器bean。启动时,应用程序上下文加载失败并显示以下错误

Caused by: org.springframework.beans.factory.BeanCurrentlyInCreationException: Error creating bean with name 'jasyptStringEncryptor': Requested bean is currently in creation: Is there an unresolvable circular reference?
   at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.beforeSingletonCreation(DefaultSingletonBeanRegistry.java:339) ~[spring-beans-5.0.8.RELEASE.jar!/:5.0.8.RELEASE]
   at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:215) ~[spring-beans-5.0.8.RELEASE.jar!/:5.0.8.RELEASE]
   at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:315) ~[spring-beans-5.0.8.RELEASE.jar!/:5.0.8.RELEAS

APP_SERVER_SSL_PWD从系统属性中读取,并具有以ENC(value)格式定义的加密值。使用明文密码可以很好地加载上下文。

@Bean("jasyptStringEncryptor")
StringEncryptor stringEncryptor() {
    return new PBEStringEncryptorFactory().getPBEStringEncryptor(PBE_KEY_CONFIG_ENV_VAR,KEY_TYPE_ENVIRONMENT_VARIABLE);}

server:
 port: 8443
 ssl:
  enabled: true
  key-store: ${SECURE_DIR}/${SSL_KEY_STORE}
  key-store-type: JKS
  key-store-provider: SUN
  key-store-password: ${APP_SERVER_SSL_PWD}
  key-alias: ssl.server-pos-non-prod

0 个答案:

没有答案