Answer the question
In order to leave comments, you need to log in
How can I use 2 databases in my spring boot application?
application:
spring.datasource.userandadvertisement.url=jdbc:postgresql://localhost:
5432
/
mydate
.Driver
spring.datasource.usersecret.url= jdbc:postgresql://localhost:5432/for_user_secure
spring.datasource.usersecret.username=test_user
spring.datasource.usersecret.password=qwerty
spring.datasource.usersecret.driverClassName=org.postgresql .Driver
//client class
@Entity
@Table(name = "Users")
public class User {
@Id
// @Column(name="login")
@GeneratedValue(strategy= GenerationType.AUTO)
private UUID iduser;
@Column(unique=true)
private String login;
private String phone;
//link to photo
private String photo;
public User(){}
...
//password class
@Entity
@Table(name = "UsersSecure")
public class UserSecure {
@Id
@GeneratedValue(strategy= GenerationType.AUTO)
private UUID idusersecure;
@Column(unique=true)
private String login;
@NotNull
private String password;
private String used token;
public UserSecure(){}
...
and their repositories:
@Repository
@Qualifier("jdbcUserandadvertisement")
public interface UserRepository extends CrudRepository {
//get all clients
List findAll();
...}
public interface UserSecureRepository extends CrudRepository {
UserSecure save(UserSecure userSecure);
...}
Answer the question
In order to leave comments, you need to log in
I didn’t implement such a thing with JPA, but I’ll assume that you need to configure two EntityManagers with two different dataSources through the configuration class and connect your own EntityManager to each repository
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question