相关文章推荐
睿智的松鼠  ·  HTTP客户端之Spring ...·  1 周前    · 
淡定的盒饭  ·  ASP.NET 核心 Blazor ...·  3 天前    · 
傻傻的馒头  ·  STRING_SPLIT ...·  昨天    · 
销魂的烈马  ·  error C2227: ...·  1 年前    · 
谦和的番茄  ·  TypeScript中的泛型 - 知乎·  2 年前    · 
怕老婆的泡面  ·  X-MOL·  2 年前    · 
Collectives™ on Stack Overflow

Find centralized, trusted content and collaborate around the technologies you use most.

Learn more about Collectives

Teams

Q&A for work

Connect and share knowledge within a single location that is structured and easy to search.

Learn more about Teams

I am getting **Caused by: org.springframework.beans.TypeMismatchException: Failed to convert value of type 'java.lang.String' to required type 'java.lang.Boolean'; nested exception is java.lang.IllegalArgumentException: **

I believe this happens due to missing spring place holder config. But I have the bean initialised in application context and still getting this error. Can any one help me out??

    @Value("${com.test.isTestEnable")
    public Boolean isTestEnable;

Spring Properties Class

public class SpringPropertiesUtil extends PropertyPlaceholderConfigurer {
    private static HashMap<String, String> systemPropertiesMap;
    private int springSystemPropertiesMode = SYSTEM_PROPERTIES_MODE_FALLBACK;
    public static String getProperty(final String name) {
        return systemPropertiesMap.get(name);
    @Override
    protected void processProperties(final ConfigurableListableBeanFactory beanFactory, final Properties props) throws BeansException {
        super.processProperties(beanFactory, props);
        systemPropertiesMap = new HashMap<String, String>();
        for (final Object key : props.keySet()) {
            final String keyStr = key.toString();
            final String valueStr = resolvePlaceholder(keyStr, props, springSystemPropertiesMode);
            systemPropertiesMap.put(keyStr, valueStr);
    @Override
    public void setSystemPropertiesMode(final int systemPropertiesMode) {
        super.setSystemPropertiesMode(systemPropertiesMode);
        springSystemPropertiesMode = systemPropertiesMode;

my application-context file

  <bean id="placeholderConfig" class="com.test.SpringPropertiesUtil">
        <property name="systemPropertiesModeName" value="SYSTEM_PROPERTIES_MODE_OVERRIDE" />
        <property name="locations">
                <value>file:${config.path}/application.properties</value>
                <value>file:${config.path}/log.properties</value>
            </list>
        </property>
    </bean>

Your real issue was just a typo at @Value("${com.test.isTestEnable") - you're missing a closing curly bracket } at the end of the expression

This should work completely fine:

    @Value("${com.test.isTestEnable}")
    public Boolean isTestEnable;
                Thanks "@Value("#{new Boolean('${com.test.isTestEnable}')}")" that's what I have been using so far to make it work. Although I have other projects where it works fine without new Boolean with above config. May be I am missing some other config or initialisation?
– lucifer_16
                Apr 23, 2020 at 4:45
                I don't think so...it is about casting property value to Boolean. Just check there ,may be the field type is string in other projects.
– Alien
                Apr 23, 2020 at 5:25
        

Thanks for contributing an answer to Stack Overflow!

  • Please be sure to answer the question. Provide details and share your research!

But avoid

  • Asking for help, clarification, or responding to other answers.
  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.