Skip to content
Felix edited this page Apr 27, 2022 · 2 revisions

This Cli-tool will help you to minimize the time lost on creating the same files over and over again for each entity, when setting up a new springboot project.

Usage

Create an Entity with DTOs and Services

its simple: SpringBootGeneratorCli --entity <entityName> <packageIdentifier> --root=./myProject

entityName The name of the entity, so for example User. Keep in mind that this is case sensitive and it is highly recommended to use PascalCase, as this will be the entity name for all Classes and Interfaces generated. packageIdentifier The full package identifier, for example at.company.project root the path of the project root. In the given folder a src folder should be present, but if not it will be generated, as well as all directories needed.

All Abstraction files will be overwritten at the moment, this is subject to change. For now try to create all Entities at once in the beginning.

The created structure is as the following: ex: SpringBootGeneratorCli --entity User at.company.proj

src
|
+ models
| + User
| | + User.java
| | + CreateUser.java
|
+ services
| + GetSingleService.java (Abstraction)
| + EntityService.java    (Abstraction)
| + UserService.java
|
+ repositories
| + UserRepository.java
|
+ controllers
| + UserController.java

As well as a UserControllerTest.java in the tests directory under controllers

Basic Configuration for a Project

You can create a dockerfile + docker-compose, a build and start script as well as the basic configuration for the app.

With --docker both a dockerfile and a docker-compose with MySQL db will get set up. The --script can then create a .cmd script to build, test, package and execute the app. Both the application.properties for normal usage and testing can be created with --config and --fix-tests. Fix-tests relies on the h2 db, you will have to make sure to add that as a dependency.

Specify the configuration

Many errors emerge, when tweaking the configuration, many parameters need to be the same across many files.

  • port
  • Docker-Image name (imageName
  • app name in compose (appName)
  • db name in compose (dbName)
  • db username
  • db password can be set with their --name=value parameter

Power usage

you can combine --entity with the configuration. running configuration multiple times to update it will overwrite all changed files, so be careful!

Installation

To install simply extract the zip or build it yourself with dotnet build to a directory of your choice and add the directory to your path, then SpringBootGeneratorCli will be available from every cmd/powershell.

Full command

SpringBootGeneratorCli [--entity <EntityName> <packageIdentifier>] [--fix-tests] [--docker] [--script] [--config]  
                       [--root='.'] [--port=8080] [--imageName=app21] [--appName=tru_app] [--dbName=truDb] [--dbUser=usr] [--dbPassword=pwd]
  
--entity......Create an Entity with given Name in the given package.
	     The packageIdentifier has to point to the package in which the model,
	     repository, controller and so on is.

--fix-tests...Creates a correct application.properties file for the tests uses the 'h2' db, so make sure to have that installed.

--docker......Creates a dockerfile and a dockercompose file that contains also the db.
--script......Creates a script to build, package and run the whole project.
--config......Creates the application.properties file for normal usage.
Clone this wiki locally