Search code examples
javaspring-4apache-mina

apache mina Custom editor configurer throws exception in spring 4


I was using Spring 3 with Apache Mina, and now I am using Spring 4 and trying to integrate Apache Mina. When I compile, I get an exception in CustomEditorConfigurer. Here is my bean:

<bean class="org.springframework.beans.factory.config.CustomEditorConfigurer">
        <property name="customEditors">
            <map>
                <entry key="java.net.SocketAddress">
                    <bean class="org.apache.mina.integration.beans.InetSocketAddressEditor" />
                </entry>
            </map>
        </property>
    </bean>

As said, it throws the following error:

Cannot convert value of type [org.apache.mina.integration.beans.InetSocketAddressEditor] to required type [java.lang.Class] for property 'customEditors[java.net.SocketAddress]': PropertyEditor [org.springframework.beans.propertyeditors.ClassEditor] returned inappropriate value of type [org.apache.mina.integration.beans.InetSocketAddressEditor]

Caused by: java.lang.IllegalArgumentException: Cannot convert value of type [org.apache.mina.integration.beans.InetSocketAddressEditor] to required type [java.lang.Class] for property 'customEditors[java.net.SocketAddress]': PropertyEditor [org.springframework.beans.propertyeditors.ClassEditor] returned inappropriate value of type [org.apache.mina.integration.beans.InetSocketAddressEditor]
    at org.springframework.beans.TypeConverterDelegate.convertIfNecessary(TypeConverterDelegate.java:263)
    at org.springframework.beans.TypeConverterDelegate.convertToTypedMap(TypeConverterDelegate.java:623)
    at org.springframework.beans.TypeConverterDelegate.convertIfNecessary(TypeConverterDelegate.java:208)
    at org.springframework.beans.BeanWrapperImpl.convertIfNecessary(BeanWrapperImpl.java:459)

Is the problem related with the newer version of Spring?

My Maven dependencies are the following:

<properties>
    <org.springframework-version>4.0.6.RELEASE</org.springframework-version>
</properties>

<dependency>
        <groupId>org.apache.mina</groupId>
        <artifactId>mina-core</artifactId>
        <version>2.0.4</version>
</dependency>

<dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-core</artifactId>
        <version>${org.springframework-version}</version>
</dependency>

<dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-context</artifactId>
        <version>${org.springframework-version}</version>
</dependency>

<dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-beans</artifactId>
        <version>${org.springframework-version}</version>
</dependency>

<dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-web</artifactId>
        <version>${org.springframework-version}</version>
</dependency>

<dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-webmvc</artifactId>
        <version>${org.springframework-version}</version>
</dependency>

<dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-messaging</artifactId>
        <version>${org.springframework-version}</version>
</dependency>

<dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-websocket</artifactId>
        <version>${org.springframework-version}</version>
</dependency>

<dependency>
        <groupId>com.fasterxml.jackson.core</groupId>
        <artifactId>jackson-databind</artifactId>
        <version>2.3.2</version>
</dependency>

<dependency>
        <groupId>org.projectreactor</groupId>
        <artifactId>reactor-net</artifactId>
        <version>1.1.0.RELEASE</version>
</dependency>

Solution

  • Based on this link it depends on the version of Spring. Changes may vary with different version of Spring.

    solved the issue modifying the list.

    from:

    <Entry Key = "java.net.SocketAddress" >  
          <Bean  class = "org.apache.mina.integration.beans.InetSocketAddressEditor"  />  
     </ Entry>  
    

    to:

    <Entry Key = "java.net.SocketAddress" value = "org.apache.mina.integration.beans.InetSocketAddressEditor" />