title: Spring session tries serialize service with session scope
body: <p>I have a service </p>
  
  <pre><code>@Service
  @Scope(value = SCOPE_SESSION, proxyMode = ScopedProxyMode.TARGET_CLASS)
  public class MyService {
      public void method() throws MyException {
          throw new MyException();
      }
  }
  </code></pre>
  
  <p>And a Rest Controller:</p>
  
  <pre><code>@RestController
  public class MyController {
  
      @Autowired
      private MyService myService;
  
      @RequestMapping(value = "/do", method = RequestMethod.POST)
      public String do() {
          myService.method();
          return null;
      }
  
      @ExceptionHandler(MyException.class)
      public ResponseEntity&lt;MyException&gt; exceptionHandler(MyException e) {
          return new ResponseEntity&lt;MyException&gt;(e, HttpStatus.UNAUTHORIZED);
      }
  }
  </code></pre>
  
  <p>And configuration file:</p>
  
  <pre><code>@EnableRedisHttpSession
  public class AppConfig {
  }
  </code></pre>
  
  <p>When I request do method of controller, service throws <code>MyException</code>, <code>ExceptionHandler</code> catch it. But after <code>exceptionHandler</code> return, I have an Exception:</p>
  
  <pre><code>org.springframework.data.redis.serializer.SerializationException: Cannot serialize; 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 [my.example.MyService$$EnhancerBySpringCGLIB$$442fa3ef_5]
      at org.springframework.data.redis.serializer.JdkSerializationRedisSerializer.serialize(JdkSerializationRedisSerializer.java:92) ~[spring-data-redis-1.8.0.RELEASE.jar:na]
      at org.springframework.data.redis.core.AbstractOperations.rawHashValue(AbstractOperations.java:171) ~[spring-data-redis-1.8.0.RELEASE.jar:na]
      at org.springframework.data.redis.core.DefaultHashOperations.putAll(DefaultHashOperations.java:129) ~[spring-data-redis-1.8.0.RELEASE.jar:na]
      at org.springframework.data.redis.core.DefaultBoundHashOperations.putAll(DefaultBoundHashOperations.java:86) ~[spring-data-redis-1.8.0.RELEASE.jar:na]
      at org.springframework.session.data.redis.RedisOperationsSessionRepository$RedisSession.saveDelta(RedisOperationsSessionRepository.java:778) ~[spring-session-1.3.0.RELEASE.jar:na]
      at org.springframework.session.data.redis.RedisOperationsSessionRepository$RedisSession.access$000(RedisOperationsSessionRepository.java:670) ~[spring-session-1.3.0.RELEASE.jar:na]
      at org.springframework.session.data.redis.RedisOperationsSessionRepository.save(RedisOperationsSessionRepository.java:388) ~[spring-session-1.3.0.RELEASE.jar:na]
      at org.springframework.session.data.redis.RedisOperationsSessionRepository.save(RedisOperationsSessionRepository.java:245) ~[spring-session-1.3.0.RELEASE.jar:na]
      at org.springframework.session.web.http.SessionRepositoryFilter$SessionRepositoryRequestWrapper.commitSession(SessionRepositoryFilter.java:245) ~[spring-session-1.3.0.RELEASE.jar:na]
      at org.springframework.session.web.http.SessionRepositoryFilter$SessionRepositoryRequestWrapper.access$100(SessionRepositoryFilter.java:217) ~[spring-session-1.3.0.RELEASE.jar:na]
      at org.springframework.session.web.http.SessionRepositoryFilter.doFilterInternal(SessionRepositoryFilter.java:170) ~[spring-session-1.3.0.RELEASE.jar:na]
      ...
  Caused by: 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 [my.example.MyService$$EnhancerBySpringCGLIB$$442fa3ef_5]
      at org.springframework.core.serializer.support.SerializingConverter.convert(SerializingConverter.java:68) ~[spring-core-4.3.6.RELEASE.jar:4.3.6.RELEASE]
      at org.springframework.core.serializer.support.SerializingConverter.convert(SerializingConverter.java:35) ~[spring-core-4.3.6.RELEASE.jar:4.3.6.RELEASE]
      at org.springframework.data.redis.serializer.JdkSerializationRedisSerializer.serialize(JdkSerializationRedisSerializer.java:90) ~[spring-data-redis-1.8.0.RELEASE.jar:na]
      ... 33 common frames omitted
  Caused by: java.lang.IllegalArgumentException: DefaultSerializer requires a Serializable payload but received an object of type [my.example.MyService$$EnhancerBySpringCGLIB$$442fa3ef_5]
      at org.springframework.core.serializer.DefaultSerializer.serialize(DefaultSerializer.java:43) ~[spring-core-4.3.6.RELEASE.jar:4.3.6.RELEASE]
      at org.springframework.core.serializer.support.SerializingConverter.convert(SerializingConverter.java:63) ~[spring-core-4.3.6.RELEASE.jar:4.3.6.RELEASE]
      ... 35 common frames omitted
  </code></pre>
  
  <p>While debugging, I've got that session tries to serialize <code>Myservice</code> object to key <code>"sessionAttr:scopedTarget.myService"</code></p>
  
  <p>I do not whant to make MyService class Serializeble. Is there any another solutions?</p>