You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: _posts/2015-03-17-spring.md
+10-4Lines changed: 10 additions & 4 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -7,7 +7,10 @@ order: 10
7
7
---
8
8
9
9
Pippo can be used together with the [Spring framework](http://projects.spring.io/spring-framework), using Spring as a dependency injection container.
10
-
When Pippo creates new instances of your various `Controller` subclasses, the [pippo-spring]({{ site.codeurl }}/pippo-spring) integration would then take care that the Spring-managed service beans (e.g. Services) get injected into the desired instance fields (marked by the `@Inject` annotations in your code).
10
+
When Pippo creates new instances of your various `Controller` subclasses it delegates the instance creation to a `ControllerFactory`.
11
+
The module [pippo-spring]({{ site.codeurl }}/pippo-spring) contains [SpringControllerFactory]({{ site.codeurl }}/pippo-spring/src/main/java/ro/pippo/spring/SpringControllerFactory.java) that it's
12
+
a `ControllerFactory` implementation that delegates to the Spring container to instantiate a given `Controller` class. This allows for the instance to be configured via dependency injection (all Spring annotations are valid, AOP, ...).
13
+
11
14
An example of such a Controller subclass could look as follows:
12
15
13
16
```java
@@ -26,7 +29,7 @@ public class ContactsController extends Controller {
26
29
27
30
Pippo automatically creates the _ContactsController_ instance and pippo-spring injects the ContactService service bean, so basically you don’t have to worry about any of that stuff.
28
31
29
-
To activate pippo-spring integration in your Application you must add `SpringControllerInjector`:
32
+
To activate pippo-spring integration in your Application you must add `SpringControllerFactory`:
30
33
31
34
```java
32
35
publicclassMyApplicationextendsApplication {
@@ -36,8 +39,8 @@ public class MyApplication extends Application {
@@ -60,6 +63,9 @@ public class SpringConfiguration {
60
63
}
61
64
```
62
65
66
+
`SpringControllerFactory` class has two constructors: with and without `autoRegistering`. By default `autoRegistering` is true. If `autoRegistering `flag is set on true then if `Spring` doesn't contain a bean for a controller class, `SpringControllerFactory` will create and register a `BeanDefinition`.
67
+
If you want to modify the default bean definition of the `Controller` you must override `createBeanDefinition` method.
68
+
63
69
Also don't forget to add pippo-spring as dependency in your project:
0 commit comments