Spring Session JDBC-使用@Autowired对象的错误

问题描述 投票:1回答:1

为了将会话保存在数据库中,我已使用此示例here实现了Spring Session JDBC。我在使用@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;
    }
}

然后,我在SESSION_SCOPE中将此bean注册如下:

@Configuration
public class DumpConfig{

    @Bean
    @Scope(value = WebApplicationContext.SCOPE_SESSION, proxyMode = ScopedProxyMode.TARGET_CLASS)
    public Dump getDump() {
        return new Dump();
    }

}

在控制器中,我正在接线并尝试使用:

@Controller
@RequestMapping("/")
public class HomeController {

    @Autowired
    private Dump dump;

    @GetMapping("/dump")
    @ResponseBody
    public String demo() {
        return dump.getSomeName();
    }
}

当我尝试运行时出现此错误:

Failed to convert from type [java.lang.Object] to type [byte[]] for value 'Dump@35b2136e' nested exception is org.springframework.core.serializer.support.SerializationFailedException
java spring spring-boot spring-mvc spring-session
1个回答
0
投票

[请参阅下面提到的链接中的视频(大约1:14),演讲者说,此问题在Spring 3.0中通过提供不可序列化的Bean的代理得以解决,该代理可从当前应用程序上下文(在反序列化)。

https://www.infoq.com/presentations/Whats-New-in-Spring-3.0

© www.soinside.com 2019 - 2024. All rights reserved.