I'm new with spring specification. I've worked with JEE for a long time. So I learned that we define datasources on application.properties file using spring.
How I define two or more datasources on application.properties and how I chose the second datasource? If I try define a second datasource using spring.datasourceB.datasource.meta-datas the file show some flags saying unknown properties.
My current case I built a project like this:
application.properties
spring.datasource.driver-class-name=com.mysql.jdbc.Driver
spring.datasource.url=jdbc:mysql://xx.xx.xx.xx:3306/dbA?useSSL=false
spring.datasource.username=username
spring.datasource.password=password
spring.jpa.hibernate.ddl-auto=update
spring.jpa.show-sql=true
spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.MySQL5InnoDBDialect
spring.DSB.jpa.properties.hibernate.dialect=org.hibernate.dialect.MySQL5InnoDBDialect
# Enable to auto identify each datasource
spring.jpa.database=default
My repository class look like this:
import java.util.List;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import org.springframework.stereotype.Repository;
@Repository
public class ClassDaoDSA {
@PersistenceContext
private EntityManager manager;
public List<T> Records() {
String stmt = "SELECT d FROM Data d ORDER BY d.id DESC";
return manager.createQuery(stmt).getResultList();
}
}
When I've worked with JEE projects I could used @PersistenceUnit tag and chose my datasource by there. How I achieve the same result using spring boot?