Advertisement
Guest User

Untitled

a guest
Apr 18th, 2017
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.98 KB | None | 0 0
  1. @PropertySource({ "classpath:application.properties" })
  2. @Configuration
  3. @EnableJpaRepositories(
  4. basePackages = "com.projectx.mysql",
  5. entityManagerFactoryRef = "userEntityManager",
  6. transactionManagerRef = "userTransactionManager"
  7. )
  8. public class DataBaseConfig {
  9.  
  10. @Autowired
  11. Environment env;
  12.  
  13.  
  14. @Bean
  15. @Primary
  16. public LocalContainerEntityManagerFactoryBean userEntityManager() {
  17. LocalContainerEntityManagerFactoryBean em = new LocalContainerEntityManagerFactoryBean();
  18. em.setDataSource(primaryDataSource());
  19. em.setPackagesToScan(new String[] { "com.projectx.mysql" });
  20. HibernateJpaVendorAdapter vendorAdapter = new HibernateJpaVendorAdapter();
  21. em.setJpaVendorAdapter(vendorAdapter);
  22. HashMap<String, Object> properties = new HashMap<String, Object>();
  23. properties.put("hibernate.hbm2ddl.auto", env.getProperty("spring.jpa.hibernate.ddl-auto_mysql"));
  24. properties.put("hibernate.dialect", env.getProperty("spring.jpa.properties.hibernate.dialect_mysql"));
  25. properties.put("hibernate.show_sql", env.getProperty("spring.jpa.show-sql"));
  26. em.setJpaPropertyMap(properties);
  27.  
  28. return em;
  29. }
  30.  
  31. @Bean
  32. @ConfigurationProperties(prefix = "spring.datasource")
  33. public DataSource primaryDataSource() {
  34. return DataSourceBuilder.create().build();
  35. }
  36.  
  37.  
  38. @Primary
  39. @Bean
  40. public PlatformTransactionManager userTransactionManager() {
  41. JpaTransactionManager transactionManager = new JpaTransactionManager();
  42. transactionManager.setEntityManagerFactory(userEntityManager().getObject());
  43. return transactionManager;
  44. }
  45. }
  46.  
  47. spring.datasource.initialize=true
  48. spring.datasource.url=jdbc:mysql://localhost/test
  49. spring.datasource.username=root
  50. spring.datasource.password=
  51. spring.datasource.driverClassName=com.mysql.jdbc.Driver
  52. spring.jpa.show-sql: true
  53. spring.jpa.hibernate.ddl-auto_mysql=update
  54. spring.jpa.properties.hibernate.dialect_mysql=org.hibernate.dialect.MySQL5Dialect
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement