Skip to content

rweisleder/archunit-spring

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

59 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

ArchUnit Spring Integration

The ArchUnit Spring Integration provides predefined ArchUnit rules for Spring applications.

badge javadoc archunit spring

Usage

<dependency>
    <groupId>de.rweisleder</groupId>
    <artifactId>archunit-spring</artifactId>
    <version>1.0.0</version>
    <scope>test</scope>
</dependency>

The library expects that the required dependencies for Spring and ArchUnit are already declared.

Examples

Given the following class:

@RestController
class DemoRestController {

    @GetMapping("/hello")
    String hello() {
        return "Hello World";
    }
}

You can write architecture rules like this:

import static de.rweisleder.archunit.spring.SpringAnnotationPredicates.springAnnotatedWith;

methods()
    // "that are annotated with @RequestMapping" (or @GetMapping, @PostMapping etc.)
    .that(are(springAnnotatedWith(RequestMapping.class)))
    // "should be declared in classes that are annotated with @Controller" (or @RestController etc.)
    .should().beDeclaredInClassesThat(are(springAnnotatedWith(Controller.class)));

User Guide

Please refer to the complete documentation here for detailed information.