Lifecycle Hooks
Lifecycle hooks allow you to hook into lifecycle events of the servlet/resource creation and REST calls.
For example, if you want to add an initialization method to your resource:
@Rest(...)
public class MyResource extends BasicRestResource {
// Our database.
private Map myDatabase;
@RestInit
public void initMyDatabase() throws Exception {
myDatabase = new LinkedHashMap();
}
}
10.0 change
Any lifecycle snippet using RestContext.Builder / RestOpContext.Builder parameters is pre-10.0 and
kept only for historical context. Builder injection was removed; migrate to @Rest(...) / @RestOp(...)
attributes and @Bean(name="...") bean suppliers. See the
V10 Migration Guide.
Or if you want to intercept REST calls:
@Rest(...)
public class MyResource extends BasicRestResource {
// Add a request attribute to all incoming requests.
@RestPreCall
public void onPreCall(RestRequest req) {
req.setAttribute("foo", "bar");
}
}
The following lifecycle annotations are provided: