Skip to content

Commit 3213edc

Browse files
committed
Fix #25
1 parent 1162d32 commit 3213edc

File tree

1 file changed

+8
-9
lines changed

1 file changed

+8
-9
lines changed

_posts/2015-03-17-modularity.md

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,19 +20,16 @@ We chose the Service Loader mechanism from Java as built in modules system in Pi
2020
You can create a modular application using [ServiceLocator]({{ site.coreurl }}/src/main/java/ro/pippo/core/util/ServiceLocator.java) class (trivial wrapper over Service Loader concept).
2121

2222
To improve the modularity mechanism, we added the concept of [Initializer]({{ site.coreurl }}/src/main/java/ro/pippo/core/Initializer.java).
23-
When Pippo starts up an application, it scans the classpath roots, looking for files named `pippo.properties`. It reads
24-
every pippo.properties file it finds, and it instantiates and execute the initializers defined in those files.
25-
26-
To demonstrate the initializer concept I added a dump [FreemarkerInitializer]({{ site.codeurl }}/pippo-template-parent/pippo-freemarker/src/main/java/ro/pippo/freemarker/FreemarkerInitializer.java) in pippo-freemarker module. In our example,
27-
the [pippo.properties]({{ site.codeurl }}/pippo-freemarker/src/main/resources/pippo.properties) file (which should be packaged in the root of the classpath) contains only one line:
28-
29-
```properties
30-
initializer=ro.pippo.freemarker.FreemarkerInitializer
31-
```
23+
When Pippo starts up an application, it scans the classpath roots, looking for _Initializer_ implementations.
24+
It instantiates and execute the initializers defined via Service Loader.
25+
Of course you can create `META-INF/services` manually but the easy mode is to use the `@MetaInfServices` annotation.
26+
The `@MetaInfServices` annotation generates _META-INF/services/*_ file from annotations that you placed on your source code, thereby eliminating the need for you to do it by yourself.
3227

28+
To demonstrate the initializer concept I added a dump [FreemarkerInitializer]({{ site.codeurl }}/pippo-template-parent/pippo-freemarker/src/main/java/ro/pippo/freemarker/FreemarkerInitializer.java) in pippo-freemarker module.
3329
The initializer can be implemented like this:
3430

3531
```java
32+
@MetaInfServices
3633
public class FreemarkerInitializer implements Initializer {
3734

3835
@Override
@@ -54,6 +51,7 @@ For example my application comes with two modules (two jars): _contacts_ and _us
5451
I can have _ContactInitializer.java_ with this content:
5552

5653
```java
54+
@MetaInfServices
5755
public class ContactInitializer implements Initializer {
5856

5957
@Override
@@ -76,6 +74,7 @@ public class ContactInitializer implements Initializer {
7674
I can have _UserInitializer.java_ with this content:
7775

7876
```java
77+
@MetaInfServices
7978
public class UserInitializer implements Initializer {
8079

8180
@Override

0 commit comments

Comments
 (0)