Is it possible to read fragment of an array by @Value (Spring 5)?
Something like this:
Input data.properties :
list.numbers=1,2,3 Read
@Value("${list.numbers[0]}") int firstNumber; Output
firstNumber=1 Is it possible to read fragment of an array by @Value (Spring 5)?
Something like this:
Input data.properties :
list.numbers=1,2,3 Read
@Value("${list.numbers[0]}") int firstNumber; Output
firstNumber=1 You can split and get the first element.
@Value("#{'${list.numbers}'.split(',')[0]}") int firstNumber; A long time ago, I have used bean injection with XML configuration. You can read that blog article and using spring-core, spring-beans and spring-context-support dependencies.
Below you'll find the XML config of that bean injection with the <bean ref="beanListItemId"> (here : song1, song2, etc.) inside your bean list (here the list container is album):
<?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd"> <bean id="song1" class="org.kodejava.spring.core.Song"> <property name="title" value="I Saw Her Standing There" /> <property name="writer" value="Beatles" /> </bean> <bean id="song2" class="org.kodejava.spring.core.Song"> <property name="title" value="Misery" /> <property name="writer" value="Beatles" /> </bean> <bean id="song3" class="org.kodejava.spring.core.Song"> <property name="title" value="Anna (Go to Him)" /> <property name="writer" value="Beatles" /> </bean> <bean id="album" class="org.kodejava.spring.core.Album"> <property name="title" value="Please Please Me" /> <property name="year" value="1963" /> <property name="songs"> <list> <ref bean="song1" /> <ref bean="song2" /> <ref bean="song3" /> </list> </property> </bean> </beans>