Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
codefromthecrypt opened this issue Jun 18, 2018 · 5 comments
Closed
Assignees
Labels
type: documentation A documentation update
Milestone

Comments

@codefromthecrypt
Copy link
Contributor

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;
  }
}
@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Jun 18, 2018
@snicoll snicoll changed the title 🐞 wildcard property names don't map into Map<String, String> ConfigurationProperties Wildcard property names don't map into Map<String, String> ConfigurationProperties Jun 18, 2018
@wilkinsona
Copy link
Member

I think this is, essentially, the same limitation as #13404 is tracking. You can get the * to bind by surrounding it with [*]:

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

@wilkinsona
Copy link
Member

Given that we've got #13404 to make this easier, I think we should use this issue to document the current situation. There's a brief mention of bracket notation on the wiki, but I can't find any mention in the reference documentation.

@wilkinsona wilkinsona changed the title Wildcard property names don't map into Map<String, String> ConfigurationProperties Document when and how to use bracket notation when binding to a map Jun 18, 2018
@wilkinsona wilkinsona added type: documentation A documentation update and removed status: waiting-for-triage An issue we've not yet triaged labels Jun 18, 2018
@wilkinsona wilkinsona added this to the 2.0.x milestone Jun 18, 2018
@codefromthecrypt
Copy link
Contributor Author

codefromthecrypt commented Jun 19, 2018 via email

@garyrussell
Copy link
Contributor

Is this behavior expected:

logging:
  level:
    org.springframework.kafka.listener[KafkaMessageListenerContainer$ListenerConsumer]: info

and

logging:
  level:
    org.springframework.kafka.listener.[KafkaMessageListenerContainer$ListenerConsumer]: info

(with and without . before [) ?

They both work.

@mbhave
Copy link
Contributor

mbhave commented Jun 22, 2018

yes this is expected behavior.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: documentation A documentation update
Projects
None yet
Development

No branches or pull requests

5 participants