title: Spring 4 + @ControllerAdvice: Jsonp support for ResponseBody causes Deployment Exception?
body: <p>I am adding JSONP support to a REST Service in SPRING4 + JDK 8 + STS 3.6.4</p>
  
  <p>Versions:
  Spring 4.1.6.RELEASE</p>
  
  <p>My implementation is based on these links:
  <a href="http://docs.spring.io/spring/docs/current/spring-framework-reference/htmlsingle/#mvc-ann-jsonp" rel="nofollow">http://docs.spring.io/spring/docs/current/spring-framework-reference/htmlsingle/#mvc-ann-jsonp</a></p>
  
  <p>The REST service returns ResponseEntity or ResponseBody and use case is to return data in JSONP format.</p>
  
  <p>Added a ControllerAdvice</p>
  
  <pre><code>@ControllerAdvice
  public class JsonpCallbackAdvice extends AbstractJsonpResponseBodyAdvice {
  
      public JsonpCallbackAdvice(){
         super("Callback");
      }
  }
  </code></pre>
  
  <p>Here is the Controller of the REST Service</p>
  
  <pre><code>@Controller
  public class AcctController {
   ...
     @RequestMapping(value = "/act/{actNum}", method = RequestMethod.GET)
  public ResponseEntity&lt;Account&gt; getAccount(@PathVariable("actNum") Integer accountNum) throws Exception {
  ...
  return new ResponseEntity&lt;account&gt;();
  }
  </code></pre>
  
  <p>Here is the relevant web application context configuration</p>
  
  <pre><code>...
   &lt;context:component-scan base-package="com.controllers" /&gt;
  &lt;bean name="jsonMessageConverter"
  class="org.springframework.http.converter.json.MappingJackson2HttpMessageConverter" /&gt;
  ...
  </code></pre>
  
  <p>The controller and ControllerAdvice are in same package.</p>
  
  <p>When deployment of the project is initiated following exception is observed</p>
  
  <pre><code> Caused by: java.lang.ClassCastException: [Ljava.lang.String; cannot be cast to java.lang.String
  at org.springframework.context.annotation.AnnotationBeanNameGenerator.determineBeanNameFromAnnotation(AnnotationBeanNameGenerator.java:91)
  at org.springframework.context.annotation.AnnotationBeanNameGenerator.generateBeanName(AnnotationBeanNameGenerator.java:69)
  at org.springframework.context.annotation.ClassPathBeanDefinitionScanner.doScan(ClassPathBeanDefinitionScanner.java:246)
  at org.springframework.context.annotation.ComponentScanBeanDefinitionParser.parse(ComponentScanBeanDefinitionParser.java:84)
  at org.springframework.beans.factory.xml.NamespaceHandlerSupport.parse(NamespaceHandlerSupport.java:74)
  at org.springframework.beans.factory.xml.BeanDefinitionParserDelegate.parseCustomElement(BeanDefinitionParserDelegate.java:1427)
  at org.springframework.beans.factory.xml.BeanDefinitionParserDelegate.parseCustomElement(BeanDefinitionParserDelegate.java:1417)
  at org.springframework.beans.factory.xml.DefaultBeanDefinitionDocumentReader.parseBeanDefinitions(DefaultBeanDefinitionDocumentReader.java:174)
  at org.springframework.beans.factory.xml.DefaultBeanDefinitionDocumentReader.doRegisterBeanDefinitions(DefaultBeanDefinitionDocumentReader.java:144)
  at org.springframework.beans.factory.xml.DefaultBeanDefinitionDocumentReader.registerBeanDefinitions(DefaultBeanDefinitionDocumentReader.java:100)
  at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.registerBeanDefinitions(XmlBeanDefinitionReader.java:510)
  at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.doLoadBeanDefinitions(XmlBeanDefinitionReader.java:392)
  </code></pre>
  
  <p>This exception was not happening before the ControllerAdvice was added.
  Also, it does not happens when @ControllerAdvice annotation is removed
  or
  the component scan excludes scanning package of the ControllerAdvice class</p>
  
  <p>I tried with Spring version 4.2.0.RC1, and the exception still happens.</p>
  
  <p>Kindly help with resolution of this exception, since not much help is available online. 
  It seems like a bug in SPRING 4, however am not sure.</p>