Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <Resource name="jdbc/my_ds"
- auth="Container"
- type="javax.sql.DataSource"
- driverClassName="org.mariadb.jdbc.Driver"
- url="jdbc:mariadb:failover://localhost:3306/mine"
- username="mine"
- password="me"
- initalSize="1"
- minIdle="1"
- maxIdle="30"
- maxActive="100"
- maxWait="10000"
- jmxEnabled="true"
- validationQuery="SELECT 1"
- testOnBorrow="true"
- minEvictableIdleTimeMillis="60000"
- timeBetweenEvictionRunsMillis="5000"
- />
- @Configuration
- @ComponentScan
- @EnableJpaRepositories
- @EnableTransactionManagement
- public class AppConfiguration {
- @Bean
- public DataSource dataSource() {
- JndiDataSourceLookup lookup = new JndiDataSourceLookup();
- return lookup.getDataSource("/jdbc/my_ds");
- }
- @Bean
- public EntityManagerFactory entityManagerFactory() {
- HibernateJpaVendorAdapter vendorAdapter = new HibernateJpaVendorAdapter();
- vendorAdapter.setGenerateDdl(true);
- vendorAdapter.setShowSql(true);
- LocalContainerEntityManagerFactoryBean factory = new LocalContainerEntityManagerFactoryBean();
- factory.setJpaVendorAdapter(vendorAdapter);
- factory.setPackagesToScan("com.example.persistence");
- factory.setDataSource(dataSource());
- factory.afterPropertiesSet();
- return factory.getObject();
- }
- @Bean
- public PlatformTransactionManager transactionManager() {
- JpaTransactionManager txManager = new JpaTransactionManager();
- txManager.setEntityManagerFactory(entityManagerFactory());
- return txManager;
- }
- }
- @Bean
- public DataSource dataSource() {
- return new DriverManagerDataSource("jdbc:mariadb://localhost:3306/mine", "mine", "my");
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement