Announcement Announcement Module
No announcement yet.
Ensuring a system property is set Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • Ensuring a system property is set


    I have a bunch of system properties that i need to be set before I can do any JSSE stuff. I wont rely on these being set with -D options on the command line (though they may be), so my bean - in this case a connection factory - which depends on these properties has a dependency like

      <bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
        <property name="location" value="classpath&#58;"/>
        <property name="ignoreResourceNotFound" value="true"/>
      <bean id="connectionFactory" class="org.springframework.jndi.JndiObjectFactoryBean" depends-on="keyStoreProperty,keyStoreTypeProperty,keyStorePasswordProperty,trustStoreProperty,trustStoreTypeProperty,trustStorePasswordProperty">
    and then my definition of one of these properties is

      <bean id="setSystemProperty" abstract="true" class="org.springframework.beans.factory.config.MethodInvokingFactoryBean">
        <property name="targetClass" value="java.lang.System"/>
        <property name="targetMethod" value="setProperty"/>
      <bean id="keyStoreProperty" parent="setSystemProperty">
        <property name="arguments">
    This works OK, because a user could invoke Java with a option or put in (and they'd not be able to override it at the command line, which is potentially useful).

    This is all a bit long-winded - can anyone think of a more consice way to do it?

  • #2
    Actually, my main gripe with this is that there may be times when JSSE properties may not be set (when they're not relevant).

    Is there a way to avoid the PropertyPlaceholderConfigurer complaining when the JSSE properties are not set, when I'm trying to use the same set of config for non-JSSE communictions?

    I can get around this by setting

    in my, but I'd like it to cope if there is just no supplied at all.


    • #3
      I can think of two ways, both having to do with overriding some method from PropertiesLoaderSupport - PropertyPlaceholderConfigurer's grandparent class.

      You can subclass PropertyPlaceholderConfigurer and override loadProperties with some logic that ignore FileNotFoundException.

      You can also subclass the same class, but override setLocation and/or setLocations to preemptively check all the locations and filter out the ones that don't exist.