How to do it...

To create and differentiate session- and request-based beans, follow these steps:

  1. This recipe needs some custom models that can be injected into the container: either request-scoped or session-scoped beans. First, let us create a model SalaryGrade in the org.packt.dissect.mvc.model.data package. This model must be injected as a @Bean into the ApplicationContext through the annotation @Component:
@Scope(value=WebApplicationContext.SCOPE_REQUEST,  
    proxyMode=ScopedProxyMode.TARGET_CLASS) 
@Component 
public class SalaryGrade { 
  
  private String grade; 
  private Double rate; 
  private Date date; 
 
  public SalaryGrade() { 
     date = new Date(); 
  } 
  
  // getters and setters 
} 

This bean is registered as a request-scoped bean, and since this type of ...

Get Spring 5.0 Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.