From 2809811d9fe32d2417f5a7e04aee19d558c5c42c Mon Sep 17 00:00:00 2001 From: Nikhil Khatwani Date: Tue, 23 Oct 2018 17:56:26 +0530 Subject: [PATCH] Changes for BAEL-2215 --- .../collection/CollectionInjectionDemo.java | 1 + .../com/baeldung/collection/CollectionsBean.java | 14 +++++++++++--- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/spring-core/src/main/java/com/baeldung/collection/CollectionInjectionDemo.java b/spring-core/src/main/java/com/baeldung/collection/CollectionInjectionDemo.java index 2e0d9eb8d8..2ee265f134 100644 --- a/spring-core/src/main/java/com/baeldung/collection/CollectionInjectionDemo.java +++ b/spring-core/src/main/java/com/baeldung/collection/CollectionInjectionDemo.java @@ -16,5 +16,6 @@ public class CollectionInjectionDemo { collectionsBean.printNameSet(); collectionsBean.printNameMap(); collectionsBean.printBeanList(); + collectionsBean.printNameListWithDefaults(); } } diff --git a/spring-core/src/main/java/com/baeldung/collection/CollectionsBean.java b/spring-core/src/main/java/com/baeldung/collection/CollectionsBean.java index a0e985267f..fc90f2c6ff 100644 --- a/spring-core/src/main/java/com/baeldung/collection/CollectionsBean.java +++ b/spring-core/src/main/java/com/baeldung/collection/CollectionsBean.java @@ -1,13 +1,14 @@ package com.baeldung.collection; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.beans.factory.annotation.Qualifier; - import java.util.ArrayList; import java.util.List; import java.util.Map; import java.util.Set; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Qualifier; +import org.springframework.beans.factory.annotation.Value; + /** * Created by Gebruiker on 5/18/2018. */ @@ -24,6 +25,9 @@ public class CollectionsBean { @Qualifier("CollectionsBean") private List beanList = new ArrayList<>(); + @Value("${names.list:}#{T(java.util.Collections).emptyList()}") + private List nameListWithDefaultValue; + public CollectionsBean() { } @@ -51,4 +55,8 @@ public class CollectionsBean { public void printBeanList() { System.out.println(beanList); } + + public void printNameListWithDefaults() { + System.out.println(nameListWithDefaultValue); + } }