daily pastebin goal
28%
SHARE
TWEET

Untitled

a guest Mar 20th, 2017 94 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. package ua.kiev.prog;
  2.  
  3. import org.springframework.context.annotation.Bean;
  4. import org.springframework.context.annotation.ComponentScan;
  5. import org.springframework.context.annotation.Configuration;
  6. import org.springframework.jdbc.datasource.DriverManagerDataSource;
  7. import org.springframework.orm.jpa.JpaTransactionManager;
  8. import org.springframework.orm.jpa.JpaVendorAdapter;
  9. import org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean;
  10. import org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter;
  11. import org.springframework.security.core.userdetails.UserDetailsService;
  12. import org.springframework.transaction.PlatformTransactionManager;
  13. import org.springframework.transaction.annotation.EnableTransactionManagement;
  14. import org.springframework.web.multipart.commons.CommonsMultipartResolver;
  15. import org.springframework.web.servlet.config.annotation.EnableWebMvc;
  16. import org.springframework.web.servlet.view.JstlView;
  17. import org.springframework.web.servlet.view.UrlBasedViewResolver;
  18.  
  19. import javax.persistence.EntityManagerFactory;
  20. import javax.sql.DataSource;
  21. import java.util.Properties;
  22.  
  23.  
  24. @Configuration
  25. @ComponentScan("ua.kiev.prog")
  26. @EnableTransactionManagement
  27. @EnableWebMvc
  28. public class AppConfig {
  29.  
  30.     @Bean
  31.     public LocalContainerEntityManagerFactoryBean entityManagerFactory
  32.             (DataSource dataSource, JpaVendorAdapter jpaVendeorAdapter)
  33.     {
  34.         LocalContainerEntityManagerFactoryBean entityManagerFactory = new LocalContainerEntityManagerFactoryBean();
  35.         entityManagerFactory.setDataSource(dataSource);
  36.         entityManagerFactory.setJpaVendorAdapter(jpaVendeorAdapter);
  37.         entityManagerFactory.setPackagesToScan("ua.kiev.prog");
  38.  
  39.         return entityManagerFactory;
  40.     }
  41.  
  42.     @Bean
  43.     public PlatformTransactionManager transactionManager(EntityManagerFactory emf){
  44.         return new JpaTransactionManager(emf);
  45.     }
  46.  
  47.     @Bean
  48.     public JpaVendorAdapter jpaVendorAdapter()
  49.     {
  50.         HibernateJpaVendorAdapter adapter = new HibernateJpaVendorAdapter();
  51.        
  52.         adapter.setShowSql(false);
  53.         adapter.setGenerateDdl(true);
  54.         adapter.setDatabasePlatform("org.hibernate.dialect.MySQLDialect");
  55.  
  56.         return adapter;
  57.     }
  58.  
  59.  
  60.  
  61.  
  62.  
  63.     @Bean
  64.     public DataSource dataSource()
  65.     {
  66.         DriverManagerDataSource ds=new DriverManagerDataSource();
  67.         ds.setDriverClassName("com.mysql.jdbc.Driver");
  68.         ds.setUrl("jdbc:mysql://localhost:3306/vape?characterEncoding=UTF-8");
  69.         ds.setUsername("root");
  70.         ds.setPassword("198007");
  71.  
  72.         return ds;
  73.     }
  74.  
  75.     @Bean
  76.     public UrlBasedViewResolver setupViewResolver() {
  77.         UrlBasedViewResolver resolver = new UrlBasedViewResolver();
  78.         resolver.setPrefix("/WEB-INF/pages/");
  79.         resolver.setSuffix(".jsp");
  80.         resolver.setViewClass(JstlView.class);
  81.         resolver.setOrder(1);
  82.         return resolver;
  83.     }
  84.  
  85.     @Bean
  86.     public CommonsMultipartResolver multipartResolver() {
  87.         return new CommonsMultipartResolver();
  88.     }
  89. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top