Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package org.lightadmin.demo.configuration;
- import org.springframework.beans.factory.annotation.Autowired;
- import org.springframework.context.annotation.Bean;
- import org.springframework.context.annotation.Configuration;
- import org.springframework.data.jpa.repository.config.EnableJpaRepositories;
- import org.springframework.jdbc.datasource.DriverManagerDataSource;
- import org.springframework.orm.jpa.JpaTransactionManager;
- import org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean;
- import org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter;
- import org.springframework.transaction.annotation.EnableTransactionManagement;
- import javax.sql.DataSource;
- import java.util.Properties;
- import static org.springframework.orm.jpa.vendor.Database.MYSQL;
- @Configuration
- @EnableTransactionManagement
- @EnableJpaRepositories(basePackages = {"org.lightadmin.demo.persistence"})
- public class ApplicationConfiguration {
- @Bean
- @Autowired
- public LocalContainerEntityManagerFactoryBean entityManagerFactory(DataSource dataSource) {
- final HibernateJpaVendorAdapter vendorAdapter = new HibernateJpaVendorAdapter();
- vendorAdapter.setDatabasePlatform("org.hibernate.dialect.MySQL5InnoDBDialect");
- vendorAdapter.setDatabase(MYSQL);
- vendorAdapter.setGenerateDdl(true);
- vendorAdapter.setShowSql(false);
- final LocalContainerEntityManagerFactoryBean factory = new LocalContainerEntityManagerFactoryBean();
- factory.setJpaVendorAdapter(vendorAdapter);
- factory.setPackagesToScan("org.lightadmin.demo.domain");
- factory.setDataSource(dataSource);
- factory.setJpaProperties(jpaProperties());
- return factory;
- }
- @Bean
- public JpaTransactionManager transactionManager() {
- return new JpaTransactionManager();
- }
- @Bean
- public DataSource dataSource() {
- DriverManagerDataSource dataSource = new DriverManagerDataSource();
- dataSource.setDriverClassName("com.mysql.jdbc.Driver");
- dataSource.setUrl("jdbc:mysql://localhost:3306/lightadmin-demo?useUnicode=true&connectionCollation=utf8_general_ci&characterSetResults=utf8&characterEncoding=utf8");
- dataSource.setUsername("root");
- dataSource.setPassword("sun1ssh1n1ng");
- return dataSource;
- }
- private Properties jpaProperties() {
- final Properties jpaProperties = new Properties();
- jpaProperties.setProperty("hibernate.ejb.naming_strategy", "org.hibernate.cfg.ImprovedNamingStrategy");
- return jpaProperties;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement