Use try-with-resources in documentation samples
Use try-with-resources in documentation samples

Fixes #22269

spring-projects/spring-framework,spring-projects/spring-framework,spring-projects/spring-framework,spring-projects/spring-framework,spring-projects/spring-framework,spring-projects/spring-framework,spring-projects/spring-framework