Skip to content

salesforce/AptSpring

Status

Build Status Codacy Badge codebeat badge Maven Site Maven Central codecov

About AptSpring

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.

Duplicate bean name and cycle free

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.

Type Safety

Return types of @Bean methods are verified against @Autowired injection points.

Disallows "Interesting" practices

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.

Safety

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.

Quick Start: Get the goodness.

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.

Enforcement

Please see @Verified Annotation for a full list of the constraints the AptSpringProcessor enforces, and what it may enforce in the future.

About

No description, website, or topics provided.

Resources

License

Code of conduct

Security policy

Stars

Watchers

Forks

Packages

No packages published

Languages