package com.malk;

import com.querydsl.jpa.impl.JPAQueryFactory;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.Bean;
import org.springframework.data.jpa.repository.config.EnableJpaAuditing;

import javax.persistence.EntityManager;

@EnableJpaAuditing
@SpringBootApplication
public class Boot {

    public static void main(String... args) {
        SpringApplication.run(Boot.class, args);
    }

    /**
     * 让Spring管理JPAQueryFactory [多数据源配置详见DataSourceConfig]
     *
     * @Qualifier("entityManagerFactory") 单数据源指向
     * @Qualifier("entityManagerFactoryPrimary") 多数据源指向
     */
    @Bean
    public JPAQueryFactory jpaQueryFactory(EntityManager entityManager) {
        return new JPAQueryFactory(entityManager);
    }
}