I am using Spring JPA. I have a master and n number of slaves. I'd like the read operations to be done on a slave, and the write operations to be done on the master.
How can I achieve that in SpringBoot? what're my options?
Some codes:
@Entity(name = "Team")
@Data
public class Team {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private int id;
private String name;
}
@Repository
public interface TeamRepository extends JpaRepository<Team, Integer> {
Optional<List<Team>> findByName(String name);
}
and I connect to DB like this
spring.jpa.hibernate.ddl-auto=create
spring.datasource.url=jdbc:mysql://localhost:3306/team
spring.datasource.username={$username}
spring.datasource.password={$passwod}
spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.MySQL5InnoDBDialect
#spring.jpa.properties.hibernate.dialect = org.hibernate.dialect.MySQLDialect
server.port=9990
spring.logging.level.org.hibernate.SQL=debug
spring.jpa.show-sql=true