O'Reilly logo

Java 11 Cookbook by Mohamed Sanaulla, Nick Samoylov

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

How to do it...

We have four modules in this recipe:

  • book.service: This is the module that contains our service provider interface, that is, the service
  • mongodb.book.service: This is one of the service provider modules
  • sqldb.book.service: This is the other service provider module
  • book.manage: This is the service consumer module

The following steps demonstrate how to make use of ServiceLoader to achieve loose coupling:

  1. Create a book.service folder under the Chapter03/8_services/src directory. All our code for the book.service module will be under this folder. 
  2. Create a new package, com.packt.model, and a new class, Book, under the new package. This is our model class, which contains the following properties:
        public String id;  ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required