2017-03-17 38 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