我在我的应用程序中使用 Spring RestTemplate 来访问外部 Web 服务。但是,此 Web 服务帽子 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>
我已将服务器证书导入密钥库,它肯定在其中。我还需要做什么?我已经在这里检查了所有类似的问题,但没有一个有帮助。谢谢。