Co-Authored-By: Claude Sonnet 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01JoVmf2fWvcpoXndcDSwRf7
19 lines
825 B
Plaintext
19 lines
825 B
Plaintext
# The same OrderService built with plain 'new', no Spring anywhere
|
|
|
|
|
|
--- constructor injection ---
|
|
new ConstructorOrderService(gateway, notifier).place("A-1", 500)
|
|
OK -> charged 500 cents for A-1
|
|
charges=1, notifications=1
|
|
|
|
--- setter injection, one setter forgotten ---
|
|
new SetterOrderService(); setter.setGateway(gateway); // setNotifier never called
|
|
NullPointerException: Cannot invoke "com.ankurm.coredi.injection.Notifier.send(String)" because "this.notifier" is null
|
|
charges=1 <-- the customer was charged before the failure
|
|
|
|
--- field injection ---
|
|
new FieldOrderService().place("A-3", 500)
|
|
NullPointerException: Cannot invoke "com.ankurm.coredi.injection.PaymentGateway.charge(String, int)" because "this.gateway" is null
|
|
after ReflectionTestUtils.setField(...) twice:
|
|
OK -> charged 500 cents for A-3
|