-
Notifications
You must be signed in to change notification settings - Fork 30
/
JndiRepositoryConfig.java
49 lines (42 loc) · 1.72 KB
/
JndiRepositoryConfig.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
package com.jayway.config;
import org.springframework.beans.factory.FactoryBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Profile;
import org.springframework.data.jpa.repository.config.EnableJpaRepositories;
import org.springframework.jndi.JndiObjectFactoryBean;
import org.springframework.orm.jpa.JpaTransactionManager;
import org.springframework.transaction.PlatformTransactionManager;
import javax.persistence.EntityManagerFactory;
import javax.sql.DataSource;
@Profile("prod")
@Configuration
@EnableJpaRepositories("com.jayway.repository")
public class JndiRepositoryConfig implements RepositoryConfig {
@Autowired
private EntityManagerFactory entityManagerFactory;
@Bean
@Override
public DataSource dataSource() {
JndiObjectFactoryBean factoryBean = new JndiObjectFactoryBean();
factoryBean.setJndiName("java:comp/env/jdbc/myds");
factoryBean.setExpectedType(DataSource.class);
return (DataSource) factoryBean.getObject();
}
@Bean
@Override
public FactoryBean entityManagerFactory() {
JndiObjectFactoryBean factoryBean = new JndiObjectFactoryBean();
factoryBean.setJndiName("persistence/bankDemo");
factoryBean.setExpectedType(EntityManagerFactory.class);
return factoryBean;
}
@Bean
@Override
public PlatformTransactionManager transactionManager() {
JpaTransactionManager transactionManager = new JpaTransactionManager();
transactionManager.setEntityManagerFactory(entityManagerFactory);
return transactionManager;
}
}