• Stars
    star
    182
  • Rank 211,154 (Top 5 %)
  • Language
    Java
  • License
    Apache License 2.0
  • Created over 7 years ago
  • Updated 4 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Simple blog web app made using Spring Boot + Thymeleaf

Spring Boot Blog Demo

About

This is a demo project for practicing Spring Boot + Thymeleaf. The idea was to build some basic blogging platform.

It was made using Spring Boot, Spring Security, Thymeleaf, Spring Data JPA, Spring Data REST and Docker. Database is in memory H2.

There is a login and registration functionality included.

User has his own blog page, where he can add new blog posts. Every authenticated user can comment on posts made by other users. Home page is paginated list of all posts. Non-authenticated users can see all blog posts, but cannot add new posts or comment.

Screenshot 1

Screenshot 1

Configuration

Configuration Files

Folder src/resources/ contains config files for blog-demo Spring Boot application.

  • src/resources/application.properties - main configuration file. Here it is possible to change admin username/password, as well as change the port number.

How to run

There are several ways to run the application. You can run it from the command line with included Maven Wrapper, Maven or Docker.

Once the app starts, go to the web browser and visit http://localhost:8090/home

Admin username: admin

Admin password: admin

User username: user

User password: password

Maven Wrapper

Using the Maven Plugin

Go to the root folder of the application and type:

$ chmod +x scripts/mvnw
$ scripts/mvnw spring-boot:run

Using Executable Jar

Or you can build the JAR file with

$ scripts/mvnw clean package

Then you can run the JAR file:

$ java -jar target/blog-demo-0.0.1-SNAPSHOT.jar

Maven

Open a terminal and run the following commands to ensure that you have valid versions of Java and Maven installed:

$ java -version
java version "1.8.0_102"
Java(TM) SE Runtime Environment (build 1.8.0_102-b14)
Java HotSpot(TM) 64-Bit Server VM (build 25.102-b14, mixed mode)
$ mvn -v
Apache Maven 3.3.9 (bb52d8502b132ec0a5a3f4c09453c07478323dc5; 2015-11-10T16:41:47+00:00)
Maven home: /usr/local/Cellar/maven/3.3.9/libexec
Java version: 1.8.0_102, vendor: Oracle Corporation

Using the Maven Plugin

The Spring Boot Maven plugin includes a run goal that can be used to quickly compile and run your application. Applications run in an exploded form, as they do in your IDE. The following example shows a typical Maven command to run a Spring Boot application:

$ mvn spring-boot:run

Using Executable Jar

To create an executable jar run:

$ mvn clean package

To run that application, use the java -jar command, as follows:

$ java -jar target/blog-demo-0.0.1-SNAPSHOT.jar

To exit the application, press ctrl-c.

Docker

It is possible to run blog-demo using Docker:

Build Docker image:

$ mvn clean package
$ docker build -t blog-demo:dev -f docker/Dockerfile .

Run Docker container:

$ docker run --rm -i -p 8090:8090 \
      --name blog-demo \
      blog-demo:dev
Helper script

It is possible to run all of the above with helper script:

$ chmod +x scripts/run_docker.sh
$ scripts/run_docker.sh

Docker

Folder docker contains:

  • docker/blog-demo/Dockerfile - Docker build file for executing blog-demo Docker image. Instructions to build artifacts, copy build artifacts to docker image and then run app on proper port with proper configuration file.

Util Scripts

  • scripts/run_docker.sh.sh - util script for running blog-demo Docker container using docker/Dockerfile

Tests

Tests can be run by executing following command from the root of the project:

$ mvn test

Helper Tools

HAL REST Browser

Go to the web browser and visit http://localhost:8090/

You will need to be authenticated to be able to see this page.

H2 Database web interface

Go to the web browser and visit http://localhost:8090/h2-console

In field JDBC URL put

jdbc:h2:mem:blog_simple_db

In /src/main/resources/application.properties file it is possible to change both web interface url path, as well as the datasource url.

More Repositories

1

spring-boot-shopping-cart

Simple shopping cart web app made using Spring Boot + Thymeleaf
Java
200
star
2

spring-boot-web-scraper

Simple web scrapping app made using Spring Boot + Thymeleaf + Jsoup + Java 8 Lambdas & Streams
Java
36
star
3

django-blog

Simple blog web app made using Django
Python
27
star
4

play-framework-blog

Simple blog web app made using Play Framework + Twirl
Java
16
star
5

ml-airflow

Generalized project for running Airflow DAGs, with possibility of skipping tasks already done for some set of input parameters.
Python
14
star
6

spring-boot-cassandra

Spring Boot + Apache Cassandra example app
Java
9
star
7

secured-spring-boot-webapp-template

Template for a Secured Spring Boot App with login and registration functionality for quick bootstrapping of secured Spring Boot projects.
Java
4
star
8

django-empty-project-template

Empty Django project template for quick bootstrapping of Django projects.
HTML
2
star
9

spring-boot-empty-mvc-thymeleaf-template

Empty Spring Boot MVC Thymeleaf template for quick bootstrapping of Spring Boot projects.
Shell
2
star
10

python-parameters-injector

Util decorator for injecting parameters into methods/functions from yaml/json files
Python
1
star
11

java-playground

Repo for my experimentation with various java algorithms, exercises, challenges...
Java
1
star
12

push-notifications-algorithm

Algorithm for optimization of bundling of push notifications, written in Python
Python
1
star
13

sudoku-java-swing

Over-engineered Sudoku app made using Java and Swing, with focus on using a lot of different GOF design patterns.
Java
1
star