Violation using field injection #916
Replies: 1 comment
-
The idea is for Spring Modulith to enforce general coding best-practices. I've always waited for someone to outline specific requirements to filter verifications before adding configuration API that would end up not meeting developers' needs. For now, you can rather call I've filed and fixed GH-995 (also a back-port to 1.3.1 in GH-996) to introduce a bit of convenience API for easier filtering. We're also planning to introduce violation types (Spring coding ones, cycles, internal references etc.) at a later stage so that going forward, you don't have to refer to the violation message for filtering. Ticket about to be filed. |
Beta Was this translation helpful? Give feedback.
-
Hello everyone,
I am trying to restructure a legacy project to use Spring modulith. When running the test via ApplicationModules.of(Application.class).verify() I am getting a violation:
org.springframework.modulith.core.Violations: - Module Module1 uses field injection in de.packagename.ClassName.autowiredservice. Prefer constructor injection instead!
While I am fully aware that constructure injection should be prefered I don't understand, how this is related to the modularization that should be enforced with Spring modulith. Can somebody give me some insight on this?
Also is there any way to disable this violation?
Thanks,
Bernd
Beta Was this translation helpful? Give feedback.
All reactions