Plexus
Most of you might be familiar with Spring but not Plexus. Plexus provides an Inversion of Control (IoC) or a Dependency Injection (DI) framework similar to Spring. If you are new to the concept of Dependency Injection, it's highly recommended that you go through the article by Martin Fowler, Inversion of Control Containers and the Dependency Injection pattern at http://martinfowler.com/articles/injection.html.
Forget about Maven for a bit; let's see how to implement Dependency Injection with Plexus with the following steps:
First, we need to define our own Java interface for our business service as follows. There can be more than one implementation of this service:
package com.packt.di; public interface MessagingService { public void sendMessage(String recipient, String message); }
Let's write a couple of implementations for the previous interface. The
SMSMessagingService
class will text the message to the recipient while theEmailMessagingService
class will email the message, shown...