title: How to implement Decorator pattern in Spring Boot
body: <p>I know how to implement and use a decorator pattern without Spring.</p>
  
  <p>Because in this pattern you yourself control the process of creating components and you can perform dynamic behavior adding.</p>
  
  <p>Below is an example of implementation without using Spring:</p>
  
  <pre><code>public class SimpleDecoratorApp {
      public static void main(String[] args) {
          SimplePrinter simplePrinter = new SimplePrinter();
  
          Printer decorated = new UpperCasePrinterDecorator(
                  new AddAsterisksPrinterDecorator(simplePrinter)
          );
          decorated.print("hello");   // *** HELLO ***
      }
  }
  
  interface Printer {
      void print(String msg);
  }
  
  class SimplePrinter implements Printer {
      @Override
      public void print(String msg) {
          System.out.println(msg);
      }
  }
  
  abstract class PrinterDecorator implements Printer {
      protected Printer printer;
      public PrinterDecorator(Printer printer) {
          this.printer = printer;
      }
  }
  
  class UpperCasePrinterDecorator extends PrinterDecorator {
      public UpperCasePrinterDecorator(Printer printer) {
          super(printer);
      }
      @Override
      public void print(String msg) {
          String s = msg.toUpperCase();
          this.printer.print(s);
      }
  }
  
  class AddAsterisksPrinterDecorator extends PrinterDecorator {
      public AddAsterisksPrinterDecorator(Printer printer) {
          super(printer);
      }
      @Override
      public void print(String msg) {
          msg = "*** " + msg + " ***";
          this.printer.print(msg);
      }
  }
  </code></pre>
  
  <p>I am interested in how to implement the same example but with the help of spring beans.</p>
  
  <p>Because I don’t quite understand how to maintain flexibility in the ability to simply wrap with any number of decorators.</p>
  
  <p>Because as I understand it - it will be implemented fixed in some separate component and I will have to create dozens of various separate components with the combinations of decorators I need.</p>