Annotations Name Description @Model Interface, holder for model attributes @ModelMap Class, in ModelMap attibute key can be omitted and the value of the attribute will be use to generate the key. @ModelAndView ModelAndView it’s a container for both View object and ModelMap @ModelAttribute Annotation that binds a method parameter or method return method to a…
Category: Spring
Method security
Spring Security’s method authorization support is handy for: And since Method Security is built using Spring AoP. Annotation @EnableMethodSecurity Annotation @Secured is a legacy option to authorize invocations, superseded by @PreAuthorized. JSR 250 annotations correspond to @RolesAllowed, @PermitAll and @DenyAll. Annotations @PreAuthorize and @PostAuthorize – verifies condition before or after method invocation. @PreFilter and @PostFilter…
SpEL and Value
Spring EL Accessing properties: $ – value# – expression/executionValue- @Value(“${bean.message}”)System environment variable- @Value(“#{systemEnvironment[‘SOME_ENV_VARIABLE’]}”) It casts to the required type: @Value(“${daily.limit}”) int maxTransferPerDay@Value(“#{environment[‘daily.limit’]}”)int maxTransferPerDay; But values are handled as String: @Value(“#{new Integer(environment[‘daily.limit’]) * 2 }”) -> OK@Value (“#{new java.net.URI(environment[‘home.page’]).host}”) -> OK@Value (“#{daily.limit * 2}”}) -> not OK Default values: @Value(“${daily.limit:1000}”)@Value(“#{environment[‘daily.limit’]?:1000}”) https://www.baeldung.com/spring-expression-language @Value This annotation can be…
SpringBoot Lifecycle extensions
BeanFactoryPostProcessor BeanFactoryPostProcessor operates on bean configuration metadata, it reads the configuration metadata and can change it before the container instantiates the beans. This interfaces can be extended to provide further customization. BeanPostProcessor The BeanPostProcessor interface can be itself customized logic to default steps, when Spring container finishes instantiating, configuring, and initializing a bean, several implementations…
Autowiring and others
Usage of @Autowired By default autowired beans are required but this be changed: @Autowired(required=false) Optional is also supported: Disambiguation @Qualifier is used for disambiguation, can be used both for components and beans (names). Autowiring resolution rules: Configuration choices If a class has only a default constructor -> no need to annotate with @Autowired if class had…