Skip to content

Commit 81768f8

Browse files
committed
Spring: javadoc+checkstyle
1 parent 51d046a commit 81768f8

File tree

5 files changed

+70
-17
lines changed

5 files changed

+70
-17
lines changed

docs/asciidoc/dependency-injection.adoc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,6 @@ include::di-dagger.adoc[]
1010

1111
include::modules/guice.adoc[]
1212

13-
include::di-spring.adoc[]
13+
include::modules/spring.adoc[]
1414

1515
include::di-weld.adoc[]
File renamed without changes.

modules/jooby-spring/src/main/java/io/jooby/di/ConfigPropertySource.java

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,22 @@
99
import com.typesafe.config.ConfigException;
1010
import org.springframework.core.env.PropertySource;
1111

12+
import javax.annotation.Nonnull;
13+
14+
/**
15+
* Property source backed by Jooby application configuration object.
16+
*
17+
* @author edgar
18+
* @since 2.0.0
19+
*/
1220
public class ConfigPropertySource extends PropertySource<Config> {
13-
public ConfigPropertySource(String name, Config source) {
14-
super(name, source);
21+
/**
22+
* Creates a new property source.
23+
*
24+
* @param source Application configuration.
25+
*/
26+
public ConfigPropertySource(@Nonnull Config source) {
27+
super("jooby", source);
1528
}
1629

1730
@Override public boolean containsProperty(String key) {

modules/jooby-spring/src/main/java/io/jooby/di/SpringModule.java

Lines changed: 52 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,30 @@
2222
import javax.inject.Provider;
2323
import 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+
*/
2549
public 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
}

modules/jooby-spring/src/main/java/io/jooby/di/SpringRegistry.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,10 @@
1313

1414
import javax.annotation.Nonnull;
1515

16-
public class SpringRegistry implements Registry {
16+
class SpringRegistry implements Registry {
1717
private final ApplicationContext ctx;
1818

19-
public SpringRegistry(ApplicationContext ctx) {
19+
SpringRegistry(ApplicationContext ctx) {
2020
this.ctx = ctx;
2121
}
2222

0 commit comments

Comments
 (0)