How to Refer to Static Fields within Spring XML Configuration

5 years ago by in How To, Spring

When configuring Spring through XML, you can use static fields in a similar way you use instances defined in the same XML or elsewhere. This is possible by using the util namespace as highlighted below.

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns=""

  <bean id="myObject" class="com.javacreed.examples.howto.spring.StaticInXml">
        <util:constant static-field="com.javacreed.examples.howto.spring.MyFields.OBJECT_1" />


The above example makes use of Spring Framework 3.1.

Albert Attard

Albert Attard is a Java passionate and technical lead at a research group. You can find him on . Over the past years Albert worked on various Java projects including traditional server/client applications, modular applications, large data handling applications and concurrent data manipulation applications to name a few. He has a BSc degree from the University of London (Homepage) and an MSc Information Security with the same university. His MSc thesis (Book) received the 2012 award (Website).

Leave a Comment

Time limit is exhausted. Please reload the CAPTCHA.