Restaurant Part 2 – Running the Application – Spring Boot Web Application

This is the second part of the series. The links for the remaining posts are introduction, screens, initial data, basic testing, detailed testing.

Overview

The restaurant web application can be run directly from the executable spring boot jar in the command prompt. Else the source can be imported into an IDE and run.

Running App from Jar and IDE

The Spring Boot restaurant jar contains three application properties files. One is for the default profile and the other two are for the test and vacant profiles. The default and vacant profile displays 15 tables and the test profile displays 50 tables which is the minimum number required to run the complete test suite (Details in a later article). The initial order data for the default and test profiles are available in the orders.json and order-test.json files respectively. The default profile will populate six orders while the vacant profile creates no orders and all the tables will be vacant.

The command to run the spring boot executable jar from the prompt needs to be in the following format – java {options} -jar restaurant.jar.

The application can also be run from an IDE by importing the source code from this location. The IDE should be set up for handling Spring Boot applications. Refer the official Spring site for more details. The program options, if required, need to be added to Arguments tab (Eclipse) for the specific application. The setting for IntelliJ should be pretty similar.

To run the application in default profileno options are required. From the command prompt use java -jar restaurant.jar and from IDE just run the configuration. Below is a list of options required for other profiles for the command – java {options} -jar restaurant.jar.

Running Option for ->Jar FileEclipse IDE
1Test OR Vacant Profile–Dspring.profiles.active= [test OR vacant]––spring.profiles.active=[test OR vacant]
2Default Profile with different table count–Dtable.count=25––table.count=50
3Test profile using the Default profile–Dtable.count=50 –Ddata.path=orders-test.json––table.count=50 ––data.path=orders-test.json
4External application properties file–Dspring.profiles.active=newtest –Dspring.config.location=D:/restaurant/––spring.profiles.active=newtest ––spring.config.location=D:/restaurant/

There is nothing special about the test profile regarding beans. The same can be run by using the data.path and table.count properties to the default profile. The data.path property in this case is relative to the ristorante package. Refer to point 3 in above table.

An external application.properties file can also be provided with a table.count property and data.path property with absolute path for the json file containing order data. Assume a file named application-newtest.properties placed in the restaurant folder (assuming windows path here). Refer to point 4 in above table.

table.count=25
data.path=d:/restaurant/orders-notest.json

H2 Database Console

The H2 database browser console is enabled when the application is run from the source code or from the executable jar. The console is available at http://localhost:8080/h2-console. The username and password are default values. ‘sa’ for username and blank for password.

Leave a Reply

Your email address will not be published. Required fields are marked *