Last active
August 14, 2018 07:28
-
-
Save jeetprksh/e611c9e0b3d1344b0f830265f71505a5 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Configuration | |
@EnableTransactionManagement | |
public class HibernateConfig { | |
@Bean | |
public LocalSessionFactoryBean getSessionFactory() throws PropertyVetoException { | |
LocalSessionFactoryBean bean = new LocalSessionFactoryBean(); | |
Properties hibernateProperties = new Properties(); | |
hibernateProperties.put("hibernate.dialect", "org.hibernate.dialect.MySQLDialect"); | |
hibernateProperties.put("hibernate.show_sql", "true"); | |
bean.setHibernateProperties(hibernateProperties); | |
bean.setDataSource(getDataSource()); | |
bean.setPackagesToScan("com.spring5.app.dto"); | |
return bean; | |
} | |
@Bean | |
public ComboPooledDataSource getDataSource() throws PropertyVetoException { | |
ComboPooledDataSource dataSource = new ComboPooledDataSource(); | |
dataSource.setDriverClass("com.mysql.cj.jdbc.Driver"); | |
dataSource.setJdbcUrl("jdbc:mysql://localhost:3306/app-db?useSSL=false"); | |
dataSource.setUser("root"); | |
dataSource.setPassword("qwerty123"); | |
dataSource.setAcquireIncrement(10); | |
dataSource.setIdleConnectionTestPeriod(0); | |
dataSource.setInitialPoolSize(5); | |
dataSource.setMaxIdleTime(0); | |
dataSource.setMaxPoolSize(50); | |
dataSource.setMaxStatements(100); | |
dataSource.setMinPoolSize(5); | |
return dataSource; | |
} | |
@Bean | |
public JdbcTemplate getJdbcTemplate() throws PropertyVetoException { | |
JdbcTemplate template = new JdbcTemplate(); | |
template.setDataSource(getDataSource()); | |
return template; | |
} | |
@Bean | |
public HibernateTransactionManager getTransactionManager() throws PropertyVetoException { | |
HibernateTransactionManager transactionManager = new HibernateTransactionManager(); | |
transactionManager.setSessionFactory(getSessionFactory().getObject()); | |
return transactionManager; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment