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

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>
有帮助吗?

解决方案

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(...).

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top