Spring 3.1 ConversionServiceFactoryBean breaks tilesViewResolver -



Spring 3.1 ConversionServiceFactoryBean breaks tilesViewResolver -

i have little spring (3.1.0.release) application, working fine, until decided need have converter converting stuff strings other types.

my application context file includes file, mvc-config.xml:

<?xml version="1.0" encoding="utf-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/xmlschema-instance" xmlns:mvc="http://www.springframework.org/schema/mvc" xmlns:p="http://www.springframework.org/schema/p" xsi:schemalocation=" http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.1.xsd http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.1.xsd"> <mvc:annotation-driven /> <mvc:view-controller path="/" view-name="index"/> <mvc:resources mapping="/resources/**" location="/resources/"/> <mvc:interceptors> <bean class="org.springframework.web.servlet.i18n.localechangeinterceptor" /> </mvc:interceptors> <bean id="localeresolver" class="org.springframework.web.servlet.i18n.cookielocaleresolver"> <property name="defaultlocale" ref="finnishlocale"/> </bean> <bean id="finnishlocale" class="java.util.locale"> <constructor-arg index="0" value="fi" /> </bean> <bean id="tilesconfigurer" class="org.springframework.web.servlet.view.tiles2.tilesconfigurer" p:definitions="/web-inf/config/tiles-config.xml"/> <bean id="tilesviewresolver" class="org.springframework.js.ajax.ajaxurlbasedviewresolver"> <property name="viewclass" value="org.springframework.webflow.mvc.view.flowajaxtilesview"/> </bean> </beans>

this works fine. problem occurs, when add together next bean definition above file:

<bean id="conversionservice" class="org.springframework.context.support.conversionservicefactorybean"> <property name="converters"> <list> <bean class="fi.mydomain.app.converter.stringtoclassconverter"/> </list> </property> </bean>

(which, way, same bean shown in spring documentation, apart converter class). i've modified the annotation-driven line this:

<mvc:annotation-driven conversion-service="conversionservice"/>

(the problem occurs, though, simply adding conversionservice bean).

(i have fi.mydomain.app.converter.stringtoclassconverter class written).

the problem application cannot deployed anymore. log file shows error message:

2012-01-16 17:55:30,427 [http-8080-7] error contextloader.initwebapplicationcontext() - context initialization failed org.springframework.beans.factory.beancreationexception: error creating bean name 'tilesviewresolver' defined in servletcontext resource [/web-inf/config/mvc-config.xml]: error setting property values; nested exception org.springframework.beans.propertybatchupdateexception; nested propertyaccessexceptions (1) are: propertyaccessexception 1: org.springframework.beans.methodinvocationexception: property 'viewclass' threw exception; nested exception java.lang.illegalargumentexception: given view class [null] not of type [org.springframework.web.servlet.view.abstracturlbasedview]

and when remove conversionservice bean xml, works again, except of course, cannot utilize own converters.

i've spent hours no avail. help appreciated. thanks.

-- hannu

i found out problem emerges converter. defined this:

final class stringtoclassconverter implements converter<string, class>, initializingbean { private map<string, class> map = new hashmap<string, class>(); public class convert(string key) { homecoming map.get(key); } public void afterpropertiesset() throws exception { map.put("organizations", class.forname("fi.mydomain.app.domain.organization")); map.put("invoices", class.forname("fi.mydomain.app.domain.invoice")); } }

this gave me symptoms described in original question. when changed converter this:

final class stringtoclassconverter implements converter<string, object>, initializingbean { private map<string, object> map = new hashmap<string, object>(); public object convert(string key) { homecoming map.get(key); } public void afterpropertiesset() throws exception { map.put("organizations", class.forname("fi.mydomain.app.domain.organization")); map.put("invoices", class.forname("fi.mydomain.app.domain.invoice")); } }

that is, after replaced class object, application started working again. not understand what's wrong in first converter, though, , i'm not happy solution either, guess have now.

-- hannu

spring spring-mvc

Comments

Popular posts from this blog

How do I check if an insert was successful with MySQLdb in Python? -

delphi - blogger via idHTTP : error 400 bad request -

postgresql - ERROR: operator is not unique: unknown + unknown -