Advertisement
Guest User

Untitled

a guest
Feb 7th, 2017
139
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.65 KB | None | 0 0
  1. @configuration
  2. @EnableJpaRepositories("com.phil.fu.core.dao")
  3. @EnableTransactionManagement
  4. public class DatabaseConfig {
  5. @Bean
  6. public DataSource dataSource() {
  7. HikariConfig config = new HikariConfig();
  8. config.setMaximumPoolSize(20); // MinimumIdle, PoolName, IdleTimeout, MaxLifetime, ConnectionTimeout
  9. config.setDataSourceClassName("com.mysql.jdbc.jdbc2.optional.MysqlDataSource);
  10. config.addDataSourceProperty("url", "jdbc:mysql://..");
  11. return new HikariDataSource(config);
  12. }
  13.  
  14. @Bean
  15. public LocalContainerEntityManagerFactoryBean entityManagerFactory() {
  16. HibernateJpaVendorAdapter vendorAdapter = new HibernateJpaVendorAdapter();
  17. vendorAdapter.setDatabase(Database.MYSQL);
  18.  
  19. LocalContainerEntityManagerFactoryBean factory = new LocalContainerEntiryManagerFactoryBean();
  20. Map<String, Object> jpaProperties = new HashMap<>();
  21. jpaProperties.put("hibernate.jdbc.fetch_size", 50); hibernate.jdbc.batch_size, hibernate.show_sql
  22. factory.setJpaVendorAdapter(vendorAdapter);
  23. factory.setJpaPropertyMap(jpaProperties);
  24. factory.setPackagesToScan("com.phil.fu.core.domain");
  25. factory.setDataSource(dataSource());
  26. return factory;
  27. }
  28.  
  29. @Bean
  30. public PlatformTransactionManager transactionManager() {
  31. JpaTransactionManager transactionManager = new JpaTransactionManager();
  32. transactionManager.setEntityManagerFactory(entityManagerFactory().getObject());
  33. return transactionManager;
  34. }
  35.  
  36. @Bean
  37. public TransactionTemplate transactionTemplate() {
  38. return new TransactionTemplate(transactionManger());
  39. }
  40. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement