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
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());
}
}