Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/323.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Mongo java.lang.IllegalArgumentException:can';t序列化类java.lang.class_Java_Xml_Spring_Mongodb_Serialization - Fatal编程技术网

Mongo java.lang.IllegalArgumentException:can';t序列化类java.lang.class

Mongo java.lang.IllegalArgumentException:can';t序列化类java.lang.class,java,xml,spring,mongodb,serialization,Java,Xml,Spring,Mongodb,Serialization,我正在使用Java+Spring+MongoTemplate+MongoDB。如果我想将对象插入我的MongoDB,那么我有一个错误: java.lang.IllegalArgumentException: can't serialize class java.lang.Class 以下是我的mongo-context.xml: <mongo:mongo id="mongoLocal" host="${local.mongo.host}" port="${local.mongo

我正在使用Java+Spring+MongoTemplate+MongoDB。如果我想将对象插入我的MongoDB,那么我有一个错误:

 java.lang.IllegalArgumentException: can't serialize class java.lang.Class
以下是我的mongo-context.xml:

    <mongo:mongo id="mongoLocal" host="${local.mongo.host}" port="${local.mongo.port}">
    <mongo:options
            connections-per-host="700"
            threads-allowed-to-block-for-connection-multiplier="100"
            connect-timeout="15000"
            auto-connect-retry="true"
            socket-timeout="60000"
            write-number="1"/>
</mongo:mongo>

<mongo:db-factory id="mongoDbFactoryLocal" dbname="${local.mongo.db}" mongo-ref="mongoLocal"/>

<bean id="mongoConverterLocal" class="org.springframework.data.mongodb.core.convert.MappingMongoConverter">
    <constructor-arg index="0" ref="mongoDbFactoryLocal" />
    <constructor-arg index="1">
        <bean class="org.springframework.data.mongodb.core.mapping.MongoMappingContext" />
    </constructor-arg>
    <property name="mapKeyDotReplacement" value="\+"/>
</bean>

<bean id="mongoTemplateLocal" class="org.springframework.data.mongodb.core.MongoTemplate">
    <constructor-arg name="mongoDbFactory" ref="mongoDbFactoryLocal"/>
    <constructor-arg name="mongoConverter" ref="mongoConverterLocal"/>
</bean>

@文档
公共类EmlMessage扩展消息{
私有WatchEvent.Kind eventType;
私有字符串emlPath;
公共信息(){
超级();
}
公共EML消息(字符串id,
WatchEvent.Kind eventType,
StatusType StatusType,
字符串(emlPath){
super(id,statusType);
this.eventType=eventType;
this.emlPath=emlPath;
}
公共EML消息(字符串id,
字符串事件类型,
StatusType StatusType,
字符串(emlPath){
super(id,statusType);
this.emlPath=emlPath;
选择事件类型(eventType);
}
public WatchEvent.Kind getEventType(){
返回事件类型;
}
public void setEventType(WatchEvent.Kind eventType){
this.eventType=eventType;
}
public void setEventType(字符串eventType){
选择事件类型(eventType);
}
private void chooseEventType(字符串事件类型){
if(eventType.equalsIgnoreCase(“条目创建”))
this.eventType=StandardWatchEventTypes.ENTRY\u CREATE;
else if(eventType.equalsIgnoreCase(“条目修改”))
this.eventType=StandardWatchEventTypes.ENTRY\u MODIFY;
else if(eventType.equalsIgnoreCase(“条目\删除”))
this.eventType=StandardWatchEventTypes.ENTRY\u DELETE;
其他的
this.eventType=null;
}
@凌驾
公共int hashCode(){
int hash=1;
hash=hash*31+(getId()==null?
“”.hashCode():getId().hashCode());
散列=散列
+(arriveDateTime==null?0:arriveDateTime.hashCode());
返回散列;
}
@凌驾
公共布尔等于(对象obj){
if(this==obj)
返回true;
如果(!(obj EML消息实例))
返回false;
SimpleMessage otherA=(SimpleMessage)obj;
返回getId().equals(otherA.getId());
}
}

有什么想法吗?我知道我可以扩展BasicDBObject,但如果我实现了MongoMappingConverter,为什么我需要这么做。

问题在于变量WatchEvent.king类似于java.nio.file.StandardwatchEventKings。该类是公共最终类StandardWatchEventKinds。我刚换成了弦乐。现在看起来像

 @Document
public class EmlMessage extends Message {

    private String eventType;
    private String emlPath;

    public EmlMessage() {
        super();
    }

    public EmlMessage(String id,
                      WatchEvent.Kind<Path> eventType,
                      StatusType statusType,
                      String emlPath) {

        super(id, statusType);
        this.eventType = eventType.name();
        this.emlPath = emlPath;
    }

    public EmlMessage(String id,
                      String eventType,
                      StatusType statusType,
                      String emlPath) {

        super(id, statusType);
        this.emlPath = emlPath;
        this.eventType = eventType;
    }

    public String getEventType() {
        return eventType;
    }

    public void setEventType(WatchEvent.Kind<Path> eventType) {
        this.eventType = eventType.name();
    }

    public void setEventType(String eventType) {
        this.eventType = eventType;
    }

    public String getEmlPath() {
        return emlPath;
    }

    public void setEmlPath(String emlPath) {
        this.emlPath = emlPath;
    }
@文档
公共类EmlMessage扩展消息{
私有字符串事件类型;
私有字符串emlPath;
公共信息(){
超级();
}
公共EML消息(字符串id,
WatchEvent.Kind eventType,
StatusType StatusType,
字符串(emlPath){
super(id,statusType);
this.eventType=eventType.name();
this.emlPath=emlPath;
}
公共EML消息(字符串id,
字符串事件类型,
StatusType StatusType,
字符串(emlPath){
super(id,statusType);
this.emlPath=emlPath;
this.eventType=eventType;
}
公共字符串getEventType(){
返回事件类型;
}
public void setEventType(WatchEvent.Kind eventType){
this.eventType=eventType.name();
}
public void setEventType(字符串eventType){
this.eventType=eventType;
}
公共字符串getEmlPath(){
返回emlPath;
}
公共void setEmlPath(字符串emlPath){
this.emlPath=emlPath;
}

您看到了吗?当然,正如您所看到的,我实现了默认构造函数并实现了可通过扩展类消息序列化。
    public abstract class Message implements Serializable {

    @Id
    private String id;

    public Message() {super();}

    public Message(String id) {
        this.id = id;
    }

    public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id;
    }
}
      @Document
public class EmlMessage extends Message {

    private WatchEvent.Kind<Path> eventType;
    private String emlPath;

    public EmlMessage() {
        super();
    }

    public EmlMessage(String id,
                      WatchEvent.Kind<Path> eventType,
                      StatusType statusType,
                      String emlPath) {

        super(id, statusType);
        this.eventType = eventType;
        this.emlPath = emlPath;
    }

    public EmlMessage(String id,
                      String eventType,
                      StatusType statusType,
                      String emlPath) {

        super(id, statusType);
        this.emlPath = emlPath;
        chooseEventType(eventType);
    }

    public WatchEvent.Kind<Path> getEventType() {
        return eventType;
    }

    public void setEventType(WatchEvent.Kind<Path> eventType) {
        this.eventType = eventType;
    }

    public void setEventType(String eventType) {
        chooseEventType(eventType);
    }

    private void chooseEventType(String eventType) {

        if (eventType.equalsIgnoreCase("ENTRY_CREATE"))
            this.eventType = StandardWatchEventKinds.ENTRY_CREATE;
        else if (eventType.equalsIgnoreCase("ENTRY_MODIFY"))
            this.eventType = StandardWatchEventKinds.ENTRY_MODIFY;
        else if (eventType.equalsIgnoreCase("ENTRY_DELETE"))
            this.eventType = StandardWatchEventKinds.ENTRY_DELETE;
        else
            this.eventType = null;

    }

    @Override
    public int hashCode() {
        int hash = 1;
        hash = hash * 31 + (getId() == null ?
                "".hashCode() : getId().hashCode());       
        hash = hash
                + (arriveDateTime == null ? 0 : arriveDateTime.hashCode());

        return hash;
    }

    @Override
    public boolean equals(Object obj) {
        if (this == obj)
            return true;

        if (!(obj instanceof EmlMessage))
            return false;

        SimpleMessage otherA = (SimpleMessage) obj;
        return getId().equals(otherA.getId());
    }
}
 @Document
public class EmlMessage extends Message {

    private String eventType;
    private String emlPath;

    public EmlMessage() {
        super();
    }

    public EmlMessage(String id,
                      WatchEvent.Kind<Path> eventType,
                      StatusType statusType,
                      String emlPath) {

        super(id, statusType);
        this.eventType = eventType.name();
        this.emlPath = emlPath;
    }

    public EmlMessage(String id,
                      String eventType,
                      StatusType statusType,
                      String emlPath) {

        super(id, statusType);
        this.emlPath = emlPath;
        this.eventType = eventType;
    }

    public String getEventType() {
        return eventType;
    }

    public void setEventType(WatchEvent.Kind<Path> eventType) {
        this.eventType = eventType.name();
    }

    public void setEventType(String eventType) {
        this.eventType = eventType;
    }

    public String getEmlPath() {
        return emlPath;
    }

    public void setEmlPath(String emlPath) {
        this.emlPath = emlPath;
    }