Skip to content

Mme-adorsys/jqa-spring-plugin

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

jQAssistant Spring Framework Plugin

This is the Spring Framework Plugin of jQAssistant. It provides pre-defined rules for projects using the 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"

<project>

  <properties>
    <jqassistant.version>1.7.0</jqassistant.version> <!-- define the jQAssistant version to use -->
  </properties>

  <build>
    <plugins>
      <plugin>
        <!-- <1> -->
        <groupId>com.buschmais.jqassistant</groupId>
        <artifactId>jqassistant-maven-plugin</artifactId>
        <version>${jqassistant.version}</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>
  </build>
</project>
  1. Activates the group "spring-boot:Strict".