Search code examples
javaspringjdbctemplatejmstemplate

What are template classes in Spring Java? Why are they called templates? For example jdbc-template, jms-template etc


I'm new to Java. I've only been programming it for about a year. What does Spring mean by the use of templates? In Spring, there is jdbc-templates, jms-templates etc.. What are template classes in java? Are they a special kind of design pattern or what?

Thank you in advance.


Solution

  • They are called template as use the Template method pattern.

    Basically the idea is define the operation needed to do something in an abstract class or super class then implement a class that use the operation previous defined.

    In the case of spring allow that operation that always need to be done for an specific purpose be done automatically, (open connection, obtain for pool, translation, execution, close connection), then user only need to call methods without worries about the previous tasks.