【发布时间】:2017-07-12 14:55:03
【问题描述】:
我正在尝试将 terracotta 服务器配置为使用 spring/mybatis 应用程序,但出现以下错误。我不确定这是否意味着密钥本身或从密钥返回的值无法序列化。缓存作为本地缓存运行良好,但现在尝试使用服务器时出现问题。我需要一个线索,为什么这不能被序列化。谢谢。
所以我从这个How do you serialize a Spring Bean (spring 3) 中得到了一个线索,这可能与缺少会话范围有关。这些错误发生在我启动 Tomcat 并且正在加载第一个网页时。我将 implementations java.io.Serializable 添加到 Site bean 类中,这使我越过了那个错误,转移到了下一个被调用的 bean。在将它添加到许多 bean 之后,我想知道 A,这是正确的做法吗?在这些 spring 类上强制实现 java.io.Serializable 是否会有任何副作用? B:有没有更好的方法来做到这一点,因为我在这个应用程序中有很多 bean?
SEVERE: Servlet.service() for servlet [ezreg] in context with path [] threw exception [Request processing failed; nested exception is net.sf.ehcache.CacheException: The value com.trifecta.src.ezreg.beans.Site@655ad5d5 for key getSiteByHostname127.0.0.1 is not Serializable. Consider using Element.getObjectValue()] with root cause
net.sf.ehcache.CacheException: The value com.trifecta.src.ezreg.beans.Site@655ad5d5 for key getSiteByHostname127.0.0.1 is not Serializable. Consider using Element.getObjectValue()
at net.sf.ehcache.Element.getValue(Element.java:326)
at net.sf.ehcache.ElementData.<init>(ElementData.java:35)
at net.sf.ehcache.EternalElementData.<init>(EternalElementData.java:19)
at org.terracotta.modules.ehcache.store.ValueModeHandlerSerialization.createElementData(ValueModeHandlerSerialization.java:48)
at org.terracotta.modules.ehcache.store.ClusteredStore.doPut(ClusteredStore.java:745)
at org.terracotta.modules.ehcache.store.ClusteredStore.putInternal(ClusteredStore.java:291)
at org.terracotta.modules.ehcache.store.ClusteredStore.put(ClusteredStore.java:263)
at org.terracotta.modules.ehcache.store.ClusteredSafeStore.put(ClusteredSafeStore.java:247)
at org.terracotta.modules.ehcache.store.nonstop.NonStopStoreWrapper.put(NonStopStoreWrapper.java:820)
at net.sf.ehcache.Cache.putInternal(Cache.java:1617)
at net.sf.ehcache.Cache.put(Cache.java:1543)
at net.sf.ehcache.Cache.put(Cache.java:1508)
at org.springframework.cache.ehcache.EhCacheCache.put(EhCacheCache.java:121)
at org.springframework.cache.interceptor.AbstractCacheInvoker.doPut(AbstractCacheInvoker.java:85)
at org.springframework.cache.interceptor.CacheAspectSupport$CachePutRequest.apply(CacheAspectSupport.java:784)
at org.springframework.cache.interceptor.CacheAspectSupport.execute(CacheAspectSupport.java:417)
at org.springframework.cache.interceptor.CacheAspectSupport.execute(CacheAspectSupport.java:327)
at org.springframework.cache.interceptor.CacheInterceptor.invoke(CacheInterceptor.java:61)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:213)
at com.sun.proxy.$Proxy56.getSiteByHostname(Unknown Source)
at com.trifecta.src.ezreg.daos.SiteDaoImpl.getSiteByHostname(SiteDaoImpl.java:35)
doa method:
public Site getSiteByHostname(String hostname) {
return getSiteMapper().getSiteByHostname(hostname);
}
映射器方法:
@Cacheable(cacheNames="siteCache", key="#root.methodName.concat(#root.args)")
Site getSiteByHostname(String hostname);
返回的站点 bean:
package com.trifecta.src.ezreg.beans;
import javax.xml.bind.annotation.XmlAttribute;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlTransient;
@XmlRootElement
public class Site {
public static String ADMIN_CURRENT_SITE = "adminCurrentSite";
public static String _CURRENT_SITE = "currentSite";
@XmlAttribute
private Long id;
@XmlAttribute
private String name;
@XmlAttribute
private String supportphonenumber;
@XmlElement
private SitePreference sitePreference;
@XmlElement
private SiteInterfaceDevice siteInterfaceDevice;
@XmlElement
private SitePdfFormat sitePdfFormat;
@XmlAttribute
private boolean ecum;
@XmlTransient
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
@XmlTransient
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
@XmlTransient
public SiteInterfaceDevice getSiteInterfaceDevice() {
return siteInterfaceDevice;
}
public void setSiteInterfaceDevice(SiteInterfaceDevice siteInterfaceDevice) {
this.siteInterfaceDevice = siteInterfaceDevice;
}
@XmlTransient
public SitePdfFormat getSitePdfFormat() {
return sitePdfFormat;
}
public void setSitePdfFormat(SitePdfFormat sitePdfFormat) {
this.sitePdfFormat = sitePdfFormat;
}
@XmlTransient
public SitePreference getSitePreference() {
return sitePreference;
}
public void setSitePreference(SitePreference sitePreference) {
this.sitePreference = sitePreference;
}
@XmlTransient
public String getSupportphonenumber() {
return supportphonenumber;
}
public void setSupportphonenumber(String supportphonenumber) {
this.supportphonenumber = supportphonenumber;
}
@XmlTransient
public boolean getEcum() {
return ecum;
}
public void setEcum(boolean ecum) {
this.ecum = ecum;
}
}
public class Site implements java.io.Serializable{
public static String ADMIN_CURRENT_SITE = "adminCurrentSite";
public static String _CURRENT_SITE = "currentSite";
【问题讨论】:
标签: ehcache terracotta