How to configure EclipseLink 2.0 and Spring 3.0.5 and Tomcat 6?

前端 未结 3 1166
清酒与你
清酒与你 2020-12-30 17:37

My web application is using Tomcat 6.0.18 and Spring 3.0.5 and eclipselink 2.0.1 and javax.persistence 2.0.0, SQL Server Database. I could not figure out the configuration

3条回答
  •  孤独总比滥情好
    2020-12-30 18:41

    As an additional way to @jisun's reply.I did it by annotation configuration and removed more properties such as username,password,driver etc.Because all of these parameters can be define in persistence.xml:

    package com.company.config;
    
    import javax.annotation.Resource;
    import org.springframework.context.annotation.Bean;
    import org.springframework.context.annotation.ComponentScan;
    import org.springframework.context.annotation.Configuration;
    import org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean;
    import org.springframework.transaction.annotation.EnableTransactionManagement;
    import org.springframework.web.servlet.config.annotation.EnableWebMvc;
    import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;
    import org.springframework.core.env.Environment;
    import org.springframework.instrument.classloading.ReflectiveLoadTimeWeaver;
    import org.springframework.orm.jpa.JpaTransactionManager;
    
    @Configuration
    @ComponentScan(basePackages = "com.company")
    @EnableTransactionManagement
    @EnableWebMvc
    public class MvcConfiguration extends WebMvcConfigurerAdapter {
    
    
        @Resource
        private Environment env;
    
        @Bean
        public LocalContainerEntityManagerFactoryBean entityManagerFactory() {
            LocalContainerEntityManagerFactoryBean emf = new LocalContainerEntityManagerFactoryBean();
            emf.setPersistenceXmlLocation("classpath:persistence.xml");
            emf.setLoadTimeWeaver(new ReflectiveLoadTimeWeaver());
            return emf;
        }
    
        @Bean
        public JpaTransactionManager transactionManager() {
            return new JpaTransactionManager(entityManagerFactory().getObject());
        }
    
    }
    

提交回复
热议问题