集群上的CDI Bean序列化问题

时间:2016-02-05 23:25:11

标签: serialization cdi wildfly infinispan jboss-weld

当我尝试在独立群集模式下在Wildfly 9.2上运行我的EJB + CDI + JSF应用程序(我也试过10.0)时,我遇到了一个大问题。

当我的集群容器尝试反序列化我的会话作用域CDI bean时会出现问题,它会抛出以下异常:

2016-02-06 02:17:22,650 ERROR [io.undertow.request] (default task-9) UT005071: Undertow request failed HttpServerExchange{ GET /login.xhtml request {Accept=[text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8], Accept-Language=[en-US,en;q=0.8], Cache-Control=[max-age=0], Accept-Encoding=[gzip, deflate, sdch], User-Agent=[Mozilla/5.0 (Windows NT 6.3; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/48.0.2564.97 Safari/537.36], Connection=[keep-alive], Cookie=[__utma=111872281.273659443.1454265274.1454265274.1454265274.1; __utmz=111872281.1454265274.1.1.utmcsr=(direct)|utmccn=(direct)|utmcmd=(none); JSESSIONID=oiC7sg_tinxBz6BWghg5PQ2urzCMw4Kh5oPqPRqU.ahmed-pc], Upgrade-Insecure-Requests=[1], Host=[localhost:8180]} response {Connection=[keep-alive], Content-Type=[text/html;charset=UTF-8], Content-Length=[12371], Date=[Fri, 05 Feb 2016 23:17:22 GMT]}}: org.jboss.weld.exceptions.IllegalStateException: WELD-001122: Failed to deserialize annotated type identified with AnnotatedTypeIdentifier [contextId=EAR-1.0.0.ear, bdaId=/C:/Web Server/wildfly-10.0.0.Final/standalone/deployments/EAR-1.0.0.ear/MySystemView-1.0.0.war/WEB-INF/lib/MySystemController-1.0.0.jar, className=com.sh.controller.MySystemController, suffix=null, modified=false]
at org.jboss.weld.annotated.slim.SlimAnnotatedType$SerializationProxy.readResolve(SlimAnnotatedType.java:60)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:497)
at org.jboss.marshalling.reflect.SerializableClass.callReadResolve(SerializableClass.java:413)
at org.jboss.marshalling.river.RiverUnmarshaller.doReadNewObject(RiverUnmarshaller.java:1286)
at org.jboss.marshalling.river.RiverUnmarshaller.doReadObject(RiverUnmarshaller.java:276)
at org.jboss.marshalling.river.RiverUnmarshaller.doReadObject(RiverUnmarshaller.java:224)
at org.jboss.marshalling.river.RiverUnmarshaller.readFields(RiverUnmarshaller.java:1745)
at org.jboss.marshalling.river.RiverUnmarshaller.doInitSerializable(RiverUnmarshaller.java:1658)
at org.jboss.marshalling.river.RiverUnmarshaller.doInitSerializable(RiverUnmarshaller.java:1606)
at org.jboss.marshalling.river.RiverUnmarshaller.doReadNewObject(RiverUnmarshaller.java:1285)
at org.jboss.marshalling.river.RiverUnmarshaller.doReadObject(RiverUnmarshaller.java:276)
at org.jboss.marshalling.river.RiverUnmarshaller.doReadObject(RiverUnmarshaller.java:224)
at org.jboss.marshalling.river.RiverUnmarshaller.readFields(RiverUnmarshaller.java:1745)
at org.jboss.marshalling.river.RiverUnmarshaller.doInitSerializable(RiverUnmarshaller.java:1658)
at org.jboss.marshalling.river.RiverUnmarshaller.doReadNewObject(RiverUnmarshaller.java:1285)
at org.jboss.marshalling.river.RiverUnmarshaller.doReadObject(RiverUnmarshaller.java:276)
at org.jboss.marshalling.river.RiverUnmarshaller.doReadObject(RiverUnmarshaller.java:224)
at org.jboss.marshalling.river.RiverUnmarshaller.readFields(RiverUnmarshaller.java:1745)
at org.jboss.marshalling.river.RiverUnmarshaller.doInitSerializable(RiverUnmarshaller.java:1658)
at org.jboss.marshalling.river.RiverUnmarshaller.doReadNewObject(RiverUnmarshaller.java:1285)
at org.jboss.marshalling.river.RiverUnmarshaller.doReadObject(RiverUnmarshaller.java:276)
at org.jboss.marshalling.river.RiverUnmarshaller.doReadObject(RiverUnmarshaller.java:224)
at org.jboss.marshalling.river.RiverUnmarshaller.readFields(RiverUnmarshaller.java:1745)
at org.jboss.marshalling.river.RiverUnmarshaller.doInitSerializable(RiverUnmarshaller.java:1658)
at org.jboss.marshalling.river.RiverUnmarshaller.doInitSerializable(RiverUnmarshaller.java:1606)
at org.jboss.marshalling.river.RiverUnmarshaller.doReadNewObject(RiverUnmarshaller.java:1285)
at org.jboss.marshalling.river.RiverUnmarshaller.doReadObject(RiverUnmarshaller.java:276)
at org.jboss.marshalling.river.RiverUnmarshaller.doReadObject(RiverUnmarshaller.java:224)
at org.jboss.marshalling.river.RiverUnmarshaller.readFields(RiverUnmarshaller.java:1745)
at org.jboss.marshalling.river.RiverUnmarshaller.doInitSerializable(RiverUnmarshaller.java:1658)
at org.jboss.marshalling.river.RiverUnmarshaller.doReadNewObject(RiverUnmarshaller.java:1285)
at org.jboss.marshalling.river.RiverUnmarshaller.doReadObject(RiverUnmarshaller.java:276)
at org.jboss.marshalling.river.RiverUnmarshaller.doReadObject(RiverUnmarshaller.java:224)
at org.jboss.marshalling.river.RiverUnmarshaller.readFields(RiverUnmarshaller.java:1745)
at org.jboss.marshalling.river.RiverUnmarshaller.doInitSerializable(RiverUnmarshaller.java:1658)
at org.jboss.marshalling.river.RiverUnmarshaller.doReadNewObject(RiverUnmarshaller.java:1285)
at org.jboss.marshalling.river.RiverUnmarshaller.doReadObject(RiverUnmarshaller.java:276)
at org.jboss.marshalling.river.BlockUnmarshaller.readObject(BlockUnmarshaller.java:149)
at org.jboss.marshalling.river.BlockUnmarshaller.readObject(BlockUnmarshaller.java:135)
at org.jboss.marshalling.MarshallerObjectInputStream.readObjectOverride(MarshallerObjectInputStream.java:53)
at org.jboss.marshalling.river.RiverObjectInputStream.readObjectOverride(RiverObjectInputStream.java:307)
at java.io.ObjectInputStream.readObject(ObjectInputStream.java:365)
at java.util.HashMap.readObject(HashMap.java:1396)
at sun.reflect.GeneratedMethodAccessor63.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:497)
at org.jboss.marshalling.reflect.SerializableClass.callReadObject(SerializableClass.java:307)
at org.jboss.marshalling.river.RiverUnmarshaller.doInitSerializable(RiverUnmarshaller.java:1637)
at org.jboss.marshalling.river.RiverUnmarshaller.doReadNewObject(RiverUnmarshaller.java:1285)
at org.jboss.marshalling.river.RiverUnmarshaller.doReadObject(RiverUnmarshaller.java:276)
at org.jboss.marshalling.river.RiverUnmarshaller.doReadObject(RiverUnmarshaller.java:209)
at org.jboss.marshalling.AbstractObjectInput.readObject(AbstractObjectInput.java:41)
at org.wildfly.clustering.marshalling.jboss.SimpleMarshalledValue.get(SimpleMarshalledValue.java:101)
at org.wildfly.clustering.marshalling.jboss.SimpleMarshalledValue.get(SimpleMarshalledValue.java:44)
at org.wildfly.clustering.marshalling.jboss.MarshalledValueMarshaller.read(MarshalledValueMarshaller.java:45)
at org.wildfly.clustering.marshalling.jboss.MarshalledValueMarshaller.read(MarshalledValueMarshaller.java:32)
at org.wildfly.clustering.web.infinispan.session.coarse.CoarseSessionAttributesFactory.findValue(CoarseSessionAttributesFactory.java:84)
at org.wildfly.clustering.web.infinispan.session.coarse.CoarseSessionAttributesFactory.findValue(CoarseSessionAttributesFactory.java:48)
at org.wildfly.clustering.web.infinispan.session.InfinispanSessionFactory.findValue(InfinispanSessionFactory.java:63)
at org.wildfly.clustering.web.infinispan.session.InfinispanSessionFactory.findValue(InfinispanSessionFactory.java:40)
at org.wildfly.clustering.web.infinispan.session.InfinispanSessionManager.findSession(InfinispanSessionManager.java:234)
at org.wildfly.clustering.web.undertow.session.DistributableSessionManager.getSession(DistributableSessionManager.java:140)
at io.undertow.servlet.spec.ServletContextImpl.getSession(ServletContextImpl.java:726)
at io.undertow.servlet.spec.ServletContextImpl.getSession(ServletContextImpl.java:756)
at io.undertow.servlet.spec.ServletContextImpl.updateSessionAccessTime(ServletContextImpl.java:760)
at io.undertow.servlet.spec.HttpServletResponseImpl.responseDone(HttpServletResponseImpl.java:557)
at io.undertow.servlet.handlers.ServletInitialHandler.handleFirstRequest(ServletInitialHandler.java:331)
at io.undertow.servlet.handlers.ServletInitialHandler.dispatchRequest(ServletInitialHandler.java:263)
at io.undertow.servlet.handlers.ServletInitialHandler.access$000(ServletInitialHandler.java:81)
at io.undertow.servlet.handlers.ServletInitialHandler$1.handleRequest(ServletInitialHandler.java:174)
at io.undertow.server.Connectors.executeRootHandler(Connectors.java:202)
at io.undertow.server.HttpServerExchange$1.run(HttpServerExchange.java:793)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at java.lang.Thread.run(Thread.java:745)
Caused by: an exception which occurred:
in object of type org.jboss.weld.annotated.slim.SlimAnnotatedType$SerializationProxy
in field type
in object of type org.jboss.weld.annotated.slim.backed.BackedAnnotatedField$SerializationProxy
in field field
in object of type org.jboss.weld.injection.attributes.InferringFieldInjectionPointAttributes
in field attributes
in object of type org.jboss.weld.injection.FieldInjectionPoint
in field injectionPoint
in object of type org.jboss.weld.event.EventImpl$SerializationProxy
in field events
in object of type com.sh.controller.MySystemController
in field instance
in object of type org.jboss.weld.context.SerializableContextualInstanceImpl
in object of type java.util.HashMap

我在stackoverflow上找到了这个问题,它提到我不应该将我的CDI注入的bean标记为瞬态跳过序列化,那么问题出在哪里?我是否需要暂时注入Injected bean?

类源代码超过2500行代码,我在这里处理类操作符:

@Named("sysControl")
@SessionScoped
public class MySystemController extends VenusAbstractBean implements 

BundleFiles,Serializable {
    private static final long serialVersionUID = 9021710761540108681L;

    private Ticket ticket;
    private Logger log = LoggerFactory.getLogger(this.getClass());
    private TicketData data;
    @Inject
    private transient TicketingSubject subject;
    @Inject
    private TicketListController ticketListCont;
    @EJB
    private SMSHandler smsHandler;
    @EJB
    private TypeFacade typeFacade;
    @EJB
    private UsersFacade usersFacade;
    @EJB
    private StatusFacade statusFacade;
    @EJB
    private TicketFacade ticketFacade;
    @EJB
    private AttachmentsFacade attachementFacade;
    @EJB
    private SourceChannelFacade sourceFacade;
    @EJB
    private TicketDataFacade dataFacade;
    @EJB
    private LockFacade lockFacade;
    @EJB
    private UsersAssignedTicketsFacade ticketAssignFacade;
    @EJB
    private TicketHistoryFacade historyFacade;
    @EJB
    private UsersAssignedTicketsFacade assignedFacade;
    @EJB
    private EmailHandler emailHandlerFacade;
    @EJB
    private GlobalConfigurationFacade globalConfigFacade;
    @EJB
    private EscalationHistoryFacade escalationHistoryFacade;
    @EJB
    private EmailMessageFacade emailMessageFacade;
    @EJB
    private TicketDataFacade ticketDataFacade;
    @EJB
    private CalendarFacade calFacade;
    @EJB
    private EmailHistoryFacade emailHistoryFacade;
    private boolean enableLastReplyEdit = false;
    private MainCategory cat;
    private SubCategory sub;
    private Topic topic;
    private TicketHistory history;
    private byte[] attachment;
    private List<String> uploadedFile;
    private String reply;
    private String reassignNote;
    private Lock myLock;
    private Status status;
    private String mimeType;
    private boolean enableReopen;
    private TicketData selectedData;
    private Long lockSeconds;
    private boolean canbeReopened;
    private List<Integer> reopenStatusList;

    private Users selectedUser;
    private String changeDeptCaller;
    private Integer viewMode;
    private boolean printContent;
    private boolean printReplies;
    private boolean printEscalation;
    private List<Attachments> attachmentsList;
    private List<Attachments> uploadAttachementsList;;
    private boolean displayTimeoutMessage;
    private List<Ticketactions> actions;
    private Ticketactions selectedAction;
    private TicketHoldReason holdReason;
    private boolean skip;
    private int assign_changeDept;
    private boolean canSetOnHold;
    private boolean lockRequired;
    private List<Ticket> selectedTickets;
    private boolean editLastRowMode;
    private List<TicketData> ticketDataList;

    @Inject
    private Event<TicketEvent> events;
    @EJB
    private TicketEventObserver listener;

    @EJB
    private SLATimeCalculator slaCalc;
    @EJB
    private SlaFacade slaFacade;

    @EJB
    private EJBUtils ejbUtils;
    private Date dueDate;

    private Long dueDateRemainingSec;
    }

TicketEvent类

import java.util.EventObject;

import com.sh.entity.Ticket;

public class TicketEvent extends EventObject {

    private static final long serialVersionUID = 1L;
    private Ticket ticket;
    private Object[] values;

    public TicketEvent(Object source, Ticket ticket, Object... values) {
        super(source);
        this.ticket = ticket;
        this.values = values;
    }

    public Ticket getTicket() {
        return ticket;
    }

    public void setTicket(Ticket ticket) {
        this.ticket = ticket;
    }

    public Object[] getValues() {
        return values;
    }

    public void setValues(Object[] values) {
        this.values = values;
    }

}

1 个答案:

答案 0 :(得分:0)

基本上,您可以执行以下操作:

  • 让您的bean实现Serializable

  • transient修饰符添加到未实现Serializable的类成员。

AFAIK,从Java EE 6开始,注入CDI托管bean时可以使用@Inject而不是@EJB