Currently, I am trying to work on making my spring boot application to be able to dynamically read the data from Consul KV.
At the moment, I have a class:
ConsulServiceClientImpl
public class ConsulServiceClientImpl implements ConsulServiceClient {
private String test;
public String getTestValueFromConsul() {
return test;
}
}
and I have defined a bean initialization for the above class in the XML configuration file like following:
consulConfiguration.xml
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context.xsd">
<bean id="consulServiceClient" class="com.example.poc.demo.adaptor.impl.ConsulServiceClientImpl">
<property name="test" value="${test}" />
</bean>
</beans>
And this is how my application class looks like:
DemoApplication.class
@SpringBootApplication
@ImportResource({"classpath*:consulConfiguration.xml"})
public class DemoApplication {
public static void main(String[] args) {
SpringApplication.run(DemoApplication.class, args);
}
}
Now, after I have tried to run the app, it gave me an error logs:
Caused by: org.springframework.beans.NotWritablePropertyException: Invalid property 'test' of bean
class [com.example.poc.demo.adaptor.impl.ConsulServiceClientImpl]: Bean property 'test' is not
writable or has an invalid setter method. Does the parameter type of the setter match the return
type of the getter?
I am wondering if there is any way that we can bind the KV from Consul by using XML configuration like so ?