File tree Expand file tree Collapse file tree 1 file changed +14
-0
lines changed
spring-core-2/src/main/java/com/baeldung/autowire/sample Expand file tree Collapse file tree 1 file changed +14
-0
lines changed Original file line number Diff line number Diff line change 33import org .springframework .beans .factory .annotation .Autowired ;
44import org .springframework .stereotype .Component ;
55
6+ /**
7+ * This class presents a field, a constructor, and a setter injection type.
8+ * Usually, we'd stick with a single approach for a given property. This is just an educational code.
9+ */
610@ Component
711public class FooService {
812
913 @ Autowired
1014 @ FormatterType ("Foo" )
1115 private Formatter formatter ;
1216
17+ @ Autowired
18+ public FooService (@ FormatterType ("Foo" ) Formatter formatter ) {
19+ this .formatter = formatter ;
20+ }
21+
22+ @ Autowired
23+ public void setFormatter (@ FormatterType ("Foo" ) Formatter formatter ) {
24+ this .formatter = formatter ;
25+ }
26+
1327 public String doStuff () {
1428 return formatter .format ();
1529 }
You can’t perform that action at this time.
0 commit comments