<p dir="auto"><strong><a href="https://jira.spring.io/secure/ViewProfile.jspa?name=david_syer" rel="nofollow">Dave Syer</a></strong> opened <strong><a href="https://jira.spring.io/browse/SPR-7192?redirect=false" rel="nofollow">SPR-7192</a></strong> and commented</p>
<p dir="auto">Example from Chris's DIStyles presentation:</p>
<p dir="auto">AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(TellerUI.class, InMemoryAccountRepository.class, TransferServiceImpl.class, FlatFeePolicy.class);<br>
TransferService transferService = context.getBean(TransferService.class);</p>
<p dir="auto">This works fine now if all the types have explicitly <code class="notranslate">@Autowired</code> constructors, it would be great if those components could just be autowirable (implicitly).  All we would need would be to optimistically register a bean definition for any class where we don't find explicit <code class="notranslate">@Autowired</code> instructions.</p>
<hr>
<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="398172524" data-permission-text="Title is private" data-url="https://github.com/spring-projects/spring-framework/issues/16883" data-hovercard-type="issue" data-hovercard-url="/spring-projects/spring-framework/issues/16883/hovercard" href="https://github.com/spring-projects/spring-framework/issues/16883">#16883</a> Make <code class="notranslate">@Autowired</code> optional on a single constructor of a class decorated with <code class="notranslate">@Component</code> (<em><strong>"duplicates"</strong></em>)</li>
</ul>
<p dir="auto">1 votes, 2 watchers</p>
<p dir="auto"><strong><a href="https://jira.spring.io/secure/ViewProfile.jspa?name=wim_dc" rel="nofollow">Wim De Clercq</a></strong> opened <strong><a href="https://jira.spring.io/browse/SPR-9646?redirect=false" rel="nofollow">SPR-9646</a></strong> and commented</p>
<p dir="auto">Using "RedirectAttributes flash"<br>
and<br>
flash.addFlashAttribute("flash_msg", "letter");</p>
<p dir="auto">Can sometimes cause this flashmap to somehow get a bit buggy and only make the attribute available after the 2nd redirect / request.</p>
<p dir="auto">This bug is reproducable by doing the following:<br>
You need a double submit to a controller which will add to the flashmap.<br>
(I use fiddler2 to block 2 requests, and then send them simultaniously)</p>
<p dir="auto">The controller will:<br>
1st request: add something to flashmap and return "redirect:/whatever";<br>
2nd request: add something to flashmap and return "viewname" (no redirect);</p>
<p dir="auto">It's a bit of a thread race, but usually the 2nd is later, and your browser will not redirect from the 1st request, but instead show the page of the 2nd.</p>
<p dir="auto">From that moment, the flashmap is lagging 1 request behind for me.</p>
<p dir="auto">I've added a small test project which will cause the bug to happen for me:<br>
In essence, the JSP is:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="&lt;c:if test=&quot;${not empty flash_msg}&quot;&gt;
    &lt;strong&gt;&lt;c:out value=&quot;${flash_msg}&quot;/&gt;&lt;/strong&gt;
&lt;/c:if&gt;"><pre class="notranslate"><code class="notranslate">&lt;c:if test="${not empty flash_msg}"&gt;
    &lt;strong&gt;&lt;c:out value="${flash_msg}"/&gt;&lt;/strong&gt;
&lt;/c:if&gt;
</code></pre></div>
<p dir="auto">Controller is straightforward, and it will do what I've just said to reproduce the problem (new2 method): 1st request&gt; redirect, 2nd request show page.</p>
<div class="highlight highlight-source-java notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="@Controller
@RequestMapping(value = &quot;/messages&quot;)
public class MessageController {
	boolean beenThere = false;

	@RequestMapping(method = RequestMethod.GET)
	public ModelAndView doGet(ModelAndView mav) {
		mav.setViewName(&quot;display-message&quot;);
		return mav;
	}

	@RequestMapping(value=&quot;/new&quot;, method = RequestMethod.POST)
	public ModelAndView createNewMessage(ModelAndView mav, RedirectAttributes flash) {
		flash.addFlashAttribute(&quot;flash_msg&quot;, &quot;number&quot;);
		mav.setViewName(&quot;redirect:/messages&quot;);
		return mav;
	}

	@RequestMapping(value=&quot;/new2&quot;, method = RequestMethod.POST)
	public ModelAndView createNewMessage2(ModelAndView mav, RedirectAttributes flash) {
		flash.addFlashAttribute(&quot;flash_msg&quot;, &quot;letter&quot;);
		if(!beenThere){
			mav.setViewName(&quot;redirect:/messages&quot;);
		} else {
			mav.setViewName(&quot;display-message&quot;);
		}
		beenThere = !beenThere;
		return mav;
	}
}"><pre class="notranslate"><span class="pl-c1">@</span><span class="pl-c1">Controller</span>
<span class="pl-c1">@</span><span class="pl-c1">RequestMapping</span>(<span class="pl-s1">value</span> = <span class="pl-s">"/messages"</span>)
<span class="pl-k">public</span> <span class="pl-k">class</span> <span class="pl-smi">MessageController</span> {
	<span class="pl-smi">boolean</span> <span class="pl-s1">beenThere</span> = <span class="pl-c1">false</span>;

	<span class="pl-c1">@</span><span class="pl-c1">RequestMapping</span>(<span class="pl-s1">method</span> = <span class="pl-smi">RequestMethod</span>.<span class="pl-c1">GET</span>)
	<span class="pl-k">public</span> <span class="pl-smi">ModelAndView</span> <span class="pl-en">doGet</span>(<span class="pl-smi">ModelAndView</span> <span class="pl-s1">mav</span>) {
		<span class="pl-s1">mav</span>.<span class="pl-en">setViewName</span>(<span class="pl-s">"display-message"</span>);
		<span class="pl-k">return</span> <span class="pl-s1">mav</span>;
	}

	<span class="pl-c1">@</span><span class="pl-c1">RequestMapping</span>(<span class="pl-s1">value</span>=<span class="pl-s">"/new"</span>, <span class="pl-s1">method</span> = <span class="pl-smi">RequestMethod</span>.<span class="pl-c1">POST</span>)
	<span class="pl-k">public</span> <span class="pl-smi">ModelAndView</span> <span class="pl-en">createNewMessage</span>(<span class="pl-smi">ModelAndView</span> <span class="pl-s1">mav</span>, <span class="pl-smi">RedirectAttributes</span> <span class="pl-s1">flash</span>) {
		<span class="pl-s1">flash</span>.<span class="pl-en">addFlashAttribute</span>(<span class="pl-s">"flash_msg"</span>, <span class="pl-s">"number"</span>);
		<span class="pl-s1">mav</span>.<span class="pl-en">setViewName</span>(<span class="pl-s">"redirect:/messages"</span>);
		<span class="pl-k">return</span> <span class="pl-s1">mav</span>;
	}

	<span class="pl-c1">@</span><span class="pl-c1">RequestMapping</span>(<span class="pl-s1">value</span>=<span class="pl-s">"/new2"</span>, <span class="pl-s1">method</span> = <span class="pl-smi">RequestMethod</span>.<span class="pl-c1">POST</span>)
	<span class="pl-k">public</span> <span class="pl-smi">ModelAndView</span> <span class="pl-en">createNewMessage2</span>(<span class="pl-smi">ModelAndView</span> <span class="pl-s1">mav</span>, <span class="pl-smi">RedirectAttributes</span> <span class="pl-s1">flash</span>) {
		<span class="pl-s1">flash</span>.<span class="pl-en">addFlashAttribute</span>(<span class="pl-s">"flash_msg"</span>, <span class="pl-s">"letter"</span>);
		<span class="pl-k">if</span>(!<span class="pl-s1">beenThere</span>){
			<span class="pl-s1">mav</span>.<span class="pl-en">setViewName</span>(<span class="pl-s">"redirect:/messages"</span>);
		} <span class="pl-k">else</span> {
			<span class="pl-s1">mav</span>.<span class="pl-en">setViewName</span>(<span class="pl-s">"display-message"</span>);
		}
		<span class="pl-s1">beenThere</span> = !<span class="pl-s1">beenThere</span>;
		<span class="pl-k">return</span> <span class="pl-s1">mav</span>;
	}
}</pre></div>
<p dir="auto">So if I click button "number", I end up at "new" method, and "number" appears on my screen.</p>
<p dir="auto">HOWEVER, after new2 is called twice with a double submit, I expect that if I click on the "number", "number" will be displayed on the page. But instead "letter" is displayed. And on the next request "number" is in the scope. So basically my flash scope has turned into a scope which makes attributes available for the 2nd request.</p>
<p dir="auto">I attached the war from this project, and a zip of the project.<br>
No weird configurations are used as far as I can tell.</p>
<p dir="auto">—</p>
<p dir="auto">Wim De Clercq</p>
<hr>
<p dir="auto"><strong>Affects:</strong> 3.1.1</p>
<p dir="auto"><strong>Attachments:</strong></p>
<ul dir="auto">
<li><a href="https://jira.spring.io/secure/attachment/20129/flashmessage.war" rel="nofollow">flashmessage.war</a> (<em>3.49 MB</em>)</li>
<li><a href="https://jira.spring.io/secure/attachment/20130/SpringTest.zip" rel="nofollow">SpringTest.zip</a> (<em>5.47 kB</em>)</li>
</ul>
<p dir="auto"><strong>Referenced from:</strong> commits <a class="commit-link" data-hovercard-type="commit" data-hovercard-url="https://github.com/spring-attic/spring-framework-issues/commit/7c4ddd5a55947285c6195cd39e52f632d55ef4f3/hovercard" href="https://github.com/spring-attic/spring-framework-issues/commit/7c4ddd5a55947285c6195cd39e52f632d55ef4f3">spring-attic/spring-framework-issues@<tt>7c4ddd5</tt></a></p>