所有我试图设置Spring的RestTemplate以允许对合作伙伴的Web服务进行SSL调用。我的设置是:设置Spring 4 RestTemplate以使用SSL(JKS)
- 的Java 1.7
- Spring版本4.1
- 的HttpClient 4.3版
- 的Tomcat 7.0.54
我想充分利用3.X的新功能servlet-api.jar(附带Tomcat 7)和Spring 4,允许我的Spring配置完全注释/代码驱动,而不是具有多个XML配置文件(截至目前我的web.xml文件完全为空)。到目前为止,我有:
我的基本配置类,相当直截了当
package com.config;
[imports]
@Configuration
@ComponentScan("com.application")
@EnableWebMvc
public class Config {
}
而且我的网络初始化类。我拉我的证书,并将它们读入Resource对象,但到目前为止我没有对它们做任何事情。我还设置了它,以便能够在我的应用程序中拨打其他电话(并非这与我的问题有关)。
package com.config;
[imports]
@Configuration
public class WebApplication implements WebApplicationInitializer {
@Override
public void onStartup(ServletContext servletContext) throws ServletException {
AnnotationConfigWebApplicationContext ctx = new AnnotationConfigWebApplicationContext();
ctx.register(com.config.Config.class);
ctx.setServletContext(servletContext);
Dynamic servlet = servletContext.addServlet("dispatcher", new DispatcherServlet(ctx));
servlet.addMapping("/");
servlet.setLoadOnStartup(1);
Resource trustStore = ctx.getResource("file:" + System.getProperty("javax.net.ssl.trustStore"));
Resource keyStore = ctx.getResource("file:" + System.getProperty("javax.net.ssl.keyStore"));
String trustStorePassword = System.getProperty("javax.net.ssl.trustStorePassword")
String keyStorePassword = System.getProperty("javax.net.ssl.keyStorePassword")
}
}
看起来体面的数额发生了变化,从春季3〜4春天等如何建立RestTemplate使用SSL,现有的例子不再有效。最重要的是,我一直在梳理网络上的一个例子,如何使用Java/annotations而不是xml文件来做到这一点,但迄今为止一直没有发现任何东西。我已经做了几次不同的尝试来自己配置一个RestTemplate对象,但没有任何运气。有没有人有一个很好的例子或链接到如何尝试实现这个例子?