2017-03-17 135 views
0

我的项目需要SSL认证机制EXTERNAL(仅使用SSL证书并避免rabbitmq上的用户名/密码)。对于connectionfactory bean,我们给了属性name =“saslConfig”value =“DefaultSaslConfig.EXTERNAL”,但是我们得到一个错误:“无法将[java.lang.String]类型的值转换为所需的类型[com.rabbitmq.client .SaslConfig]属性'saslConfig':找不到匹配的编辑或转换策略“。我们尝试了其他值,例如value =“com.rabbitmq.client.DefaultSaslConfig.EXTERNAL”和value =“EXTERNAL”,但仍然存在错误。你可以请检查下面的配置和日志,并提供给我你的建议。使用spring rabbitmq不起作用的saslConfig

bean配置

<rabbit:connection-factory id="connectionFactory" connection-factory="clientConnectionFactory" host="x.y.z.m" port="5671"/> 
    <bean id="clientConnectionFactory" class="org.springframework.amqp.rabbit.connection.RabbitConnectionFactoryBean"> 
    <property name="useSSL" value="true" /> 
    <property name="saslConfig" value=com.rabbitmq.client.DefaultSaslConfig.EXTERNAL"/> 
    <property name="sslPropertiesLocation" value="classpath:/rabbitSSL.properties"/></bean> 

日志

Caused by: java.lang.IllegalStateException: Cannot convert value of type [java.lang.String] to required type [com.rabbitmq.client.SaslConfig] for property 'saslConfig': no matching editors or conversion strategy found 
at org.springframework.beans.TypeConverterDelegate.convertIfNecessary(TypeConverterDelegate.java:306) 
at org.springframework.beans.AbstractNestablePropertyAccessor.convertIfNecessary(AbstractNestablePropertyAccessor.java:576) 

回答

0

EXTERNAL是一个静态变量,而不是一个枚举。

使用

"#{T(com.rabbitmq.client.DefaultSaslConfig).EXTERNAL}"

其是使用类型运算符(T)来获得到静态参考SpeI位表达。

请参阅SpEL