spring-projects / spring-projects/spring-boot

Allow binder to compose collections from multiple sources

Open
#41,830 2 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

type: enhancement
Dominant language
Java
Stars
81.5k
Forks
42.7k
Avg merge
2d 4h
Merged PRs (30d)
65

Description

Currently the Binder class has a "first wins" policy for binding lists. From the docs:

When lists are configured in more than one place, overriding works by replacing the entire list.

This policy has worked well, however, it also causes problems such as #41669 where users really want to merge lists together.

I think it would be a mistake to attempt to compose lists from elements in different property sources, however, we might be able to offer a feature where distinct lists could be merged together.

Proposal

When property values are defined, the property name could include an additional indicator that is used to determine how the values should be merged. The indicator would be (+) for addAll and (-) for removeAll:

This example shows an auto-configure exclude:

.properties

spring.autoconfigure.exclude=org.springframework.boot.autoconfigure.elasticsearch.ElasticsearchClientAutoConfiguration
#---
spring.config.activate.on-profile: noredis
spring.autoconfigure.exclude(+)=org.springframework.boot.autoconfigure.data.redis.RedisAutoConfiguration

.yaml

spring:
  autoconfigure:
    exclude: org.springframework.boot.autoconfigure.elasticsearch.ElasticsearchClientAutoConfiguration
---
spring:
  config:
    activate:
      on-profile: noredis
  autoconfigure:
    exclude(+): org.springframework.boot.autoconfigure.data.redis.RedisAutoConfiguration

More complex examples are:

.properties

my.list-of-names(+)[0].first=Spring
my.list-of-names(+)[0].last=Boot
my.list-of-names(+)[1].first=Spring
my.list-of-names(+)[1].last=Framework

.yaml

my:
  list(-):
    - remove
    - stuff
Limitations

It will be hard to support this syntax with environment variables.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reading the Binder class and the documented list-binding behavior, then trace how property names could represent the proposed (+) and (-) indicators. Compare the properties and YAML examples, account for the environment-variable limitation, and establish tests and documentation that define when merging is complete.

Written by the indexing model from the issue text.

Assessment

Tech stack
java, spring-boot
Domain
backend
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.