Skip to content

Document when and how to use bracket notation when binding to a map #13506

Closed
@codefromthecrypt

Description

@codefromthecrypt

Camel's zipkin spring boot thing uses wildcard mappings to properties like this:

# the zipkin service name
camel.zipkin.server-service-mappings.*=service1
camel.zipkin.client-service-mappings.*=service2

The corresponding @ConfigurationProperties would receive a map entry for the wildcard into a map field like this: private Map<String, String> clientServiceMappings

The last version this worked on was Spring Boot 2.0 M7. Afterwards, this mapping fails with the following exception:

Caused by: org.springframework.core.convert.ConverterNotFoundException: No converter found capable of converting from type [java.lang.String] to type [java.util.Map<java.lang.String, java.lang.String>] at org.springframework.core.convert.support.GenericConversionService.handleConverterNotFound (GenericConversionService.java:321)

So that you don't have to build camel, you can paste the below into a start.spring.io app, setting the above as application.properties

@SpringBootApplication
@EnableConfigurationProperties(ZipkinConfigurationProperties.class)
public class DemoApplication {

  public static void main(String[] args) {
    SpringApplication.run(DemoApplication.class, args);
  }
}
@ConfigurationProperties(prefix = "camel.zipkin")
public class ZipkinConfigurationProperties {
  private Map<String, String> clientServiceMappings;
  private Map<String, String> serverServiceMappings;

  public Map<String, String> getClientServiceMappings() {
    return clientServiceMappings;
  }

  public void setClientServiceMappings(Map<String, String> clientServiceMappings) {
    this.clientServiceMappings = clientServiceMappings;
  }

  public Map<String, String> getServerServiceMappings() {
    return serverServiceMappings;
  }

  public void setServerServiceMappings(Map<String, String> serverServiceMappings) {
    this.serverServiceMappings = serverServiceMappings;
  }
}

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions