This project checks that spring beans in your project adhere to certain properties when you add the @Verified
annotation to your @Component
or @Bean
lite class.
Some of those properties include all beans being explicitly named, all names are unique, and all autowiring includes names via @Qualifier
annotations. Cycles are prevented as well as duplicate bean names.
Return types of @Bean
methods are verified against @Autowired
injection points.
No autowiring in to @Bean
lite instances.
No non literal static member variables on @Bean
lite instances.
No autowiring an unknown list of instances by type... instead encourages the construction of named lists.
No @ComponentScan
, instead use @Import
to allow the annotation processor to analyze your graph.
By defining the spring graph in a type safe and introspectable manner the relevant parts of a spring graph are encoded in the java type system. Your code will be more readable, more refactorable, and less error prone even if your app has to scale to thousands of beans.
In your pom file, include the version of spring you wish to use (3+ should be fine)
Include these dependency:
<dependency>
<groupId>com.salesforce.aptspring</groupId>
<artifactId>AptSpringAPI</artifactId>
<version>${apt.spring.version}</version>
</dependency>
<dependency>
<groupId>com.salesforce.aptspring</groupId>
<artifactId>AptSpringProcessor</artifactId>
<version>${apt.spring.version}</version>
<scope>provided</scope>
</dependency>
Include the @Verified
annotation on your spring classes with @Bean
methods.
Use eclipse 2019.6 + (4.12) with m2e for incremental compiler support.
You can also configure the APT manually in eclipse if you are not using m2e, but eclipse's default APT handling will not support referencing a @Bean
lite class in another eclipse project/maven module. You would be limited to having on one eclipse project.
The error messages will help clean up your code and keep it clean.
A full list of checks can be found on the javadoc of the @Verified
annotation class.
In short, no cycles, fully defined decoupled spring graphs, with clear entry point for all system properties.
No guarantee you wont have runtime problems.
The guarantee is that those problems will be a lot simpler than the one you would otherwise get out of spring.
Please see @Verified Annotation for a full list of the constraints the AptSpringProcessor enforces, and what it may enforce in the future.