jqa-spring-plugin icon indicating copy to clipboard operation
jqa-spring-plugin copied to clipboard

= jQAssistant Spring Framework Plugin

NOTE:: With jQAssistant 2.0.0, this plugin has been removed from the core-distribution. It is now available at https://github.com/jqassistant-plugin/jqassistant-spring-plugin[jqassistant-spring-plugin]

This is the Spring Framework Plugin of https://jqassistant.org[jQAssistant]. It provides pre-defined rules for projects using the http://www.spring.org/[Spring Framework], e.g.:

  • Spring Boot ** Package layout, i.e. all classes of a Spring Boot application must be located in the package of the application class or a child package of it. ** Considers classes annotated with @SpringBootApplication and @TestConfiguration configuration classes and injectables.

  • Spring Components ** Considers classes annotated with @Component, @Service, @Repository injectables. ** Considers classes that are returned from @Bean methods injectables. ** Considers Spring Data repositories injectables. ** Verifies dependencies between Spring components, i.e. controllers (must depend on services, repositories or components), services (must depend on other services, repositories or components) and repositories (must depend on other repositories and components). ** Requires @Bean methods to be used from with configuration classes only. ** Requires that JDK classes are not injectables.

  • Dependency Injection ** Prevents field injection (except in tests, in Strict mode) ** Requires injectables to be assigned to final fields (in Strict mode) ** Rejects direct instantiation of injectable types, except in tests and @Bean methods. ** Ensures that fields of injectable types are not manipulated. ** Ensures that injectables are never assigned to static fields or accessed via static methods.

** Recommends to use @PostConstruct and @PreDestroy over implementing InitializingBean and DisposableBean. ** Recommends to directly inject BeanFactory, ApplicationContext, and ApplicationEventPublisher instead of implementing callback interfaces.

  • Transactions ** Disallow direct invocation of methods annotated with @Transaction from methods not annotated with that annotation within the same class

For more information on jQAssistant see https://jqassistant.org[^].

== Usage

This plugin is part of the official jQAssistant release. You just need to activate the desired group of rules, either "spring-boot:Default" or "spring-boot:Strict"

[source,xml]

1.7.0 com.buschmais.jqassistant jqassistant-maven-plugin ${jqassistant.version}
    <executions>
      <execution>
        <id>cli-default</id>
        <goals>
          <goal>scan</goal>
          <goal>analyze</goal>
        </goals>
        <configuration>
          <groups>
            <!-- <1> -->
            <group>spring-boot:Strict</group>
          </groups>
        </configuration>
      </execution>
    </executions>
  </plugin>
</plugins>
----

<1> Activates the group "spring-boot:Strict".