Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.eventapp.rest.conf;
- import java.util.Properties;
- import javax.sql.DataSource;
- import org.hibernate.SessionFactory;
- import org.springframework.beans.factory.annotation.Autowired;
- import org.springframework.context.annotation.Bean;
- import org.springframework.context.annotation.ComponentScan;
- import org.springframework.context.annotation.Configuration;
- import org.springframework.jdbc.datasource.DriverManagerDataSource;
- import org.springframework.orm.hibernate5.HibernateTransactionManager;
- import org.springframework.orm.hibernate5.LocalSessionFactoryBean;
- import org.springframework.transaction.annotation.EnableTransactionManagement;
- import org.springframework.web.servlet.config.annotation.EnableWebMvc;
- @Configuration
- @EnableTransactionManagement
- @ComponentScan(
- basePackages = {"com.eventapp.*"})
- @EnableWebMvc
- public class EventApp {
- @Bean
- public LocalSessionFactoryBean sessionFactory() {
- LocalSessionFactoryBean sessionFactory = new LocalSessionFactoryBean();
- sessionFactory.setDataSource(dataSource());
- sessionFactory.setPackagesToScan(new String[] { "com.eventapp.db.model" });
- sessionFactory.setHibernateProperties(hibernateProperties());
- return sessionFactory;
- }
- @Bean
- public DataSource dataSource() {
- DriverManagerDataSource dataSource = new DriverManagerDataSource();
- dataSource.setDriverClassName("org.postgresql.Driver");
- dataSource.setUrl("jdbc:postgresql://localhost:5432/eventapp");
- dataSource.setUsername("postgres");
- dataSource.setPassword("zaq1@WSX");
- return dataSource;
- }
- private Properties hibernateProperties() {
- Properties properties = new Properties();
- properties.put("hibernate.dialect", "org.hibernate.dialect.MySQLDialect");
- properties.put("hibernate.show_sql", "false");
- properties.put("hibernate.format_sql", "false");
- return properties;
- }
- @Bean
- @Autowired
- public HibernateTransactionManager transactionManager(SessionFactory s) {
- HibernateTransactionManager txManager = new HibernateTransactionManager();
- txManager.setSessionFactory(s);
- return txManager;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement