Joly
Joly

Reputation: 3276

char[] to String Conversion in Spring configuration

I have bean A that returns an attribute as char[] and another bean that expects an attribute as String and I would like to inject the attribute from bean A to bean B.

When I do this:

    <bean id="B" class="....">
        <property name="password" value="#{A.password}" />
    </bean>

    <bean id="A" class="...">
    </bean>

The error I'm getting is:

Cannot convert value of type [char[]] to required type [java.lang.String] for property 'password': no matching editors or conversion strategy found

Any idea how to resolve this?

Perhaps by using an expression language syntax?

Perhaps by registering some sort of a converter like org.springframework.beans.propertyeditors.CharArrayPropertyEditor in the configuration before injecting the char[] attribute?

Upvotes: 0

Views: 1534

Answers (1)

Tomasz Nurkiewicz
Tomasz Nurkiewicz

Reputation: 340713

Looks like this will work:

<property name="password" value="#{new java.lang.String(A.password)}" />

Upvotes: 1

Related Questions