Created
May 12, 2015 13:59
-
-
Save japharr/14a5f5a95bac481eac3d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import javax.sql.DataSource; | |
import org.apache.commons.dbcp.BasicDataSource; | |
import org.springframework.beans.factory.annotation.Value; | |
import org.springframework.context.annotation.Bean; | |
import org.springframework.context.annotation.Configuration; | |
import org.springframework.data.jpa.repository.config.EnableJpaRepositories; | |
import org.springframework.orm.jpa.JpaTransactionManager; | |
import org.springframework.orm.jpa.JpaVendorAdapter; | |
import org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean; | |
import org.springframework.orm.jpa.vendor.Database; | |
import org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter; | |
import org.springframework.transaction.PlatformTransactionManager; | |
@Configuration | |
@EnableJpaRepositories({"com.tams.anclock.repository"}) | |
public class DatabaseConfig { | |
@Value("${jdbc.driver}") | |
private String driver; | |
@Value("${jdbc.url}") | |
private String url; | |
@Value("${jdbc.username}") | |
private String username; | |
@Value("${jdbc.password}") | |
private String password; | |
@Bean | |
public DataSource dataSource() { | |
BasicDataSource dataSource = new BasicDataSource(); | |
dataSource.setDriverClassName(driver); | |
dataSource.setUrl(url); | |
dataSource.setUsername(username); | |
dataSource.setPassword(password); | |
return dataSource; | |
} | |
@Bean | |
public LocalContainerEntityManagerFactoryBean entityManagerFactory() { | |
LocalContainerEntityManagerFactoryBean lef = new LocalContainerEntityManagerFactoryBean(); | |
lef.setDataSource(dataSource()); | |
lef.setJpaVendorAdapter(jpaVendorAdapter()); | |
lef.setPackagesToScan(new String[] { "com.tams.anclock.domain" }); | |
//lef.setJpaPropertyMap(jpaPropertyMap()); | |
return lef; | |
} | |
@Bean | |
public JpaVendorAdapter jpaVendorAdapter() { | |
HibernateJpaVendorAdapter hibernateJpaVendorAdapter = new HibernateJpaVendorAdapter(); | |
hibernateJpaVendorAdapter.setShowSql(false); | |
hibernateJpaVendorAdapter.setGenerateDdl(true); | |
hibernateJpaVendorAdapter.setDatabase(Database.MYSQL); | |
hibernateJpaVendorAdapter.setDatabasePlatform("org.hibernate.dialect.MySQL5Dialect"); //MySQLMyISAMDialect //MySQL5Dialect | |
return hibernateJpaVendorAdapter; | |
} | |
/* For Hibernate Search | |
@Bean | |
public Map<String, ?> jpaPropertyMap() { | |
Map<String, String> map = new HashMap<String, String>(); | |
map.put("hibernate.search.default.directory_provider", "filesystem"); | |
map.put("hibernate.search.default.indexBase", dbSettings.getIndexBase()); | |
return map; | |
} | |
*/ | |
@Bean | |
public PlatformTransactionManager transactionManager() { | |
return new JpaTransactionManager(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment