-
-
Save brmeyer/bbb8688658dd71752738 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 AppConfig { | |
... | |
@Bean | |
public LocalSessionFactoryBean sessionFactory() { | |
LocalSessionFactoryBean sessionFactory = new LocalSessionFactoryBean(); | |
sessionFactory.setDataSource(dataSource()); | |
sessionFactory.setHibernateProperties(hibernateProperties()); | |
... | |
return sessionFactory; | |
} | |
@Bean | |
public HibernateTransactionManager transactionManager() { | |
HibernateTransactionManager txManager = new HibernateTransactionManager(); | |
txManager.setSessionFactory(sessionFactory().getObject()); | |
return txManager; | |
} | |
private DataSource dataSource() { | |
... | |
final HikariDataSource ds = new HikariDataSource(); | |
ds.setMaximumPoolSize(100); | |
ds.setDataSourceClassName("com.mysql.jdbc.jdbc2.optional.MysqlDataSource"); | |
ds.addDataSourceProperty("url", url); | |
ds.addDataSourceProperty("user", username); | |
ds.addDataSourceProperty("password", password); | |
ds.addDataSourceProperty("cachePrepStmts", true); | |
ds.addDataSourceProperty("prepStmtCacheSize", 250); | |
ds.addDataSourceProperty("prepStmtCacheSqlLimit", 2048); | |
ds.addDataSourceProperty("useServerPrepStmts", true); | |
return ds; | |
} | |
private Properties hibernateProperties() { | |
final Properties properties = new Properties(); | |
... (Dialect, 2nd level entity cache, query cache, etc.) | |
return properties; | |
} | |
... | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment