Guest User

Untitled

a guest
Aug 12th, 2018
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.85 KB | None | 0 0
  1. @Configuration
  2. @EnableTransactionManagement
  3. public class HibernateConfig {
  4.  
  5. @Bean
  6. public LocalSessionFactoryBean getSessionFactory() throws PropertyVetoException {
  7. LocalSessionFactoryBean bean = new LocalSessionFactoryBean();
  8.  
  9. Properties hibernateProperties = new Properties();
  10. hibernateProperties.put("hibernate.dialect", "org.hibernate.dialect.MySQLDialect");
  11. hibernateProperties.put("hibernate.show_sql", "true");
  12.  
  13. bean.setHibernateProperties(hibernateProperties);
  14. bean.setDataSource(getDataSource());
  15. bean.setPackagesToScan("com.spring5.app.dto");
  16. return bean;
  17. }
  18.  
  19. @Bean
  20. public ComboPooledDataSource getDataSource() throws PropertyVetoException {
  21. ComboPooledDataSource dataSource = new ComboPooledDataSource();
  22.  
  23. dataSource.setDriverClass("com.mysql.cj.jdbc.Driver");
  24. dataSource.setJdbcUrl("jdbc:mysql://localhost:3306/app-db?useSSL=false");
  25. dataSource.setUser("root");
  26. dataSource.setPassword("qwerty123");
  27. dataSource.setAcquireIncrement(10);
  28. dataSource.setIdleConnectionTestPeriod(0);
  29. dataSource.setInitialPoolSize(5);
  30. dataSource.setMaxIdleTime(0);
  31. dataSource.setMaxPoolSize(50);
  32. dataSource.setMaxStatements(100);
  33. dataSource.setMinPoolSize(5);
  34.  
  35. return dataSource;
  36. }
  37.  
  38. @Bean
  39. public JdbcTemplate getJdbcTemplate() throws PropertyVetoException {
  40. JdbcTemplate template = new JdbcTemplate();
  41. template.setDataSource(getDataSource());
  42. return template;
  43. }
  44.  
  45. @Bean
  46. public HibernateTransactionManager getTransactionManager() throws PropertyVetoException {
  47. HibernateTransactionManager transactionManager = new HibernateTransactionManager();
  48. transactionManager.setSessionFactory(getSessionFactory().getObject());
  49. return transactionManager;
  50. }
  51.  
  52. }
Add Comment
Please, Sign In to add comment