-
Notifications
You must be signed in to change notification settings - Fork 0
/
LegacyCodeUsingSpring.java
41 lines (34 loc) · 1.03 KB
/
LegacyCodeUsingSpring.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
package example.legacy;
import example.spring.IndependentSpringBean;
import org.springframework.beans.FatalBeanException;
import static diergo.spring.legacy.LegacySpringAccess.getSpringBean;
/**
* A simple class using code which became a Spring bean.
*/
public class LegacyCodeUsingSpring {
private final IndependentSpringBean springBean;
/**
* The old constructor without DI typically used by production code.
*/
public LegacyCodeUsingSpring() {
this(getSpringBean(IndependentSpringBean.class));
}
/**
* A new constructor with DI to be used by tests or from new code with DI.
*/
LegacyCodeUsingSpring(IndependentSpringBean springBean) {
this.springBean = springBean;
}
/**
* Try to access a method of the Spring bean.
* @return whether the call was successful or not
*/
public boolean canUseSpring() {
try {
springBean.doIt();
return true;
} catch (FatalBeanException error) {
return false;
}
}
}