迁移到JRE 1.8时Spring Bean创建属性不可写异常

时间:2018-10-08 12:38:12

标签: java spring hazelcast

在创建HazelCast的bean时遇到以下异常。当我将已安装的JRE版本更改为jre 1.8时,会发生这种情况。但是在jre 1.6中,我们没有得到错误。对jre 8进行了任何更改,以禁止使用此类配置。

错误:

Invalid property 'name' of bean class [com.hazelcast.config.TopicConfig]: Bean property 'name' is not writable or has an invalid setter method. Does the parameter type of the setter match the return type of the getter?

在第三方类setter的属性name的{​​{1}}中,我们可以看到它返回的是TopicConfig的实例,而不是{{1 }}返回类型。对TopicConfig进行了任何更改,以禁止在setter返回值的情况下进行此类配置

1 个答案:

答案 0 :(得分:1)

这不是答案,而是显示代码示例。

我尝试了以下操作(Java 1.8.0_181,春季4.3.0.RELEASE),它正在构造主题bean,没有任何问题:

public static void main(String[] args) {
  ApplicationContext context = new ClassPathXmlApplicationContext("spring.xml");
  ITopic topic = context.getBean("topic", ITopic.class);
}

spring.xml

<beans xmlns="http://www.springframework.org/schema/beans"
   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
   xmlns:hz="http://www.hazelcast.com/schema/spring"
   xsi:schemaLocation="http://www.springframework.org/schema/beans
    http://www.springframework.org/schema/beans/spring-beans.xsd
    http://www.hazelcast.com/schema/spring
    http://www.hazelcast.com/schema/spring/hazelcast-spring-3.10.xsd">

  <hz:hazelcast id="instance">
    <hz:config>
        <hz:network port="5701" port-auto-increment="false">
            <hz:join>
                <hz:multicast enabled="false"/>
                <hz:tcp-ip enabled="true">
                    <hz:interface>127.0.0.1</hz:interface>
                </hz:tcp-ip>
            </hz:join>
        </hz:network>

        <hz:topic name="my-topic" />
    </hz:config>
  </hz:hazelcast>

  <hz:topic id="topic" instance-ref="instance" name="my-topic" />

</beans>
相关问题