Setting up the Spring WebApplication

To start up the Spring application we need to have JDK8 and Maven installed (their environment variables need to be set up as well). After installing those we will continue to the next part.

Packaging the Application into a Jar

Navigate in your Terminal to the directory sa-webapp (repo) and type the following command:

$ maven install

This will generate a folder named target, under the directory sa-webapp, there you will find your Java Application named ‘sentiment-analysis-web-0.0.1-SNAPSHOT.jar

Starting our Java Application

Navigate to the target directory and start the application with the command:

$ java -jar sentiment-analysis-web-0.0.1-SNAPSHOT.jar

Darn it! Our application fails on startup and our only lead is the exception in the stack trace:

Error creating bean with name 'sentimentController': Injection of autowired 
dependencies failed; nested exception is java.lang.IllegalArgumentException: 
Could not resolve placeholder 'sa.loigic.api.url' in value "${sa.logic.api.url}"

The vital information here is the placeholder sa.logic.api.url in the SentimentController. Let’s check that out!

Inspecting the Code

  1. The sentiment controller has a property sa.logic.api.url, when this property get’s defined it’s value will initialize/be injected into saLogicApiUrl
  2. The object saLogicApiUrl is concatenated with the value “/analyse/sentiment” and together forming the URL to make the request for Sentiment Analysis.

In Spring the default property source is (located in sa-webapp/src/main/resources) and checking it we see that it’s empty. Hmm…! We are left to either add a value in for the property (don’t forget to rebuild the jar) or we provide it with the earlier command:

$ java -jar sentiment-analysis-web-0.0.1-SNAPSHOT.jar --sa.logic.api.url=BUT.WHAT.IS.THE.SA.LOGIC.API.URL

“BUT.WHAT.IS.THE.SA.LOGIC.API.URL??” That’s a good question and if you guessed that it cannot be anything else but the IP and Port in which our Sentiment Analysis Python application is listening for requests, then you are totally right.

Next question that pops up is “But we still didn’t start the python application up, how can we know the IP and PORT”?

We can decide preliminary on what IP and PORT we will spin up the python/flask application. If we follow our Base Architecture in figure 1 then it will be localhost:5000.

Fig. 1. SA Logic still not started on localhost:5000


So let’s let our Spring WebApp forward calls to that url:

$ java -jar sentiment-analysis-web-0.0.1-SNAPSHOT.jar --sa.logic.api.url=http://localhost:5000

Now we got to the point where we have the Nginx Server with our static files running, and the Spring WebApp running, we are left with the Flask app and we are complete. Let’s get started on the next article.

Setting up the Python Application >>
If you enjoyed the article, please share and comment below!