2222import javax .inject .Provider ;
2323import java .util .Map ;
2424
25+ /**
26+ * Spring module: https://jooby.io/modules/spring.
27+ *
28+ * Jooby integrates the {@link io.jooby.ServiceRegistry} into the Spring Core framework.
29+ *
30+ * Usage:
31+ *
32+ * <pre>{@code
33+ * {
34+ *
35+ *
36+ * install(new SpringModule());
37+ *
38+ * }
39+ *
40+ * }</pre>
41+ *
42+ * Require calls are going to be resolve by Spring now.
43+ *
44+ * Spring scan the {@link Jooby#getBasePackage()}, unless you specify them explicitly.
45+ *
46+ * @author edgar
47+ * @since 2.0.0
48+ */
2549public class SpringModule implements Extension {
2650
2751 private AnnotationConfigApplicationContext applicationContext ;
@@ -32,24 +56,46 @@ public class SpringModule implements Extension {
3256
3357 private String [] packages ;
3458
59+ /**
60+ * Creates a new Spring module using the given application context.
61+ *
62+ * @param applicationContext Application context to use.
63+ */
3564 public SpringModule (@ Nonnull AnnotationConfigApplicationContext applicationContext ) {
3665 this .applicationContext = applicationContext ;
3766 }
3867
68+ /**
69+ * Creates a new Spring module, scan the default package: {@link Jooby#getBasePackage()}.
70+ */
3971 public SpringModule () {
40- this .applicationContext = null ;
4172 }
4273
43- public SpringModule (String ... packages ) {
44- this .applicationContext = null ;
74+ /**
75+ * Creates a new Spring module and scan the provided packages.
76+ *
77+ * @param packages Package to scan.
78+ */
79+ public SpringModule (@ Nonnull String ... packages ) {
4580 this .packages = packages ;
4681 }
4782
83+ /**
84+ * Indicates the Spring application context should NOT be refreshed. Default is: true.
85+ *
86+ * @return This module.
87+ */
4888 public SpringModule noRefresh () {
4989 this .refresh = false ;
5090 return this ;
5191 }
5292
93+ /**
94+ * Turn off discovering/scanning of MVC routes. For Spring integration an MVC route must be
95+ * annotated with {@link Controller}.
96+ *
97+ * @return This module.
98+ */
5399 public SpringModule noMvcRoutes () {
54100 this .registerMvcRoutes = false ;
55101 return this ;
@@ -72,7 +118,8 @@ public SpringModule noMvcRoutes() {
72118 }
73119 Environment environment = application .getEnvironment ();
74120
75- applicationContext = defaultApplicationContext (packages );
121+ applicationContext = new AnnotationConfigApplicationContext ();
122+ applicationContext .scan (packages );
76123
77124 ConfigurableEnvironment configurableEnvironment = applicationContext .getEnvironment ();
78125 String [] profiles = environment .getActiveNames ().toArray (new String [0 ]);
@@ -81,7 +128,7 @@ public SpringModule noMvcRoutes() {
81128
82129 Config config = environment .getConfig ();
83130 MutablePropertySources propertySources = configurableEnvironment .getPropertySources ();
84- propertySources .addFirst (new ConfigPropertySource ("application" , config ));
131+ propertySources .addFirst (new ConfigPropertySource (config ));
85132
86133 ConfigurableListableBeanFactory beanFactory = applicationContext .getBeanFactory ();
87134 beanFactory .registerSingleton ("conf" , config );
@@ -116,11 +163,4 @@ public SpringModule noMvcRoutes() {
116163 }
117164 }
118165 }
119-
120- public static AnnotationConfigApplicationContext defaultApplicationContext (
121- @ Nonnull String ... packages ) {
122- AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext ();
123- context .scan (packages );
124- return context ;
125- }
126166}
0 commit comments