Public Repository

Last pushed: 5 months ago
Short Description
Java Spring Web Server demo + MySQL Database bindings + Thymeleaf HTML template iteration over DB
Full Description

[docker-compose.yml]

version: '2'
services:
web:
build: .
ports:

- "443:443"

======================================================================================

[dockerfile]

FROM blissnd/spring-web-server
CMD service mysql start && java -jar /home/spring/spring_test/target/gs-serving-web-content-0.1.0.jar

=====================================================================================

Usage:

docker-compose up

=====================================================================================

Point your web browser (from the host) to:

https://localhost/demo/greeting

This is a very simple example of mapping to an HTML template within the Spring framework


Put the following URL in your web browser:

https://localhost/demo/all

This is an example of using a URL route to fetch all rows from an example table in the back-end MySQL database and return to the client browser in JSON format.


Now put the following URL in your web browser:

https://localhost/demo/demo2

This is an example of pulling the rows from same back-end MySQL table into a Thymeleaf HTML template, which iterates over the Java DB model, i.e.:

<table border="1">
<tr th:each="user : ${users}">
<td th:text="${user.name}"></td>
<td th:text="${user.email}"></td>
</tr>
</table>


Now, add a new entry to the database:

https://localhost/demo/add?name=Dave&email=davey_boy@daves_pub.com

And view the result:

https://localhost/demo/demo2


To persist the database after the docker container shuts down:

docker commit <YOUR_CONTAINER_ID> blissnd/spring-web-server


Study the source code and config files in combination with the spring.io tutorials on their spring website. Here is the directory structure of the project:

-- spring_test |-- build.gradle |-- gradle |-- wrapper
| |-- gradle-wrapper.jar
| -- gradle-wrapper.properties |-- gradlew |-- gradlew.bat |-- keystore.jks |-- mvnw |-- mvnw.cmd |-- pom.xml |-- src | |-- main | | |-- java | | |-- hello
| | | |-- Application.java
| | | |-- GreetingController.java
| | | |-- User.java
| | | -- UserRepository.java | |-- resources
| | |-- application.properties
| | |-- keystore.jks
| | |-- static
| | | -- index.html | |-- templates
| | |-- greeting.html
| | -- users.html |-- test
| -- java |-- hello
| -- ApplicationTest.java-- target

Docker Pull Command
Owner
blissnd

Comments (0)