Guest User

Untitled

a guest
Nov 18th, 2018
133
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.13 KB | None | 0 0
  1. @Configuration
  2. @EnableWebMvc
  3. @ComponentScan(basePackages = "first.test")
  4. @EnableTransactionManagement
  5. public class WebConfig implements WebMvcConfigurer {
  6. @Bean
  7. public ViewResolver internalResourceViewResolver() {
  8. InternalResourceViewResolver bean = new InternalResourceViewResolver();
  9. bean.setViewClass(JstlView.class);
  10. bean.setPrefix("/WEB-INF/templates/");
  11. bean.setSuffix(".jsp");
  12. return bean;
  13. }
  14.  
  15. @Bean
  16. public LocalContainerEntityManagerFactoryBean entityManagerFactory() {
  17. LocalContainerEntityManagerFactoryBean em = new LocalContainerEntityManagerFactoryBean();
  18. em.setDataSource(dataSource());
  19. em.setPackagesToScan(new String[] {"first.test"});
  20. em.setJpaDialect(new HibernateJpaDialect());
  21. em.setJpaVendorAdapter(new HibernateJpaVendorAdapter());
  22. em.setJpaProperties(additionalProperties());
  23. return em;
  24. }
  25.  
  26. Properties additionalProperties() {
  27. Properties properties = new Properties();
  28. properties.setProperty("hibernate.hbm2ddl.auto", "drop-and-create");
  29. properties.setProperty("hibernate.dialect", "org.hibernate.dialect.MySQL5InnoDBDialect");
  30. properties.setProperty("hibernate.show_sql", "true");
  31. properties.setProperty("hibernate.format_sql", "true");
  32. return properties;
  33. }
  34.  
  35. @Bean
  36. public PlatformTransactionManager transactionManager(EntityManagerFactory emf) {
  37. JpaTransactionManager transactionManager = new JpaTransactionManager();
  38. transactionManager.setEntityManagerFactory(emf);
  39. return transactionManager;
  40. }
  41.  
  42. @Bean
  43. public PersistenceExceptionTranslationPostProcessor exceptionTranslation() {
  44. return new PersistenceExceptionTranslationPostProcessor();
  45. }
  46.  
  47. @Bean
  48. public DataSource dataSource() {
  49. DriverManagerDataSource dataSource = new DriverManagerDataSource();
  50. dataSource.setDriverClassName("com.mysql.jdbc.Driver");
  51. dataSource.setUrl("jdbc:mysql://localhost:3306/testdb?useSSL=false");
  52. dataSource.setUsername("root");
  53. dataSource.setPassword("tajne123");
  54. return dataSource;
  55. }
  56. }
Add Comment
Please, Sign In to add comment