Over a million developers have joined DZone.

Finally! A Web App (Part 4)

DZone's Guide to

Finally! A Web App (Part 4)

We're getting close to finishing our journey to making a Java web app. Learn how to get the pieces of your app talking to each other.

· Java Zone ·
Free Resource

Java-based (JDBC) data connectivity to SaaS, NoSQL, and Big Data. Download Now.


We are close to completing this round of applications that expose or make our in-house component or service (the Shape Calculator) available. Here is where we left off, and if you have not been following this series from the start, you'll probably want to refer back to all the previous articles, since we are going to be working with the Shape Calculator component we wish to expose.

Add Calculator Operations

Let's open the RequestResponseController, and inside the "pending()" method (the method mapped to "/pending" ), let's add the code to get back all Pending Requests from the Shape Calculator:

    List<CalculationRequest> calcReqList = this.calculator.getAllPendingRequests();

    if (null==calcReqList || calcReqList.isEmpty()) {
        return new ModelAndView(
                    "There are NO Pending CalculationRequests");

    return new ModelAndView("/pending","calcReqList",calcReqList);

Right away, my Eclipse complains. We need to inform our webapp project of the shape-calc project; go to this webapp's properties and:

Image title

(The name of the Eclipse web app project that we began with in previous articles is "webapp-dep-on-shape-calc-jpa-hibernate," but because I am writing these articles in pieces, I need to have and keep intermediate projects along the way, thus a different name)

Once we add the child project, Eclipse only complains of a missing "calculator" member, so let's add it:

    private ShapeCalculatorService calculator;

This time, no compile errors, so I do a Build.Deploy.Start (BDS)  and... I see this in the Eclipse console output:

Caused by: java.lang.ClassNotFoundException: com.eli.calc.shape.service.ShapeCalculatorService

at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1284)

at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1118)

... 30 more

I'm not going to use Eclipse's method of adding the project dependency. Rather, let's add this to the web app's POM: Our web app knows nothing of the existence of the Shape Calculator, of course, because that is a different project.






We may need to do a Maven update... and a BDS...

I checked the server, and I see this:

Image title

In the console output, I see this:

Caused by: java.net.ConnectException: Connection refused: connect
at java.net.DualStackPlainSocketImpl.waitForConnect(Native Method)

So this time, the web app project is aware of the shape-calc project, and Spring is doing its thing. However, we need our MySQL database to be up and running.

I'm going to be using Cygwin command-line terminals rather than Windows. I previously covered all this in the articles leading up to this one, so I won't go into any detail here.

Image title

Image title

OK, I think we're good now. Let's try to restart the server... and we have a clean start, and the web page tabs work.

Correcting Server Shutdown Process

When we shut down the server, though, we notice a problem. Two problems, actually.

Sep 09, 2016 11:29:43 AM org.apache.catalina.loader.WebappClassLoaderBase clearReferencesJdbc
WARNING: The web application [webapp-p3] registered the JDBC driver [com.mysql.jdbc.Driver] but failed to unregister it when the web application was stopped. To prevent a memory leak, the JDBC Driver has been forcibly unregistered.

Sep 09, 2016 11:29:43 AM org.apache.catalina.loader.WebappClassLoaderBase clearReferencesThreads
WARNING: The web application [webapp-p3] appears to have started a thread named [Abandoned connection cleanup thread] but has failed to stop it. This is very likely to create a memory leak. Stack trace of thread:
java.lang.Object.wait(Native Method)

The idea here is that when shutting down the server, we have not dealt correctly with cleaning up some resources. Let's take a side-trip from completing our web app and focus on these issues.

  1. The Shape Caculator itself uses an ExecutorService thread pool.

  2. And it also has a DataSource.

  3. And we have the MySQL driver.

We need to handle those in that same order.

Before we get to them, though, let's learn some more about how a Spring-based web app starts up and shuts down.


This is going to get a bit lengthy, and it deserves another article, so stay tuned for the next one. After we handle the topic of shutting down, we'll continue with completing the web app.

See you next time!

Connect any Java based application to your SaaS data.  Over 100+ Java-based data source connectors.

java 8 ,web application ,integration ,full stack ,iframes ,jsp ,spring mvc ,form binding methods in spring ,javascript ,mysql

Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}