<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.
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)));
Please refer to the complete documentation here for detailed information.