All Downloads are FREE. Search and download functionalities are using the official Maven repository.

fun.bigtable.kraken.config.MongoTemplateClassFieldConfig Maven / Gradle / Ivy

There is a newer version: 2.0.9.1
Show newest version
package fun.bigtable.kraken.config;

import jakarta.annotation.Resource;
import org.springframework.context.ApplicationListener;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.event.ContextRefreshedEvent;
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.data.mongodb.core.convert.DefaultMongoTypeMapper;
import org.springframework.data.mongodb.core.convert.MappingMongoConverter;
import org.springframework.data.mongodb.core.convert.MongoConverter;


/**
 */
@Configuration
public class MongoTemplateClassFieldConfig implements ApplicationListener {

    @Resource
    private MongoTemplate mongoTemplate;

    @Override
    public void onApplicationEvent(ContextRefreshedEvent contextRefreshedEvent) {
        // mongo去掉_class文件
        MongoConverter converter = mongoTemplate.getConverter();
        if (converter.getTypeMapper().isTypeKey("_class")) {
            ((MappingMongoConverter) converter).setTypeMapper(new DefaultMongoTypeMapper(null));
        }
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy