Can I use Spring EL inside the bean id attribute?

Can I use SpEL inside id bean attribute?

for example: <bean id="#{T(com.om.m).PublicStaticFinalStringProperty}"...

So it does not work, what should I change or is it impossible?

+4
source share
1 answer

Strange, but possible (example uses spring 3.1). Different versions:

 <?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context" xmlns:util="http://www.springframework.org/schema/util" xsi:schemaLocation=" http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util.xsd "> <context:property-placeholder properties-ref="myProps"/> <util:properties id="myProps" > <prop key="xyz">possible</prop> </util:properties> <bean id="testBean" class="Bean"> <property name="value" value="weird"/> </bean> <bean id="${xyz}" class="Bean"> <property name="value" value="but"/> </bean> <bean id="#{testBean.value}" class="Bean"> <property name="value" value="${xyz}"/> </bean> </beans> 

Bean.java

 public class Bean implements InitializingBean { String value; public void setValue(String value) { this.value = value; } public void afterPropertiesSet() throws Exception { System.out.println(value); } } 
+2
source

Source: https://habr.com/ru/post/1399155/


All Articles