Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <blockquote> <p>1) Define Maintainer class as a Spring bean.</p> </blockquote> <p>Standard Spring syntax applies:</p> <pre><code>&lt;bean id="maintainer" class="com.example.Maintainer"/&gt; </code></pre> <blockquote> <p>2) Make it so that all sorts of listeners would be able to register themselves to Maintainer via XML by using addListener method. Spring doc nor Google are very generous in examples.</p> </blockquote> <p>This is trickier. You <em>could</em> use <code>MethodInvokingFactoryBean</code> to individually call <code>maintainer#addListener</code>, like so:</p> <pre><code>&lt;bean id="listener" class="com.example.Listener"/&gt; &lt;bean id="maintainer.addListener" class="org.springframework.beans.factory.config.MethodInvokingFactoryBean"&gt; &lt;property name="targetObject" ref="maintainer"/&gt; &lt;property name="targetMethod" value="addListener"/&gt; &lt;property name="arguments"&gt; &lt;list&gt; &lt;ref&gt;listener&lt;/ref&gt; &lt;value&gt;com.example.MyEnum&lt;/value&gt; &lt;/list&gt; &lt;/property&gt; &lt;/bean&gt; </code></pre> <p>However, this is unwieldy, and potentially error-prone. I attempted something similar on a project, and created a Spring utility class to help out instead. I don't have the source code available at the moment, so I'll describe how to implement what I did. </p> <p>1) Refactor the event types listened to into a <code>MyListener</code> interface</p> <pre><code>public interface MyListener extends Listener { public Enum[] getEventTypes() } </code></pre> <p>Which changes the registration method to</p> <pre><code>public void addListener(MyListener listener) </code></pre> <p>2) Create Spring helper class that finds all relevant listeners in the context, and calls maintainer#addListener for each listener found. I would start with <code>BeanFilteringSupport</code>, and also implement <code>BeanPostProcessor</code> (or <code>ApplicationListener</code>) to register the beans after all beans have been instantiated.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload