Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- @configuration
- @EnableJpaRepositories("com.phil.fu.core.dao")
- @EnableTransactionManagement
- public class DatabaseConfig {
- @Bean
- public DataSource dataSource() {
- HikariConfig config = new HikariConfig();
- config.setMaximumPoolSize(20); // MinimumIdle, PoolName, IdleTimeout, MaxLifetime, ConnectionTimeout
- config.setDataSourceClassName("com.mysql.jdbc.jdbc2.optional.MysqlDataSource);
- config.addDataSourceProperty("url", "jdbc:mysql://..");
- return new HikariDataSource(config);
- }
- @Bean
- public LocalContainerEntityManagerFactoryBean entityManagerFactory() {
- HibernateJpaVendorAdapter vendorAdapter = new HibernateJpaVendorAdapter();
- vendorAdapter.setDatabase(Database.MYSQL);
- LocalContainerEntityManagerFactoryBean factory = new LocalContainerEntiryManagerFactoryBean();
- Map<String, Object> jpaProperties = new HashMap<>();
- jpaProperties.put("hibernate.jdbc.fetch_size", 50); hibernate.jdbc.batch_size, hibernate.show_sql
- factory.setJpaVendorAdapter(vendorAdapter);
- factory.setJpaPropertyMap(jpaProperties);
- factory.setPackagesToScan("com.phil.fu.core.domain");
- factory.setDataSource(dataSource());
- return factory;
- }
- @Bean
- public PlatformTransactionManager transactionManager() {
- JpaTransactionManager transactionManager = new JpaTransactionManager();
- transactionManager.setEntityManagerFactory(entityManagerFactory().getObject());
- return transactionManager;
- }
- @Bean
- public TransactionTemplate transactionTemplate() {
- return new TransactionTemplate(transactionManger());
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement