Spring boot: Add new endpoints at runtime

2019-07-23 13:40发布

I'm working on a feature to allow a spring boot application to have 'plugins'. This means that without new builds, the application should be able to integrate new pieces of code.

The dynamic class loading is ok, however, for each new 'plugin' I need to add a new rest endpoint. I know some libraries are able to add new endpoints in a spring boot application (like netflix zuul and spring-fox), so I think this is possible.

I think a way to do that is overriding the spring's 'mapping resolver' and resolving the 'extra' mappings without using the annotations. I took a look and seems like the class RequestMappingHandlerMapping is responsible to resolve the spring mappings, however, I do not know what I should override there.

Of course I may do this using wildcard in a controller, however, I'm trying to find a more elegant approach.

Any example of how can I add new endpoints on the fly?

0条回答
登录 后发表回答