<p dir="auto"><strong><a href="https://jira.spring.io/secure/ViewProfile.jspa?name=javachap" rel="nofollow">Vijay Dendukuri</a></strong> opened <strong><a href="https://jira.spring.io/browse/SPR-8546?redirect=false" rel="nofollow">SPR-8546</a></strong> and commented</p>
<p dir="auto">When "RequestResponseBodyMethodProcessor" is used to handle the return value (by annotating the method with <code class="notranslate">@ResponseBody</code>), the HttpMessageConverter is choosen based on request header "Accept".</p>
<p dir="auto">Please provide an ability to also choose a HttpMessageConverter based on pathExtension (similar to ContentNegotiatingViewResolver).</p>
<p dir="auto">The HtppMessageConverter is choosed in the following class now.<br>
org.springframework.web.servlet.mvc.method.annotation.support.AbstractMessageConverterMethodProcessor<br>
Method: writeWithMessageConverters</p>
<hr>
<p dir="auto"><strong>Affects:</strong> 3.0.5</p>
<p dir="auto"><strong>Issue Links:</strong></p>
<ul dir="auto">
<li><a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="398100331" data-permission-text="Title is private" data-url="https://github.com/spring-projects/spring-framework/issues/11163" data-hovercard-type="issue" data-hovercard-url="/spring-projects/spring-framework/issues/11163/hovercard" href="https://github.com/spring-projects/spring-framework/issues/11163">#11163</a> <code class="notranslate">@RequestMapping</code> should support accept header and url extension (<em><strong>"duplicates"</strong></em>)</li>
<li><a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="398112762" data-permission-text="Title is private" data-url="https://github.com/spring-projects/spring-framework/issues/13057" data-hovercard-type="issue" data-hovercard-url="/spring-projects/spring-framework/issues/13057/hovercard" href="https://github.com/spring-projects/spring-framework/issues/13057">#13057</a> Content negotiation improvements (<em><strong>"duplicates"</strong></em>)</li>
</ul>
<p dir="auto"><strong><a href="https://jira.spring.io/secure/ViewProfile.jspa?name=olivergierke" rel="nofollow">Oliver Drotbohm</a></strong> opened <strong><a href="https://jira.spring.io/browse/SPR-6671?redirect=false" rel="nofollow">SPR-6671</a></strong> and commented</p>
<p dir="auto">There is a subtle issue with <code class="notranslate">EventListener</code> handling. <code class="notranslate">EventListeners</code> are generic since Spring 3.0 and works perfectly fine in most cases. Suppose the folloeing case:</p>
<p dir="auto">You have an interface as well as an implementation. The implementation is using <code class="notranslate">@Transactional</code> for transaction demarcation <strong>and</strong> implements <code class="notranslate">EventListener&lt;ContextRefreshedEvent&gt;</code>. As there is a JDK dynamic proxy created by Spring, the reflective lookup of the event type fails, which causes Spring to assume the implementation actually declares a raw <code class="notranslate">EventListener</code> and thus also hands <code class="notranslate">ContextClosedEvent</code> e.g. which then in turn leads to a <code class="notranslate">ClassCastException</code> as the method only accepts <code class="notranslate">ContextRefreshedEvent</code> as parameter.</p>
<p dir="auto">The major problem is that I see no correct way of solving this as Spring cannot simply reject the listener instead of blindly handing all events to it. As the main issue with the current situation is, that it is not really obvious <strong>why</strong> the <code class="notranslate">ClassCastException</code> occurs, a feasible solution might be to check the inspected listener instance for implementing <code class="notranslate">Adviced</code> and log a warning if also implements <code class="notranslate">EventListener</code> <strong>and</strong> does not return the event type.</p>
<p dir="auto">Test case reproducing the issue attached.</p>
<hr>
<p dir="auto"><strong>Affects:</strong> 3.0 GA</p>
<p dir="auto"><strong>Attachments:</strong></p>
<ul dir="auto">
<li><a href="https://jira.spring.io/secure/attachment/16081/event-listener-bug.zip" rel="nofollow">event-listener-bug.zip</a> (<em>10.71 kB</em>)</li>
</ul>
<p dir="auto"><strong>Issue Links:</strong></p>
<ul dir="auto">
<li><a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="398101182" data-permission-text="Title is private" data-url="https://github.com/spring-projects/spring-framework/issues/11262" data-hovercard-type="issue" data-hovercard-url="/spring-projects/spring-framework/issues/11262/hovercard" href="https://github.com/spring-projects/spring-framework/issues/11262">#11262</a> Parameterized ApplicationListener does not work with AOP proxies (<em><strong>"duplicates"</strong></em>)</li>
</ul>