我在应用程序中使用Spring RestTemplate来访问外部网络服务。这个网络服务启用了SSL,但是使用的是自签名证书(域名等也不合法)。这只是在本地网络上,所以我不必担心安全问题。我希望让Spring接受这个证书。我已经完成了以下步骤:
1.) 我已配置我的JBOSS 7使用这个密钥库。
<connector name="https" protocol="HTTP/1.1" socket-binding="https" scheme="https" enable-lookups="false" secure="true">
<ssl name="ssl" key-alias="my-private-key" password="rmi+ssl" certificate-key-file="../standalone/configuration/server-keystore.jks" protocol="TLSv1" verify-client="false"/>
</connector>
2.) 这是我的RestTemplate Bean配置(我在我的类中使用自动装配)
<bean id="stringHttpConverter" class="org.springframework.http.converter.StringHttpMessageConverter"></bean>
<bean id="httpClientParams" class="org.apache.commons.httpclient.params.HttpClientParams">
<property name="authenticationPreemptive" value="true"/>
<property name="connectionManagerClass" value="org.apache.commons.httpclient.MultiThreadedHttpConnectionManager"/>
</bean>
<bean id="httpClient" class="org.apache.commons.httpclient.HttpClient">
<constructor-arg ref="httpClientParams"/>
</bean>
<bean id="httpClientFactory" class="org.springframework.http.client.CommonsClientHttpRequestFactory">
<constructor-arg ref="httpClient"/>
</bean>
<bean id="restTemplate" class="org.springframework.web.client.RestTemplate">
<constructor-arg ref="httpClientFactory"/>
<property name="messageConverters">
<list>
<!-- <ref bean="marshallingConverter" /> -->
<ref bean="stringHttpConverter" />
</list>
</property>
</bean>
我已经将服务器证书导入密钥库,它肯定在里面。我还需要做什么?我已经检查过所有类似的问题,但都没有帮助。谢谢。