Praveen
Praveen

Reputation: 627

Spring-bean default to null if property not set

I am adding a new property on existing bean but I do not want it on all instance of the bean. I did see this option ignoreUnresolvablePlaceholders that can be put in

org.springframework.beans.factory.config.PropertyPlaceholderConfigure

However this has unintended of consequence if ignoring unset property for all beans defined. Is there a way that I can do either one of these 2 things

1)Tell spring-bean to ignore unset token for a singe type of bean

2)For the bean set a default value which gets over-riden only when property defined in spring-bean.Since I do not want to add empty property name for all instance of a bean

Upvotes: 0

Views: 614

Answers (1)

Sushil Behera
Sushil Behera

Reputation: 981

Set the default value to the bean property like below.

In below code it will try to set the property name. If none found it will set "ABC".

@Value(value = "${name:ABC}")
private String name;

Upvotes: 1

Related Questions