> For the complete documentation index, see [llms.txt](https://bernardo.gitbook.io/development-docs-java/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://bernardo.gitbook.io/development-docs-java/spring-mvc/controllers/controller-advices.md).

# Controller Advices

By using aspects controllers can receive common configurations. This requires just annotating a class like this:

```java
@ControllerAdvice
public final class GlobalControllerConfig
```

It may also define specific controllers:

```java
@ControllerAdvice(assignableTypes = { EmployeeController.class })
@Order(Ordered.HIGHEST_PRECEDENCE)
public class EmployeeControllerConfig
```

This can contain global configuration through annotations such as @ExceptionHandler, @InitBinder or @ModelAttribute.

## Testing

Always remember to add the required advices to MVC tests:

```java
getMockMvcBuilder().setControllerAdvice(new EmployeeControllerConfig())
```
