O'Reilly logo

Java 9 Cookbook by Nick Samoylov, Mohamed Sanaulla

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:

  1. book.service: This is the module which contains our service provider interface that is, the service
  2. mongodb.book.service: This is one of the service provider module
  3. sqldb.book.service: This is the other service provider module
  4. 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 folder book.service under the directory chp3/8_services/src. All our code for 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;         public String ...

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