Simple internal constants, that should not be externalized to properties:
object InternalConstant {
val CONSTANT_ONE: Byte = 21
val CONSTANT_TWO: Byte = 42
}
Injecting them as I would with Java:
<bean id="daBean" class="my.package.DaClass">
<constructor-arg>
<util:开发者_开发知识库constant static-field="my.package.InternalConstant.CONSTANT_TWO"/>
</constructor-arg>
</bean>
getting a java.lang.NoSuchFieldException:
CONSTANT_TWO
( the package path is correct )
That's because behind the scenes InternalConstant
is compiled into a class with static CONSTANT_ONE()
method returning 21, not a field. And calling static methods is possible in Spring with SpEL:
<constructor-arg value="#{T(my.package.InternalConstant).CONSTANT_TWO()}"/>
Haven't tested it though.
精彩评论