Announcement Announcement Module
No announcement yet.
How do I call java.lang.System.setProperties Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • How do I call java.lang.System.setProperties

    I can't figure out how to set a system property from /WEB-INF/applicationContext.xml. I tried the following (taken from the example at, but I get a java.lang.NullPointerException:

    	<bean id="setKerberosProperties" class="org.springframework.beans.factory.config.MethodInvokingFactoryBean">
    		<property name="targetClass"><value>java.lang.System</value></property>
    		<property name="targetMethod"><value>setProperties</value></property>
    		<property name="arguments">
    					<prop key=""></prop>
    					<prop key=""></prop>
    The interesting thing is that the java.lang.NullPointerException doesn't come from a Spring stack trace, it is comming from Tomcat:

    Code:; java.lang.NullPointerException at
    If I remove the "setKerberosProperties" bean stanza from /WEB-INF/applicationContext.xml, the web application deploys fine (but doesn't work since I need to define those two system properties).

    What is the "Spring Way" to set system properties from one's /WEB-INF/applicationContext.xml?

    I need to set these system properties in oreder to get Acegi (and CAS) to use our Kerberos servers for authentication.

    Warmest regards, Matt

  • #2
    Take a look at org.springframework.util.Log4jConfigurer it is called by the Log4jWebConfigurer, and seems to be just a static wrapper around a System.setProperty() call so that it can be triggered from a Spring bean. I am not aware of any generic solution for this in Spring; but you could write a custom class that on init (or statically) sets the sytem properties.


    • #3

      The easiest way to set these system properties is to either create a simple wrapper like Log4JConfigurer, or just set them when starting tomcat. You need to set a value for the JAVA_OPTS env variable that contains the system property calls.