Hi all,

I have a homegrown annotation @HealthCheck that aggregates @WebListener
like this:

@Target({TYPE})
@Retention(RUNTIME)
@WebListener
public @interface HealthCheck {
...

}

The idea is that classes annotated with this, being web listeners, are
automatically instantiated in a web application. Since the HealthCheck
annotation has several attributes (check name, caching time etc.), I
cannot use the pure @WebListener annotation.

Now it looks to me as if the tomcat (I currently use 8.5.30) tries to
instantiate the annotation itself:

org.apache.catalina.core.StandardContext.listenerStart Error configuring
application listener of class [de.dimdi.util.healthcheck.HealthCheck]
 java.lang.NoSuchMethodException:
de.dimdi.util.healthcheck.HealthCheck.<init>()
        at java.lang.Class.getConstructor0(Class.java:3082)
        at java.lang.Class.getConstructor(Class.java:1825)
        at
org.apache.catalina.core.DefaultInstanceManager.newInstance(DefaultInstanceManager.java:151)
        at
org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4698)
        at
org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5240)
        at
org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
        at
org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:754)
        at
org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:730)
        at
org.apache.catalina.core.StandardHost.addChild(StandardHost.java:734)
        at
org.apache.catalina.startup.HostConfig.deployWAR(HostConfig.java:985)
        at
org.apache.catalina.startup.HostConfig$DeployWar.run(HostConfig.java:1856)
        at
java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
        at java.util.concurrent.FutureTask.run(FutureTask.java:266)
        at
java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
        at
java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
        at java.lang.Thread.run(Thread.java:748)

This leads to a failure to start the web application. My question is: Is
this a bug or a feature? It can hardly ever be intended to instantiate
an annotation (this is not possibly anyway). So

- should I file a bug report? Or ...

- is anyone aware of a mechanism to prevent certain classes from being
instantiated in tomcat? Or ...

- did I miss something that would make my approach work?

I tried already to annotate a base class (which I need anyway, so the
check can be registered) with @WebListener and derive my health checks
from this base class. Alas, @WebListener is not inherited, so this does
not work, either. The simple and obvious approach would probably be to
annotate my check with @WebListener AND @HealthCheck, but I'd like to
keep it as simple as possible for the users of this library.

Thanks for any advice and best regards,

Tarek Ahmed




---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org
For additional commands, e-mail: users-h...@tomcat.apache.org

Reply via email to