org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'contentNegotiatingViewResolver' defined in ServletContext resource [/WEB-INF/app-servlet.xml]: Initialization of bean failed; nested exception is org.springframework.core.convert.ConversionFailedException: Unable to convert value application/xml from type 'java.lang.String' to type 'org.springframework.http.MediaType'; nested exception is org.springframework.core.convert.ConversionFailedException: Unable to convert value application/xml from type 'java.lang.String' to type 'org.springframework.http.MediaType'; nested exception is java.lang.reflect.InvocationTargetException

Spring JIRA | Gerrit Brehmer | 6 years ago
  1. 0

    Because MediaType has an special constructor with only one String parameter, the ObjectToObjectConverter thought, that he can convert the String value "application/xml" to an MediaType. So ObjectToObjectConverter will call the constructor and conversion fails, because this constructor only need the primary content type: Exception: {noformat} org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'contentNegotiatingViewResolver' defined in ServletContext resource [/WEB-INF/app-servlet.xml]: Initialization of bean failed; nested exception is org.springframework.core.convert.ConversionFailedException: Unable to convert value application/xml from type 'java.lang.String' to type 'org.springframework.http.MediaType'; nested exception is org.springframework.core.convert.ConversionFailedException: Unable to convert value application/xml from type 'java.lang.String' to type 'org.springframework.http.MediaType'; nested exception is java.lang.reflect.InvocationTargetException at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:527) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:456) at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:291) at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222) at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:288) at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:190) at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:563) at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:872) at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:423) at org.springframework.web.servlet.FrameworkServlet.createWebApplicationContext(FrameworkServlet.java:442) at org.springframework.web.servlet.FrameworkServlet.createWebApplicationContext(FrameworkServlet.java:458) at org.springframework.web.servlet.FrameworkServlet.initWebApplicationContext(FrameworkServlet.java:339) at org.springframework.web.servlet.FrameworkServlet.initServletBean(FrameworkServlet.java:306) at org.springframework.web.servlet.HttpServletBean.init(HttpServletBean.java:127) at javax.servlet.GenericServlet.init(GenericServlet.java:212) at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1139) at org.apache.catalina.core.StandardWrapper.load(StandardWrapper.java:966) at org.apache.catalina.core.StandardContext.loadOnStartup(StandardContext.java:3996) at org.apache.catalina.core.StandardContext.start(StandardContext.java:4266) at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1014) at org.apache.catalina.core.StandardHost.start(StandardHost.java:736) at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1014) at org.apache.catalina.core.StandardEngine.start(StandardEngine.java:443) at org.apache.catalina.core.StandardService.start(StandardService.java:448) at org.apache.catalina.core.StandardServer.start(StandardServer.java:700) at org.apache.catalina.startup.Catalina.start(Catalina.java:552) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) at java.lang.reflect.Method.invoke(Method.java:592) at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:295) at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:433) Caused by: org.springframework.core.convert.ConversionFailedException: Unable to convert value application/xml from type 'java.lang.String' to type 'org.springframework.http.MediaType'; nested exception is org.springframework.core.convert.ConversionFailedException: Unable to convert value application/xml from type 'java.lang.String' to type 'org.springframework.http.MediaType'; nested exception is java.lang.reflect.InvocationTargetException at org.springframework.core.convert.support.ConversionUtils.invokeConverter(ConversionUtils.java:40) at org.springframework.core.convert.support.GenericConversionService.convert(GenericConversionService.java:138) at org.springframework.beans.TypeConverterDelegate.convertIfNecessary(TypeConverterDelegate.java:201) at org.springframework.beans.TypeConverterDelegate.convertIfNecessary(TypeConverterDelegate.java:155) at org.springframework.beans.BeanWrapperImpl.convertForProperty(BeanWrapperImpl.java:461) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.convertForProperty(AbstractAutowireCapableBeanFactory.java:1363) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1322) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1076) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:517) ... 31 more Caused by: org.springframework.core.convert.ConversionFailedException: Unable to convert value application/xml from type 'java.lang.String' to type 'org.springframework.http.MediaType'; nested exception is java.lang.reflect.InvocationTargetException at org.springframework.core.convert.support.ObjectToObjectConverter.convert(ObjectToObjectConverter.java:82) at org.springframework.core.convert.support.ConversionUtils.invokeConverter(ConversionUtils.java:37) ... 39 more Caused by: java.lang.reflect.InvocationTargetException at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39) at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27) at java.lang.reflect.Constructor.newInstance(Constructor.java:501) at org.springframework.core.convert.support.ObjectToObjectConverter.convert(ObjectToObjectConverter.java:70) ... 40 more Caused by: java.lang.IllegalArgumentException: Invalid token character '/' in token "application/xml" at org.springframework.http.MediaType.checkToken(MediaType.java:286) at org.springframework.http.MediaType.<init>(MediaType.java:257) at org.springframework.http.MediaType.<init>(MediaType.java:207) at org.springframework.http.MediaType.<init>(MediaType.java:196) ... 45 more {noformat} With disabled ConversionService, the value will be converted by MediaTypeEditor, which uses the MediaType.parseMediaType method. I think the behauvior should be the same like mediaTypes-parameter map (ContentNegotiatingViewResolver), where Strings must be used. Example spring config: {code:xml} <bean id="contentNegotiatingViewResolver" class="org.springframework.web.servlet.view.ContentNegotiatingViewResolver"> <property name="defaultContentType" value="application/xml"/> <property name="mediaTypes"> <map> <entry key="xml" value="application/xml" /> <entry key="json" value="application/json" /> </map> </property> </bean> {code}

    Spring JIRA | 6 years ago | Gerrit Brehmer
    org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'contentNegotiatingViewResolver' defined in ServletContext resource [/WEB-INF/app-servlet.xml]: Initialization of bean failed; nested exception is org.springframework.core.convert.ConversionFailedException: Unable to convert value application/xml from type 'java.lang.String' to type 'org.springframework.http.MediaType'; nested exception is org.springframework.core.convert.ConversionFailedException: Unable to convert value application/xml from type 'java.lang.String' to type 'org.springframework.http.MediaType'; nested exception is java.lang.reflect.InvocationTargetException
  2. 0

    Because MediaType has an special constructor with only one String parameter, the ObjectToObjectConverter thought, that he can convert the String value "application/xml" to an MediaType. So ObjectToObjectConverter will call the constructor and conversion fails, because this constructor only need the primary content type: Exception: {noformat} org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'contentNegotiatingViewResolver' defined in ServletContext resource [/WEB-INF/app-servlet.xml]: Initialization of bean failed; nested exception is org.springframework.core.convert.ConversionFailedException: Unable to convert value application/xml from type 'java.lang.String' to type 'org.springframework.http.MediaType'; nested exception is org.springframework.core.convert.ConversionFailedException: Unable to convert value application/xml from type 'java.lang.String' to type 'org.springframework.http.MediaType'; nested exception is java.lang.reflect.InvocationTargetException at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:527) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:456) at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:291) at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222) at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:288) at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:190) at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:563) at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:872) at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:423) at org.springframework.web.servlet.FrameworkServlet.createWebApplicationContext(FrameworkServlet.java:442) at org.springframework.web.servlet.FrameworkServlet.createWebApplicationContext(FrameworkServlet.java:458) at org.springframework.web.servlet.FrameworkServlet.initWebApplicationContext(FrameworkServlet.java:339) at org.springframework.web.servlet.FrameworkServlet.initServletBean(FrameworkServlet.java:306) at org.springframework.web.servlet.HttpServletBean.init(HttpServletBean.java:127) at javax.servlet.GenericServlet.init(GenericServlet.java:212) at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1139) at org.apache.catalina.core.StandardWrapper.load(StandardWrapper.java:966) at org.apache.catalina.core.StandardContext.loadOnStartup(StandardContext.java:3996) at org.apache.catalina.core.StandardContext.start(StandardContext.java:4266) at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1014) at org.apache.catalina.core.StandardHost.start(StandardHost.java:736) at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1014) at org.apache.catalina.core.StandardEngine.start(StandardEngine.java:443) at org.apache.catalina.core.StandardService.start(StandardService.java:448) at org.apache.catalina.core.StandardServer.start(StandardServer.java:700) at org.apache.catalina.startup.Catalina.start(Catalina.java:552) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) at java.lang.reflect.Method.invoke(Method.java:592) at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:295) at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:433) Caused by: org.springframework.core.convert.ConversionFailedException: Unable to convert value application/xml from type 'java.lang.String' to type 'org.springframework.http.MediaType'; nested exception is org.springframework.core.convert.ConversionFailedException: Unable to convert value application/xml from type 'java.lang.String' to type 'org.springframework.http.MediaType'; nested exception is java.lang.reflect.InvocationTargetException at org.springframework.core.convert.support.ConversionUtils.invokeConverter(ConversionUtils.java:40) at org.springframework.core.convert.support.GenericConversionService.convert(GenericConversionService.java:138) at org.springframework.beans.TypeConverterDelegate.convertIfNecessary(TypeConverterDelegate.java:201) at org.springframework.beans.TypeConverterDelegate.convertIfNecessary(TypeConverterDelegate.java:155) at org.springframework.beans.BeanWrapperImpl.convertForProperty(BeanWrapperImpl.java:461) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.convertForProperty(AbstractAutowireCapableBeanFactory.java:1363) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1322) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1076) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:517) ... 31 more Caused by: org.springframework.core.convert.ConversionFailedException: Unable to convert value application/xml from type 'java.lang.String' to type 'org.springframework.http.MediaType'; nested exception is java.lang.reflect.InvocationTargetException at org.springframework.core.convert.support.ObjectToObjectConverter.convert(ObjectToObjectConverter.java:82) at org.springframework.core.convert.support.ConversionUtils.invokeConverter(ConversionUtils.java:37) ... 39 more Caused by: java.lang.reflect.InvocationTargetException at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39) at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27) at java.lang.reflect.Constructor.newInstance(Constructor.java:501) at org.springframework.core.convert.support.ObjectToObjectConverter.convert(ObjectToObjectConverter.java:70) ... 40 more Caused by: java.lang.IllegalArgumentException: Invalid token character '/' in token "application/xml" at org.springframework.http.MediaType.checkToken(MediaType.java:286) at org.springframework.http.MediaType.<init>(MediaType.java:257) at org.springframework.http.MediaType.<init>(MediaType.java:207) at org.springframework.http.MediaType.<init>(MediaType.java:196) ... 45 more {noformat} With disabled ConversionService, the value will be converted by MediaTypeEditor, which uses the MediaType.parseMediaType method. I think the behauvior should be the same like mediaTypes-parameter map (ContentNegotiatingViewResolver), where Strings must be used. Example spring config: {code:xml} <bean id="contentNegotiatingViewResolver" class="org.springframework.web.servlet.view.ContentNegotiatingViewResolver"> <property name="defaultContentType" value="application/xml"/> <property name="mediaTypes"> <map> <entry key="xml" value="application/xml" /> <entry key="json" value="application/json" /> </map> </property> </bean> {code}

    Spring JIRA | 6 years ago | Gerrit Brehmer
    org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'contentNegotiatingViewResolver' defined in ServletContext resource [/WEB-INF/app-servlet.xml]: Initialization of bean failed; nested exception is org.springframework.core.convert.ConversionFailedException: Unable to convert value application/xml from type 'java.lang.String' to type 'org.springframework.http.MediaType'; nested exception is org.springframework.core.convert.ConversionFailedException: Unable to convert value application/xml from type 'java.lang.String' to type 'org.springframework.http.MediaType'; nested exception is java.lang.reflect.InvocationTargetException
  3. 0

    Spring 3.0.1 Release Media Type issue - Spring Team - Spring Forum

    spring.io | 8 months ago
    java.lang.IllegalArgumentException: Invalid token character '/' in token "text/html"
  4. Speed up your debug routine!

    Automated exception search integrated into your IDE

  5. 0

    Content-Type request header issue under Chrome - SmartClient Forums

    smartclient.com | 8 months ago
    java.lang.IllegalArgumentException: Invalid token character ',' in token "xml, application/json"

    Not finding the right solution?
    Take a tour to get the most out of Samebug.

    Tired of useless tips?

    Automated exception search integrated into your IDE

    Root Cause Analysis

    1. java.lang.IllegalArgumentException

      Invalid token character '/' in token "application/xml"

      at org.springframework.http.MediaType.checkToken()
    2. Spring
      MediaType.<init>
      1. org.springframework.http.MediaType.checkToken(MediaType.java:286)
      2. org.springframework.http.MediaType.<init>(MediaType.java:257)
      3. org.springframework.http.MediaType.<init>(MediaType.java:207)
      4. org.springframework.http.MediaType.<init>(MediaType.java:196)
      4 frames
    3. Java RT
      Constructor.newInstance
      1. sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
      2. sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
      3. sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
      4. java.lang.reflect.Constructor.newInstance(Constructor.java:501)
      4 frames
    4. Spring Core
      GenericConversionService.convert
      1. org.springframework.core.convert.support.ObjectToObjectConverter.convert(ObjectToObjectConverter.java:70)
      2. org.springframework.core.convert.support.ConversionUtils.invokeConverter(ConversionUtils.java:37)
      3. org.springframework.core.convert.support.GenericConversionService.convert(GenericConversionService.java:138)
      3 frames
    5. Spring Beans
      DefaultListableBeanFactory.preInstantiateSingletons
      1. org.springframework.beans.TypeConverterDelegate.convertIfNecessary(TypeConverterDelegate.java:201)
      2. org.springframework.beans.TypeConverterDelegate.convertIfNecessary(TypeConverterDelegate.java:155)
      3. org.springframework.beans.BeanWrapperImpl.convertForProperty(BeanWrapperImpl.java:461)
      4. org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.convertForProperty(AbstractAutowireCapableBeanFactory.java:1363)
      5. org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1322)
      6. org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1076)
      7. org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:517)
      8. org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:456)
      9. org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:291)
      10. org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222)
      11. org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:288)
      12. org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:190)
      13. org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:563)
      13 frames
    6. Spring Context
      AbstractApplicationContext.refresh
      1. org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:872)
      2. org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:423)
      2 frames
    7. Spring MVC
      HttpServletBean.init
      1. org.springframework.web.servlet.FrameworkServlet.createWebApplicationContext(FrameworkServlet.java:442)
      2. org.springframework.web.servlet.FrameworkServlet.createWebApplicationContext(FrameworkServlet.java:458)
      3. org.springframework.web.servlet.FrameworkServlet.initWebApplicationContext(FrameworkServlet.java:339)
      4. org.springframework.web.servlet.FrameworkServlet.initServletBean(FrameworkServlet.java:306)
      5. org.springframework.web.servlet.HttpServletBean.init(HttpServletBean.java:127)
      5 frames
    8. JavaServlet
      GenericServlet.init
      1. javax.servlet.GenericServlet.init(GenericServlet.java:212)
      1 frame
    9. Glassfish Core
      Catalina.start
      1. org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1139)
      2. org.apache.catalina.core.StandardWrapper.load(StandardWrapper.java:966)
      3. org.apache.catalina.core.StandardContext.loadOnStartup(StandardContext.java:3996)
      4. org.apache.catalina.core.StandardContext.start(StandardContext.java:4266)
      5. org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1014)
      6. org.apache.catalina.core.StandardHost.start(StandardHost.java:736)
      7. org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1014)
      8. org.apache.catalina.core.StandardEngine.start(StandardEngine.java:443)
      9. org.apache.catalina.core.StandardService.start(StandardService.java:448)
      10. org.apache.catalina.core.StandardServer.start(StandardServer.java:700)
      11. org.apache.catalina.startup.Catalina.start(Catalina.java:552)
      11 frames
    10. Java RT
      Method.invoke
      1. sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      2. sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
      3. sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
      4. java.lang.reflect.Method.invoke(Method.java:592)
      4 frames
    11. Glassfish Core
      Bootstrap.main
      1. org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:295)
      2. org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:433)
      2 frames