I'm trying to add BouncyCastle to my Spring application but I am not sure how to add the provider to the java.security.Security
provider list using JavaConfig.
Using XML configuration, I can use the MethodInvokingFactoryBean
similar the following:
<bean class="org.springframework.beans.factory.config.MethodInvokingFactoryBean">
<property name="staticMethod" value="java.security.Security.addProvider"/>
<property name="arguments">
<list>
<bean class="org.bouncycastle.jce.provider.BouncyCastleProvider"/>
</list>
</property>
</bean>
However, I'm not sure of the right way to do this using JavaConfig. Should I still be using the MethodInvokingFactoryBean
? I presumed since it is pure java, there would be a more direct approach. At the moment, I've added the directive to a @PostConstruct
method in the JavaConfig object, but not too thrilled about it - it seems a little "hacky" to me:
@Configuration
public class AppConfig {
// other @Bean definitions
@PostConstruct
public void init(){
Security.addProvider(new org.bouncycastle.jce.provider.BouncyCastleProvider());
}
}
MethodInvokingBean
will be the de facto choice for add BouncyCastleProvider
to java.security.Security
since you won't need any exposure to your application context.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With