<p dir="auto"><strong><a href="https://jira.spring.io/secure/ViewProfile.jspa?name=youngm" rel="nofollow">Mike Youngstrom</a></strong> opened <strong><a href="https://jira.spring.io/browse/SPR-3370?redirect=false" rel="nofollow">SPR-3370</a></strong> and commented</p>
<p dir="auto">There are cases where PersistenceAnnotationBeanPostProcessor doesn't find lazy loaded EMFs.  I think it's because in findNamedEntityManagerFactory it uses beanFactory.isTypeMatch() to find EMFs that implement EntityManagerFactoryInfo and isTypeMatch() only matches cached singletons.</p>
<p dir="auto">This is probably a known limitation so it may only require a documentation mention in PersistenceAnnotationBeanPostProcessor.</p>
<p dir="auto">For anyone experiencing this problem the solution is to just make your EMF non lazy.</p>
<p dir="auto">Mike</p>
<hr>
<p dir="auto"><strong>Affects:</strong> 2.0.4</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="398077649" data-permission-text="Title is private" data-url="https://github.com/spring-projects/spring-framework/issues/8117" data-hovercard-type="issue" data-hovercard-url="/spring-projects/spring-framework/issues/8117/hovercard" href="https://github.com/spring-projects/spring-framework/issues/8117">#8117</a> PersistenceAnnotationBeanPostProcessor fails to find EMFBs (<em><strong>"is duplicated by"</strong></em>)</li>
</ul>
<p dir="auto"><strong><a href="https://jira.spring.io/secure/ViewProfile.jspa?name=prickus" rel="nofollow">Osvaldas Grigas</a></strong> opened <strong><a href="https://jira.spring.io/browse/SPR-8269?redirect=false" rel="nofollow">SPR-8269</a></strong> and commented</p>
<p dir="auto">When using AnnotationConfigApplicationContext, if I declare at least one <code class="notranslate">@Bean</code> of type BeanFactoryPostProcessor (even if it's a stub that doesn't do anything), this breaks default post-processing of the <code class="notranslate">@Configuration</code> bean, meaning that <code class="notranslate">@Autowired</code> fields are no longer injected, <code class="notranslate">@PostConstruct</code> methods are not called, etc.</p>
<p dir="auto">I'm attaching a test case to prove my point.</p>
<p dir="auto">A workaround is to manually add the relevant BeanPostProcessors (like AutowiredAnnotationBeanPostProcessor and CommonAnnotationBeanPostProcessor) to BeanFactory.</p>
<p dir="auto">Same thing happens in web app when I use ContextLoaderInitializer to load <code class="notranslate">@Configuration</code> classes or define them through XML config. My particular case is that I use MyBatis-Spring integration and I cannot declare a <code class="notranslate">@Bean</code> of type org.mybatis.spring.mapper.MapperScannerConfigurer using annotation config, because this bean is a BeanFactoryPostProcessor and thus breaks autowiring of <code class="notranslate">@Configuration</code> class.</p>
<hr>
<p dir="auto"><strong>Affects:</strong> 3.1 M1</p>
<p dir="auto"><strong>Attachments:</strong></p>
<ul dir="auto">
<li><a href="https://jira.spring.io/secure/attachment/19013/org.mybatis.spring.sample.zip" rel="nofollow">org.mybatis.spring.sample.zip</a> (<em>8.37 kB</em>)</li>
<li><a href="https://jira.spring.io/secure/attachment/18060/testcase.zip" rel="nofollow">testcase.zip</a> (<em>1.98 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="398111848" data-permission-text="Title is private" data-url="https://github.com/spring-projects/spring-framework/issues/12905" data-hovercard-type="issue" data-hovercard-url="/spring-projects/spring-framework/issues/12905/hovercard" href="https://github.com/spring-projects/spring-framework/issues/12905">#12905</a> <code class="notranslate">@PostConstruct</code> and PropertyPlaceholderConfigurer do not work together in AnnotationConfigApplicationContext (<em><strong>"is duplicated by"</strong></em>)</li>
<li><a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="398109541" data-permission-text="Title is private" data-url="https://github.com/spring-projects/spring-framework/issues/12525" data-hovercard-type="issue" data-hovercard-url="/spring-projects/spring-framework/issues/12525/hovercard" href="https://github.com/spring-projects/spring-framework/issues/12525">#12525</a> BeanDefinitionRegistryPostProcessor registered via <code class="notranslate">@Bean</code> will not be invoked</li>
<li><a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="398150911" data-permission-text="Title is private" data-url="https://github.com/spring-projects/spring-framework/issues/14099" data-hovercard-type="issue" data-hovercard-url="/spring-projects/spring-framework/issues/14099/hovercard" href="https://github.com/spring-projects/spring-framework/issues/14099">#14099</a> Method postProcessBeanDefinitionRegistry is not called if the bean implements BeanDefinitionRegistryPostProcessor</li>
<li><a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="398192895" data-permission-text="Title is private" data-url="https://github.com/spring-projects/spring-framework/issues/18808" data-hovercard-type="issue" data-hovercard-url="/spring-projects/spring-framework/issues/18808/hovercard" href="https://github.com/spring-projects/spring-framework/issues/18808">#18808</a> Warn about non-static BeanDefinitionRegistryPostProcessor declarations on <code class="notranslate">@Configuration</code> classes</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-projects/spring-framework/commit/52bef0b7b024e794186437dee78945fbb5bd209a/hovercard" href="https://github.com/spring-projects/spring-framework/commit/52bef0b7b024e794186437dee78945fbb5bd209a"><tt>52bef0b</tt></a></p>