Spring Application Context: How do you set a constructor argument of a class to a class static member variable?

StackOverflow https://stackoverflow.com/questions/13269880

Frage

In the application context XML file, how do you set a constructor argument to a static class member?

For example, I am using Restlet and one of Restlet's classes called ChallengeAuthenticator receives a challenge scheme member variable.

// Normal Initialization
ChallengeAuthenticator challengeAuthenticator = new ChallengeAuthenticator(
                null, ChallengeScheme.HTTP_BASIC, "WSRealm");

I want to have this in the application context if possible. To something like this:

<bean id="challengeAuthenticator" class="org.restlet.security.ChallengeAuthenticator">
  <!-- Not meant to be String for value just trying to make it easier to reader to interpret my question -->  
  <constructor-arg value="ChallengeScheme.HTTP_BASIC" />
</bean>
War es hilfreich?

Lösung

The easiest way is to use Spring Expression Language:

<constructor-arg value="#{ T(ChallengeScheme).HTTP_BASIC }" />

Note that you need a full class name in T(...).

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top