There is various way we can generate REST application base template in java. Today I’m going to share you one of the example.
Why we require to generate the template ?
Going with your own project structure is good for example or test project. but if we talking about production application or some of serious project we must require to follow the standard. generally if we talk about Framework like spring that have certain rules to read application properties and they have defined standard project structure. and that is very use-full and self explanatory.
you can see on of this example, where clearly defined ‘src’ section that contain test and main application source. apart from this there is HELP.md where user can define there application details. also there is gradle config files are there that can be replace with maven if you choose maven build system.
Now these are The basics template every time create these structure manually is not worth to spend time. if there is already tools out there. Spring introduced spring initialiser that can help you generate base template where developer only require to generate and import into IDE.
Today most of the people prefer to deploy the standalone application and easy to manageable instead of doing too much overhead or get expert advice on it to manage a specific web server for rest application.
dilemma: When we have a standalone jar there are few minor hacks we have to do this with it. like, configure log path, start with a specific promised user. run it with standalone process instead of inline execution.
A fully executable jar can be executed like any other executable binary or it can be registered with ‘systemd‘. This makes it very easy to install and manage spring boot applications in common production environments.
#systemd: systemd is system and service manager for linux operating system. When run as the first process on boot (as PID 1), it acts as init system that brings up and maintains userspace services. it is a replacement of ‘Unix system v’ and BSD (Berkeley Software Distribution) init system. for more detail #man systemd
Assume that you have a linux server that has Java installed, now place your executable spring boot jar file in a /opt/apps/ directory
Now create a app.service file in a /etc/systemd/system
directory and execute below command also make sure your permission before creating a file at a particular location #vi /etc/systemd/system/app.service
Spring highly adopted annotation based configuration and it is happily accepted by developer communities and why not, no one wants to struggle with XML tags but that’s not enough somewhere we still miss XML configuration or you can say external file configuration as powerful as XML configuration. especially when we write an application that has to alter behaviors without compilation.
But still writing an XML configuration is not readable and not easily understandable for beginners, so I’ve written experimental plugins for spring boot that convert YAML definition to Spring Beans.
here is an example of bean definition in XML and same in YAML.