[英]Spring Session JDBC - error using @Autowired Objects
In order to save the sessions in a Database, I have implemented the Spring Session JDBC using this example here .为了将会话保存在数据库中,我在此处使用此示例实现了 Spring Session JDBC。 I am having problems using the @Autowired with session scope: I have Java Class Dump
as follow:我在使用带有会话范围的 @Autowired 时遇到问题:我有 Java 类Dump
如下:
public class Dump
{
private String someName;
public Dump(){}
public Dump(String someName) {
this.someName = someName;
}
public String getSomeName() {
return someName;
}
public void setSomeName(String someName) {
this.someName = someName;
}
}
And then I am registering this bean in a SESSION_SCOPE
as following:然后我在SESSION_SCOPE
注册这个 bean,如下所示:
@Configuration
public class DumpConfig{
@Bean
@Scope(value = WebApplicationContext.SCOPE_SESSION, proxyMode = ScopedProxyMode.TARGET_CLASS)
public Dump getDump() {
return new Dump();
}
}
In a controller I am wiring it and trying to use:在控制器中,我正在接线并尝试使用:
@Controller
@RequestMapping("/")
public class HomeController {
@Autowired
private Dump dump;
@GetMapping("/dump")
@ResponseBody
public String demo() {
return dump.getSomeName();
}
}
When I try to run I get this error:当我尝试运行时,出现此错误:
Failed to convert from type [java.lang.Object] to type [byte[]] for value 'Dump@35b2136e' nested exception is org.springframework.core.serializer.support.SerializationFailedException
Please refer to the video in the below mentioned link(around 1:14) the speaker says that this issue is resolved in spring 3.0 by providing a proxy of non-serializable beans, which obtains an instance from the current application context (on deserialization).请参考下面提到的链接中的视频(大约 1:14) 演讲者说这个问题在 spring 3.0 中通过提供不可序列化 bean 的代理得到解决,该代理从当前应用程序上下文中获取实例(关于反序列化) .
https://www.infoq.com/presentations/Whats-New-in-Spring-3.0 https://www.infoq.com/presentations/Whats-New-in-Spring-3.0
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.