title: @Scope("session") and spring.session.store-type=jdbc, ERROR 30396
body: <p>I have been tried to use Spring session and Spring boot, but I could do it.</p>
  
  <p>My objetive is save the currently session in a database with jdbc, and manager the scope of the bean with @scope("session") in a @RestController that calls to service.</p>
  
  <p>When I write spring.session.store-type=hash-map in the application.properties file, the application work very well, however, when I interchange the property by:</p>
  
  <pre><code>    spring.datasource.url=jdbc:as400://localhost/example
      spring.datasource.username=user
      spring.datasource.password=pass
      spring.datasource.driver-class-name=com.ibm.as400.access.AS400JDBCDriver
  
      spring.session.store-type=jdbc
      server.session.cookie.max-age=3600
      server.session.timeout=60
      spring.session.jdbc.initializer.enabled=true
      spring.session.jdbc.table-name=SPRING_SESSION
  </code></pre>
  
  <p>The service starts normally, but when I try to consume it, 
  I get the following error:</p>
  
  <pre><code>2017-05-24 16:27:44.329 ERROR 30396 --- [nio-8080-exec-1] o.a.c.c.C.[.[.[/].[dispatcherServlet]    : Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception
  
  
  
  org.springframework.core.convert.ConversionFailedException: Failed to convert from type [java.lang.Object] to type [byte[]] for value 'com.orm.control.UsuariosControlRest@27f9f7e6'; nested exception is org.springframework.core.serializer.support.SerializationFailedException: Failed to serialize object using DefaultSerializer; nested exception is java.lang.IllegalArgumentException: DefaultSerializer requires a Serializable payload but received an object of type [com.orm.control.UsuariosControlRest]
  </code></pre>
  
  <p>I have the RestController class:</p>
  
  <pre><code>    @Scope("session")
      @RestController
      @RequestMapping("/UsuariosREST")
      public class UsuariosControlRest{
      @GetMapping("/readSession")
               public Usuarios getSessionUsuarios(){
                     return this.objSesionesService.getUsuarios();
               }
      }
  </code></pre>
  
  <p>The interface:</p>
  
  <pre><code>    public interface SesionesService {
          public Usuarios getUsuarios();
      }
  </code></pre>
  
  <p>The class SesionesServiceImpl</p>
  
  <pre><code>    @Scope("session")
      @Service("sesionesServiceImpl")
      public class SesionesServiceImpl implements SesionesService{
  
          @Autowired
          @Qualifier("usuario")
          private Usuarios objUsuario;
  
             @Override
             public Usuarios getUsuarios() {
                    return this.objUsuario;
             }
  
       }
  </code></pre>
  
  <p>and finally one class named Usuarios</p>
  
  <pre><code>   @Scope("session")
     @Component("usuario")
     public class Usuarios{
          public String nombre;
          public int id;
          public String correo;
  
          public String getCorreo() {
             return correo;
          }
         public void setCorreo(String correo) {
             this.correo = correo;
         }
  
         public String getNombre() {
             return nombre;
         }
         public void setNombre(String strNombre) {
             this.nombre = strNombre;
         }
         public int getId() {
             return id;
         }
         public void setId(int id) {
             this.id = id;
         }
      }
  </code></pre>
  
  <p>I wrote in the three classes @Scope('session') because I found here </p>
  
  <pre><code>http://www.baeldung.com/spring-security-session
  </code></pre>
  
  <p>that there are 3 ways for working with session in Spring. The first is with Session Scoped Beans (my way), follow by the inject the raw Session into a Controller and finally obtaining the raw session. I am using @Scope("session") in the related classes with the session, because the objects will be created for each user. If I only use @scope("session") in the first class, other classes will be "singleton" and when I modified some attribute in one session the other user will see it. Do you think that existe other way?.</p>