Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- @Configuration
- @EnableWebMvc
- @ComponentScan(basePackages = "first.test")
- @EnableTransactionManagement
- public class WebConfig implements WebMvcConfigurer {
- @Bean
- public ViewResolver internalResourceViewResolver() {
- InternalResourceViewResolver bean = new InternalResourceViewResolver();
- bean.setViewClass(JstlView.class);
- bean.setPrefix("/WEB-INF/templates/");
- bean.setSuffix(".jsp");
- return bean;
- }
- @Bean
- public LocalContainerEntityManagerFactoryBean entityManagerFactory() {
- LocalContainerEntityManagerFactoryBean em = new LocalContainerEntityManagerFactoryBean();
- em.setDataSource(dataSource());
- em.setPackagesToScan(new String[] {"first.test"});
- em.setJpaDialect(new HibernateJpaDialect());
- em.setJpaVendorAdapter(new HibernateJpaVendorAdapter());
- em.setJpaProperties(additionalProperties());
- return em;
- }
- Properties additionalProperties() {
- Properties properties = new Properties();
- properties.setProperty("hibernate.hbm2ddl.auto", "drop-and-create");
- properties.setProperty("hibernate.dialect", "org.hibernate.dialect.MySQL5InnoDBDialect");
- properties.setProperty("hibernate.show_sql", "true");
- properties.setProperty("hibernate.format_sql", "true");
- return properties;
- }
- @Bean
- public PlatformTransactionManager transactionManager(EntityManagerFactory emf) {
- JpaTransactionManager transactionManager = new JpaTransactionManager();
- transactionManager.setEntityManagerFactory(emf);
- return transactionManager;
- }
- @Bean
- public PersistenceExceptionTranslationPostProcessor exceptionTranslation() {
- return new PersistenceExceptionTranslationPostProcessor();
- }
- @Bean
- public DataSource dataSource() {
- DriverManagerDataSource dataSource = new DriverManagerDataSource();
- dataSource.setDriverClassName("com.mysql.jdbc.Driver");
- dataSource.setUrl("jdbc:mysql://localhost:3306/testdb?useSSL=false");
- dataSource.setUsername("root");
- dataSource.setPassword("tajne123");
- return dataSource;
- }
- }
Add Comment
Please, Sign In to add comment