<p dir="auto"><strong><a href="https://jira.spring.io/secure/ViewProfile.jspa?name=raykrueger" rel="nofollow">Ray Krueger</a></strong> opened <strong><a href="https://jira.spring.io/browse/SPR-1743?redirect=false" rel="nofollow">SPR-1743</a></strong> and commented</p>
<p dir="auto">The current hibernate3.LocalSessionFactoryBean does not allow for multiple listeners of the same type. There is no means to assign multiple PostLoadEventListeners to the "post-load" event type. Currently the setListners method takes a map that is defined as a Map of &lt;eventListenerType, Listener&gt;.</p>
<p dir="auto">I propose changing the eventListeners configuration block to check to see if the entry value is a list...</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="    if (eventListeners != null) {

        Set entries = eventListeners.entrySet();
        for (Iterator iterator = entries.iterator(); iterator.hasNext();) {
            Map.Entry entry = (Map.Entry) iterator.next();
            String listenerType = (String) entry.getKey();
            Object value = entry.getValue();
            if (value instanceof List) {
                List list = ((List) value);
                Class clazz = config.getEventListeners().getListenerClassFor(listenerType);
                Object[] listeners = (Object[]) Array.newInstance(clazz, list.size());
                listeners = list.toArray(listeners);
                config.setListeners(listenerType, listeners);
            } else {
                config.setListener(listenerType, value);
            }
        }

    }"><pre class="notranslate"><code class="notranslate">    if (eventListeners != null) {

        Set entries = eventListeners.entrySet();
        for (Iterator iterator = entries.iterator(); iterator.hasNext();) {
            Map.Entry entry = (Map.Entry) iterator.next();
            String listenerType = (String) entry.getKey();
            Object value = entry.getValue();
            if (value instanceof List) {
                List list = ((List) value);
                Class clazz = config.getEventListeners().getListenerClassFor(listenerType);
                Object[] listeners = (Object[]) Array.newInstance(clazz, list.size());
                listeners = list.toArray(listeners);
                config.setListeners(listenerType, listeners);
            } else {
                config.setListener(listenerType, value);
            }
        }

    }
</code></pre></div>
<p dir="auto">Then it is possible from the context configuration to do the following...<br>
&lt;property name="eventListeners"&gt;<br>
&lt;map&gt;<br>
&lt;entry key="post-load"&gt;<br>
&lt;list&gt;<br>
&lt;bean class="com.blah.listeners.Listener1"/&gt;<br>
&lt;bean class="com.blah.listneres.Listener2"/&gt;<br>
&lt;property name="dataSource" ref="bopDataSource"/&gt;<br>
&lt;/bean&gt;<br>
&lt;/list&gt;<br>
&lt;/entry&gt;<br>
&lt;entry key="post-commit-insert" value-ref="com.blah.MyPostInsertListener"/&gt;<br>
&lt;/map&gt;<br>
&lt;/property&gt;</p>
<hr>
<p dir="auto"><strong>Affects:</strong> 1.2.6</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="398062648" data-permission-text="Title is private" data-url="https://github.com/spring-projects/spring-framework/issues/6304" data-hovercard-type="issue" data-hovercard-url="/spring-projects/spring-framework/issues/6304/hovercard" href="https://github.com/spring-projects/spring-framework/issues/6304">#6304</a> Spring does not support setting multiple event listeners with Hibernate 3.1 (<em><strong>"duplicates"</strong></em>)</li>
</ul>
<p dir="auto"><strong><a href="https://jira.spring.io/secure/ViewProfile.jspa?name=cbeams" rel="nofollow">Chris Beams</a></strong> opened <strong><a href="https://jira.spring.io/browse/SPR-5529?redirect=false" rel="nofollow">SPR-5529</a></strong> and commented</p>
<p dir="auto">In alignment with Java 5 style and migration of JavaConfig features into core, support the following signature on the BeanFactory interface:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="&lt;T&gt; T getBean(Class&lt;T&gt; requiredType) throws BeansException;"><pre class="notranslate"><code class="notranslate">&lt;T&gt; T getBean(Class&lt;T&gt; requiredType) throws BeansException;
</code></pre></div>
<p dir="auto">This will need to be implemented by the following classes:</p>
<p dir="auto">AbstractBeanFactory<br>
SimpleJndiBeanFactory<br>
StaticListableBeanFactory<br>
AbstractApplicationContext</p>
<p dir="auto">There are also several locations throughout the Spring test codebase that call getBean(null).  These calls will have to be disambiguated as getBean((String)null).</p>
<p dir="auto">With the above in mind, the addition of getBean(Class&lt;T&gt;) does introduce a minor backward compatibility issue for anyone calling getBean(null).  Given that this is extremely unlikely (because it's meaningless to do so), it's probably not a significant concern.</p>
<p dir="auto">Implementation approach:</p>
<p dir="auto">Apply logic similar to that in getBeansOfType(), iterating through all beans, building up a collection of beans that match the given 'requiredType' parameter.  If the resulting list contains exactly one bean, return it.  If the list contains zero beans, throw a NoSuchBeanDefinitionException.  If the list contains more than one matching bean, throw a BeansException specific to the issue.  No suitable BeansException currently exists for this, so a suggestion would be 'AmbiguousBeanLookupException extends BeansException' with an appropriate error message, something to the effect of: "3 beans match requested type com.acme.Foo.  Consider using getBean(String, Class&lt;T&gt;) to disambiguate.  Matching bean names are: ['foo1', 'foo2', 'foo3']</p>
<p dir="auto">Qualified access by type:</p>
<p dir="auto">Currently we're supporting &lt;T&gt; T getBean(String, Class&lt;T&gt;).  This is a qualification-by-bean-name scenario.  We may also want to support qualification-by-<code class="notranslate">@Qualifier</code>.  Haven't given much thought to this, but something to the effect of:</p>
<p dir="auto">&lt;T&gt; T getBean(Class&lt;? extends Annotation&gt; qualifier, Class&lt;T&gt; requiredType)</p>
<p dir="auto">Such that a client can define two classes of the same supertype:</p>
<p dir="auto"><code class="notranslate">@Production</code><br>
<code class="notranslate">@Service</code><br>
public XyzCustomerService implements CustomerService { ... }</p>
<p dir="auto"><code class="notranslate">@Testing</code><br>
<code class="notranslate">@Service</code><br>
public TestCustomerService implements CustomerService { ... }</p>
<p dir="auto">Where <code class="notranslate">@Production</code> and <code class="notranslate">@Testing</code> are both meta-annotated as <code class="notranslate">@Qualifier</code></p>
<p dir="auto">The user can then register bean definitions for both classes and access the production instance as follows:</p>
<p dir="auto">ApplicationContext ctx = ...<br>
CustomerService productionInstance = ctx.getBean(Production.class, CustomerService.class);</p>
<p dir="auto">The latter portion of this issue may well be moved to an issue all its own.  Just including it here for completeness &amp; concision.</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="398065576" data-permission-text="Title is private" data-url="https://github.com/spring-projects/spring-framework/issues/6649" data-hovercard-type="issue" data-hovercard-url="/spring-projects/spring-framework/issues/6649/hovercard" href="https://github.com/spring-projects/spring-framework/issues/6649">#6649</a> Support beanFactory.getBean(Bar.class) signature to instantiate a bean. (<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="398094525" data-permission-text="Title is private" data-url="https://github.com/spring-projects/spring-framework/issues/10353" data-hovercard-type="issue" data-hovercard-url="/spring-projects/spring-framework/issues/10353/hovercard" href="https://github.com/spring-projects/spring-framework/issues/10353">#10353</a> Provide dedicated ApplicationContext implementations for use with (JavaConfig) <code class="notranslate">@Configuration</code> classes</li>
</ul>