I hope to find some help in converting Java class initiation to spring beans. I have not worked much with spring beans and getting a variety of errors. Java version works no problem.
Java version:
SSLContextBuilder builder = new SSLContextBuilder();
builder.loadTrustMaterial(null, new TrustSelfSignedStrategy());
SSLConnectionSocketFactory sslsf = new SSLConnectionSocketFactory(builder.build());
Spring bean:
<spring:bean id="ssl_strategy" class="org.apache.http.conn.ssl.TrustSelfSignedStrategy" init-method="init"/>
<spring:bean id="ssl_builder" class="org.apache.http.conn.ssl.SSLContextBuilder" init-method="loadTrustMaterial(null, ssl_strategy)">
I'm getting an error that TrustSelfSignedStrategy has no method "init". The error :
Couldn't find an init method named 'init' on bean with name 'ssl_strategy'
But once I remove init-method="init" from the first bean, then I get an error for .loadTrustMaterial method:
Couldn't find an init method named 'loadTrustMaterial(null, ssl_strategy)' on bean with name 'ssl_builder'
EDIT #1: I also have tried using org.springframework.beans.factory.config.MethodInvokingFactoryBean as follows and this is so far the closest I think:
<spring:bean id="ssl_strategy" class="org.apache.http.conn.ssl.TrustSelfSignedStrategy" />
<spring:bean id="ssl_builder" class="org.apache.http.conn.ssl.SSLContextBuilder" />
<spring:bean class="org.springframework.beans.factory.config.MethodInvokingFactoryBean">
<spring:property name="targetObject" ref="ssl_builder"/>
<spring:property name="targetMethod" value="loadTrustMaterial"/>
<spring:property name="arguments">
<spring:list>
<spring:value>null</spring:value>
<spring:value>ssl_strategy</spring:value>
</spring:list>
</spring:property>
</spring:bean>
But the above results in the following error:
java.lang.NoSuchMethodException: org.apache.http.conn.ssl.SSLContextBuilder.loadTrustMaterial(java.lang.String, java.lang.String)
Could someone please post here what would be the right way to have the above Java as Spring beans?
... much appreciate your time.
@Configurationclasses and let the IDE and compiler help you. - Sean Patrick Floyd