0

目前,我正在努力使我的 Spring Boot 应用程序能够从 Consul KV 动态读取数据。

目前,我有一堂课:

ConsulServiceClientImpl

public class ConsulServiceClientImpl implements ConsulServiceClient {

       private String test;

       public String getTestValueFromConsul() {
          return test;
       }
}

我在 XML 配置文件中为上述类定义了一个 bean 初始化,如下所示:

领事配置.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>

这就是我的应用程序类的样子:

DemoApplication.class

@SpringBootApplication
@ImportResource({"classpath*:consulConfiguration.xml"})
public class DemoApplication {

       public static void main(String[] args) {
          SpringApplication.run(DemoApplication.class, args);
       }
}

现在,在我尝试运行该应用程序后,它给了我一个错误日志:

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?

我想知道是否有任何方法可以像这样使用 XML 配置从 Consul 绑定 KV?

4

0 回答 0