- Write the WORKSPACE and BUILD files to define the compilation process and external dependencies. (The dependency declarations in the BUILD file only require the group id and artifact id.)
- Initialize a main class that contains the main method.
- Re-introduce the project using the Bazel plugin or execute the synchronization command.
- Write the classes that need to be injected (hereinafter referred to as the "classes to be injected") by using the @Inject + constructor injection method.
- Write the Module class. If there are dependencies of the same type, you can combine the @Qualifier declaration to define custom annotations. Use them in the Module class and the classes to be injected respectively to indicate the relationship between injection and being injected.
- Declare the Injector and Instance in the main class and make corresponding method calls. Finally, complete the dependency injection based on Guice.
bazel build //:app_deploy.jar
java -jar bazel-bin/app_deploy.jar