API to scan for annotations?

We would like to package parts of our application as “add-ons” or “plugins”. The add-ons would be packaged as JAR files that we load dynamically at runtime. These add-ons might include additional views which require new Routes.

My question is - is there an API to invoke @Route annotation scanning on a dynamically loaded JAR or package? I know that the Route configuration can be modified directly using API calls, but it would make add-on development simpler if we could use the @Route annotation in our add-on classes.

If you use Spring Boot it might be enough to use @EnableVaadin(value=other.package, main.package) so that your add-ons are also scanned for Route annotations

1 Like

I’m interested in hearing if you manage to get that working.

If you are using Spring Boot, then you can use Spring API’s for this.

Inject ApplicationContext to your utility bean and you can find annotated beans

In my demo those are not routes, but you can use the same approach.

You just need to ensure these are managed beans. I would not use @Route annotation in this use case, but create custom annotation for this purpose. And I would register routes programmatically for the found beans.

We ultimately ended up going a different direction with this. We’re modifying the web application’s classpath to get the add-on jars installed before the web app starts, so now there’s no need for extra annotation scanning.