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

com.github.aidensuen.mongo.pagehelper.autoconfigure.PageHelperAutoConfiguration Maven / Gradle / Ivy

There is a newer version: 1.1.2
Show newest version
package com.github.aidensuen.mongo.pagehelper.autoconfigure;

import com.github.aidensuen.mongo.autoconfigure.MongoDaoAutoConfiguration;
import com.github.aidensuen.mongo.interceptor.PageInterceptor;
import com.github.aidensuen.mongo.session.MongoSessionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.AutoConfigureAfter;
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import javax.annotation.PostConstruct;
import java.util.List;
import java.util.Properties;

/**
 * auto config for PageHelper
 *
 * @author aidensuen
 *
 */
@Configuration
@ConditionalOnBean(MongoSessionFactory.class)
@EnableConfigurationProperties(PageHelperProperties.class)
@AutoConfigureAfter(MongoDaoAutoConfiguration.class)
public class PageHelperAutoConfiguration {

    @Autowired
    List mongoSessionFactoryList;

    @Autowired
    PageHelperProperties properties;

    @Bean
    @ConfigurationProperties(prefix = PageHelperProperties.PAGEHELPER_PREFIX)
    public Properties pageHelperProperties() {
        return new Properties();
    }

    @PostConstruct
    public void addPageInterceptor() {
        PageInterceptor interceptor = new PageInterceptor();
        Properties properties = new Properties();
        properties.putAll(pageHelperProperties());
        properties.putAll(this.properties.getProperties());
        interceptor.setProperties(properties);
        for (MongoSessionFactory mongoSessionFactory : mongoSessionFactoryList) {
            mongoSessionFactory.getConfiguration().addInterceptor(interceptor);
        }
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy