Issue #2754 Only instantiate listener if it will be used (#2763)

Signed-off-by: Jan Bartel <janb@webtide.com>
This commit is contained in:
Jan Bartel 2018-08-07 12:23:09 +10:00 committed by GitHub
parent 9dd2369a53
commit 88d1ead25b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 11 additions and 2 deletions

View File

@ -79,10 +79,10 @@ public class WebListenerAnnotation extends DiscoveredAnnotation
HttpSessionAttributeListener.class.isAssignableFrom(clazz) ||
HttpSessionIdListener.class.isAssignableFrom(clazz))
{
java.util.EventListener listener = (java.util.EventListener)_context.getServletContext().createInstance(clazz);
MetaData metaData = _context.getMetaData();
if (metaData.getOrigin(clazz.getName()+".listener") == Origin.NotSet)
{
java.util.EventListener listener = (java.util.EventListener)_context.getServletContext().createInstance(clazz);
ListenerHolder h = _context.getServletHandler().newListenerHolder(new Source(Source.Origin.ANNOTATION, clazz.getName()));
h.setListener(listener);
_context.getServletHandler().addListener(h);

View File

@ -62,4 +62,13 @@ public class ListenerHolder extends BaseHolder<EventListener>
super.doStart();
}
@Override
public String toString()
{
return super.toString()+(_listener == null?"":": "+getClassName());
}
}