This repo is a proof of concept demonstrating how to invoke multiple entry points using popular dependency injection frameworks such as Spring, Micronaut, and Guice with Java Spark. Follow the steps below to complete the demonstrations.
cd
to the project's root directory.- Run
mvn clean install
.
cd
to the project's root directory.- Run
export ALTERNATIVE_ENTRY_POINT=periodicRun && export AMOUNT_TO_TAX=10
. - Run
java -cp ./target/multiple-entry-points-with-dependency-injection-1.0-SNAPSHOT.jar com.amazon.spring.SpringBootEntryPoint
. You should seeTax is 0.7
among the output and the Spring app and JVM should exit. - Run
unset ALTERNATIVE_ENTRY_POINT && unset AMOUNT_TO_TAX
. - Run
java -cp ./target/multiple-entry-points-with-dependency-injection-1.0-SNAPSHOT.jar com.amazon.spring.SpringBootEntryPoint
again. - Open another terminal and run
curl http://localhost:8080?amountToTax=10
. You should see0.7
as the output. - Close the app by pressing Ctrl+C.
cd
to the project's root directory.- Run
export ALTERNATIVE_ENTRY_POINT=periodicRun && export AMOUNT_TO_TAX=10
. - Run
java -cp ./target/multiple-entry-points-with-dependency-injection-1.0-SNAPSHOT.jar com.amazon.micronaut.MicronautEntryPoint
. You should seeTax is 0.7
among the output and the Micronaut app and JVM should exit. - Run
unset ALTERNATIVE_ENTRY_POINT && unset AMOUNT_TO_TAX
. - Run
java -cp ./target/multiple-entry-points-with-dependency-injection-1.0-SNAPSHOT.jar com.amazon.micronaut.MicronautEntryPoint
again. - Open another terminal and run
curl http://localhost:8080?amountToTax=10
. You should see0.7
as the output. - Close the app by pressing Ctrl+C.
cd
to the project's root directory.- Run
export ALTERNATIVE_ENTRY_POINT=periodicRun && export AMOUNT_TO_TAX=10
. - Run
java -cp ./target/multiple-entry-points-with-dependency-injection-1.0-SNAPSHOT.jar com.amazon.guice.GuiceEntryPoint
. You should seeTax is 0.7
among the output and the Guice and Java Spark app and JVM should exit. - Run
unset ALTERNATIVE_ENTRY_POINT && unset AMOUNT_TO_TAX
. - Run
java -cp ./target/multiple-entry-points-with-dependency-injection-1.0-SNAPSHOT.jar com.amazon.guice.GuiceEntryPoint
again. - Open another terminal and run
curl http://localhost:8080?amountToTax=10
. You should see0.7
as the output. - Close the app by pressing Ctrl+C.
Note: In order to complete the steps below, you will need a Kubernetes cluster. One of the simplest solutions is, if you have Docker Desktop, you can enable a local Kubernetes cluster. Follow these directions to do so: https://docs.docker.com/desktop/kubernetes/#enable-kubernetes
cd
to the project's root directory.- Build the docker image by running
docker build -t "$(whoami)"/multiple-entry-points:local .
. - Run
docker images
. You should see the image in the output. - Run
k8s/replace_username.sh k8s/cronjob.yml | kubectl apply -f -
to create the Kubernetes CronJob resource that executes every 1 minute. - Run
kubectl get jobs --watch
to watch the jobs that the CronJob resource creates. - Once a job is created, get job's pod name by running
pods=$(kubectl get pods --selector=job-name={job name goes here} --output=jsonpath={.items[*].metadata.name})
. Be sure to replace the placeholder with the name of the job. For example, if the job name ismy-service-27808790
, then the command would bepods=$(kubectl get pods --selector=job-name=my-service-27808790 --output=jsonpath={.items[*].metadata.name})
. - Run
kubectl logs $pods
to see the logs of the job's pod. You should seeTax is 0.7
among the output. - Clean up the CronJob resource by running
k8s/replace_username.sh k8s/cronjob.yml | kubectl delete -f -
.
- Run
k8s/replace_username.sh k8s/pod.yml | kubectl apply -f -
to create a pod for the REST API. - Run
kubectl apply -f k8s/service.yml
to create a service that exposes the REST API pod to clients outside the Kubernetes cluster. - Run
curl http://localhost:30000?amountToTax=10
. You should see0.7
as the output. - Clean up the Service and Pod resources by running
kubectl delete -f k8s/service.yml && k8s/replace_username.sh k8s/pod.yml | kubectl delete -f -
.