configuration
@Configuration
@EntityScan("com.codecraft.domain")
@EnableJpaRepositories(basePackages = "com.codecraft",entityManagerFactoryRef = "pgEntityManagerFactory",
transactionManagerRef = "pgTransactionManager")
public class JpaConfig {
@Autowired
@Qualifier("pgDataSource")
public DataSource pgDataSource;
@Bean
PlatformTransactionManager pgTransactionManager() {
return new JpaTransactionManager(pgEntityManagerFactory().getObject());
}
@Bean
LocalContainerEntityManagerFactoryBean pgEntityManagerFactory() {
HibernateJpaVendorAdapter jpaVendorAdapter = new HibernateJpaVendorAdapter();
jpaVendorAdapter.setGenerateDdl(true);
jpaVendorAdapter.setDatabase(Database.POSTGRESQL);
jpaVendorAdapter.setDatabasePlatform("org.hibernate.dialect.PostgreSQLDialect");
LocalContainerEntityManagerFactoryBean factoryBean = new LocalContainerEntityManagerFactoryBean();
factoryBean.setDataSource(pgDataSource);
factoryBean.setJpaVendorAdapter(jpaVendorAdapter);
factoryBean.setJpaPropertyMap(jpaProperties());
return factoryBean;
}
private Map<String, Object> jpaProperties() {
Map<String, Object> props = new HashMap<>();
props.put("hibernate.ejb.naming_strategy",new SpringNamingStrategy());
return props;
}
}
**粗体** _斜体_ [链接](http://example.com) `代码` - 列表 > 引用
。你还可以使用@
来通知其他用户。