Google Guice
is a dependency injection framework that you can use with an
Endpoints Frameworks v2 project to configure servlet mapping and filtering
programmatically in Java, rather than in
web.xml
.
To use Guice, you need to add the following prepackaged dependency to your
pom.xml
or build.gradle
. Also, you need to configure the
Endpoints Frameworks plugins for Maven and Gradle to define which
service classes the plugins use to create OpenAPI documents.
Maven
Gradle
Next, you need to update web.xml
to direct all traffic from /_ah/api/*
to the Endpoints Frameworks Guice Servlet.
Implement the listener class in your project. It should look similar to the following depending on the number of services:
The listener class creates a new injector that handles servlet mapping and
filtering, which is normally defined by the web.xml
, but instead is now
defined by the EchoEndpointModule class defined as:
What's next?
- Write and annotate your backend API code
- Learn more about annotations
- Add API management
- Deploy and test your API
- Learn more about supported parameter and return types