Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package ua.kiev.prog;
- import org.springframework.context.annotation.Bean;
- import org.springframework.context.annotation.ComponentScan;
- import org.springframework.context.annotation.Configuration;
- import org.springframework.jdbc.datasource.DriverManagerDataSource;
- import org.springframework.orm.jpa.JpaTransactionManager;
- import org.springframework.orm.jpa.JpaVendorAdapter;
- import org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean;
- import org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter;
- import org.springframework.security.core.userdetails.UserDetailsService;
- import org.springframework.transaction.PlatformTransactionManager;
- import org.springframework.transaction.annotation.EnableTransactionManagement;
- import org.springframework.web.multipart.commons.CommonsMultipartResolver;
- import org.springframework.web.servlet.config.annotation.EnableWebMvc;
- import org.springframework.web.servlet.view.JstlView;
- import org.springframework.web.servlet.view.UrlBasedViewResolver;
- import javax.persistence.EntityManagerFactory;
- import javax.sql.DataSource;
- import java.util.Properties;
- @Configuration
- @ComponentScan("ua.kiev.prog")
- @EnableTransactionManagement
- @EnableWebMvc
- public class AppConfig {
- @Bean
- public LocalContainerEntityManagerFactoryBean entityManagerFactory
- (DataSource dataSource, JpaVendorAdapter jpaVendeorAdapter)
- {
- LocalContainerEntityManagerFactoryBean entityManagerFactory = new LocalContainerEntityManagerFactoryBean();
- entityManagerFactory.setDataSource(dataSource);
- entityManagerFactory.setJpaVendorAdapter(jpaVendeorAdapter);
- entityManagerFactory.setPackagesToScan("ua.kiev.prog");
- return entityManagerFactory;
- }
- @Bean
- public PlatformTransactionManager transactionManager(EntityManagerFactory emf){
- return new JpaTransactionManager(emf);
- }
- @Bean
- public JpaVendorAdapter jpaVendorAdapter()
- {
- HibernateJpaVendorAdapter adapter = new HibernateJpaVendorAdapter();
- adapter.setShowSql(false);
- adapter.setGenerateDdl(true);
- adapter.setDatabasePlatform("org.hibernate.dialect.MySQLDialect");
- return adapter;
- }
- @Bean
- public DataSource dataSource()
- {
- DriverManagerDataSource ds=new DriverManagerDataSource();
- ds.setDriverClassName("com.mysql.jdbc.Driver");
- ds.setUrl("jdbc:mysql://localhost:3306/vape?characterEncoding=UTF-8");
- ds.setUsername("root");
- ds.setPassword("198007");
- return ds;
- }
- @Bean
- public UrlBasedViewResolver setupViewResolver() {
- UrlBasedViewResolver resolver = new UrlBasedViewResolver();
- resolver.setPrefix("/WEB-INF/pages/");
- resolver.setSuffix(".jsp");
- resolver.setViewClass(JstlView.class);
- resolver.setOrder(1);
- return resolver;
- }
- @Bean
- public CommonsMultipartResolver multipartResolver() {
- return new CommonsMultipartResolver();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement