SpringBoot application failed with error "Could not resolve placeholder 'random.value'"
search cancel

SpringBoot application failed with error "Could not resolve placeholder 'random.value'"

book

Article ID: 297935

calendar_today

Updated On:

Products

VMware Tanzu Application Service for VMs

Issue/Introduction

One SpringBoot app was using Spring-Cloud-Services-Connector to get properties of the registry service instance binding to the application. However, the application was not able to start after being pushed to the Tanzu Application Service (TAS) for VMs platform. The error messages from application logs look similar to the following. 
   2020-12-22T08:37:43.97+0000 [APP/PROC/WEB/0] OUT org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'io.pivotal.spring.cloud.service.eureka.EurekaInstanceAutoConfiguration': Injection of autowired dependencies failed; nested exception is java.lang.IllegalArgumentException: Could not resolve placeholder 'random.value' in value "vcap.application.instance_id:${random.value}"

   2020-12-22T08:37:43.97+0000 [APP/PROC/WEB/0] OUT     at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessProperties(AutowiredAnnotationBeanPostProcessor.java:405)

   2020-12-22T08:37:43.97+0000 [APP/PROC/WEB/0] OUT     at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1422)

   2020-12-22T08:37:43.97+0000 [APP/PROC/WEB/0] OUT     at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:594)

   2020-12-22T08:37:43.97+0000 [APP/PROC/WEB/0] OUT     at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:517)

   2020-12-22T08:37:43.97+0000 [APP/PROC/WEB/0] OUT     at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:323)

   2020-12-22T08:37:43.97+0000 [APP/PROC/WEB/0] OUT     at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:226)

   2020-12-22T08:37:43.97+0000 [APP/PROC/WEB/0] OUT     at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:321)

   2020-12-22T08:37:43.97+0000 [APP/PROC/WEB/0] OUT     at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:202)

   2020-12-22T08:37:43.97+0000 [APP/PROC/WEB/0] OUT     at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:893)

   2020-12-22T08:37:43.97+0000 [APP/PROC/WEB/0] OUT     at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:879)

   2020-12-22T08:37:43.97+0000 [APP/PROC/WEB/0] OUT     at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:551)

   2020-12-22T08:37:43.97+0000 [APP/PROC/WEB/0] OUT     at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:143)

   2020-12-22T08:37:43.97+0000 [APP/PROC/WEB/0] OUT     at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:758)

   2020-12-22T08:37:43.97+0000 [APP/PROC/WEB/0] OUT     at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:750)

   2020-12-22T08:37:43.97+0000 [APP/PROC/WEB/0] OUT     at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:397)

   2020-12-22T08:37:43.97+0000 [APP/PROC/WEB/0] OUT     at org.springframework.boot.SpringApplication.run(SpringApplication.java:315)

   2020-12-22T08:37:43.97+0000 [APP/PROC/WEB/0] OUT     at org.springframework.boot.SpringApplication.run(SpringApplication.java:1237)

   2020-12-22T08:37:43.97+0000 [APP/PROC/WEB/0] OUT     at org.springframework.boot.SpringApplication.run(SpringApplication.java:1226)

   2020-12-22T08:37:43.97+0000 [APP/PROC/WEB/0] OUT     at kr.co.kblife.customer.web.CustomerWebApplication.main(CustomerWebApplication.java:57)

   2020-12-22T08:37:43.97+0000 [APP/PROC/WEB/0] OUT     at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

   2020-12-22T08:37:43.97+0000 [APP/PROC/WEB/0] OUT     at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)

   2020-12-22T08:37:43.97+0000 [APP/PROC/WEB/0] OUT     at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)

   2020-12-22T08:37:43.97+0000 [APP/PROC/WEB/0] OUT     at java.lang.reflect.Method.invoke(Method.java:498)

   2020-12-22T08:37:43.97+0000 [APP/PROC/WEB/0] OUT     at org.springframework.boot.loader.MainMethodRunner.run(MainMethodRunner.java:49)

   2020-12-22T08:37:43.97+0000 [APP/PROC/WEB/0] OUT     at org.springframework.boot.loader.Launcher.launch(Launcher.java:109)

   2020-12-22T08:37:43.97+0000 [APP/PROC/WEB/0] OUT     at org.springframework.boot.loader.Launcher.launch(Launcher.java:58)

   2020-12-22T08:37:43.97+0000 [APP/PROC/WEB/0] OUT     at org.springframework.boot.loader.WarLauncher.main(WarLauncher.java:59)

   2020-12-22T08:37:43.97+0000 [APP/PROC/WEB/0] OUT Caused by: java.lang.IllegalArgumentException: Could not resolve placeholder 'random.value' in value "vcap.application.instance_id:${random.value}"
   ......


Environment

Product Version: 2.1

Resolution

The application was adding a bean to encrypt or decrypt JDBC properties with the jasypt.spring4 package. 
<bean class="org.jasypt.spring4.properties.EncryptablePropertyPlaceholderConfigurer">
                <constructor-arg ref="configurationEncryptor" />
                <property name="locations">
                        <list>
                           <value>classpath:config/dev/jdbc.properties</value>
                           <value>classpath:config/dev/context.properties</value>
                        </list>
                </property>
 </bean>

However, jasypt.spring4 package is not compatible with SpringBoot, which would break functionality of RandomValuePropertySource class to resolve place holder, like  ${random.value}.

It is required to use the jasypt-spring-boot package instead for SpringBoot applications to encrypt or decrypt sensitive data.