Every class that wants to use java.util.logging generally needs to declare a logger like this:
public class MyClass {
private static Logger _log = Logger.getLogger(MyClass.class.getName());
}
How do you avoid this MyClass.class.getName() boilerplate code?
Spring boot avoids all these boilerplate codes. Boilerplate code: refers to the lots of code which programmer must write to do minimal jobs. So, spring boot increase productivity by removing the boilerplate code and minimizing the programmer's effort.
In computer programming, boilerplate code, or simply boilerplate, are sections of code that are repeated in multiple places with little to no variation. When using languages that are considered verbose, the programmer must write a lot of boilerplate code to accomplish only minor functionality.
One of the most popular solutions for the Java world is the Apache Log4j 2 framework.
I have a template set up in Eclipse so that I only have to type a portion of the declaration, and then Eclipse will auto-complete the rest for me.
${:import(org.apache.log4j.Logger)}
private final static Logger log = Logger.getLogger(${enclosing_type}.class);
${cursor}
So, I only have to type logger
, hit Ctrl+Space
, followed by Enter
, and Eclipse fills in the rest for me and adds the import declaration as well.
This won't cut down on the amount of boilerplate code, but at least it cuts down on the amount of keystrokes.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With