Book Image

Mastering Apache Maven 3

Book Image

Mastering Apache Maven 3

Overview of this book

Table of Contents (16 chapters)
Credits
About the Author
Acknowledgments
About the Reviewers
www.PacktPub.com
Preface
Index

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:

  1. 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);
    }
  2. Let's write a couple of implementations for the previous interface. The SMSMessagingService class will text the message to the recipient while the EmailMessagingService class will email the message, shown...