Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

No converter found capable of converting from type [java.lang.String] to type [java.util.LinkedHashMap<java.lang.String, java.lang.String>]

spring boot 2.1.1 can not read yml config to LinkedHashMap

this is my class

I've provided get and set functions. But it doesn't work.

@Getter
@Setter
@Configuration
@ConfigurationProperties("shiro")
public class ShiroConfiguration {
    private LinkedHashMap<String, String> filterChainDefinitions;
}

this is my config

shiro:
  filterChainDefinitions:
    /**: origin

this is error message

Description:

Failed to bind properties under 'shiro.filter-chain-definitions' to java.util.LinkedHashMap<java.lang.String, java.lang.String>:

    Reason: No converter found capable of converting from type [java.lang.String] to type [java.util.LinkedHashMap<java.lang.String, java.lang.String>]

Action:

Update your application's configuration
like image 305
linuxprobe org Avatar asked Dec 17 '18 08:12

linuxprobe org


1 Answers

@ConfigurationProperties can't map LinkedHashMap from you properties. You have to use SpEL which is not supported as mentioned here

To solve your issue could update the configuration by adding @Value annotation eg.:

@Getter
@Setter
@Component
public class ShiroConfiguration {

  @Value("#{${shiro.filter-chain-definitions}}")
  private LinkedHashMap<String, String> filterChainDefinitions;

}
like image 114
jirka Avatar answered Sep 30 '22 17:09

jirka