0

I tryng to use Two DataSources with spring boot, than I configure just like the tutorial : http://docs.spring.io/spring-boot/docs/1.3.1.RELEASE/reference/htmlsingle/#howto-two-datasources

@Configuration
public class MigrarService {


    @Bean(name = "dbdnaso")
    @Primary
    @ConfigurationProperties(prefix="spring.dbdnaso")
    public DataSource primaryDataSource() {
        return DataSourceBuilder.create().build();
    }

    @Bean(name = "dbregistro")
    @ConfigurationProperties(prefix="spring.dbregistro")
    public DataSource dbRegistro() {
        return DataSourceBuilder.create().build();
    }

}

Then I create 2 entity and 2 repositories

import br.com.lumera.entity.TbUsuario;
import org.springframework.data.repository.CrudRepository;

public interface IUsuario1 extends CrudRepository<TbUsuario1, Integer>{

    TbUsuario1 getTbUsuarioByNmEmail(String nmEmail);

    TbUsuario1 getTbUsuarioByNmEmailAndDsSenha(String nmEmail, String string);
} 

and

import br.com.lumera.entity.TbUsuario;
import org.springframework.data.repository.CrudRepository;

public interface IUsuario2 extends CrudRepository<TbUsuario2, Integer>{

    TbUsuario2 getTbUsuarioByNmEmail(String nmEmail);

    TbUsuario2 getTbUsuarioByNmEmailAndDsSenha(String nmEmail, String string);
}

Now how can I say how datasource I use in every repository??

tks

Fabio
  • 225
  • 1
  • 6
  • 10
  • Look at this: http://stackoverflow.com/questions/12612288/spring-data-jpa-with-multiple-datasources-but-only-one-set-of-repositories – luboskrnac Jan 04 '16 at 14:25
  • do the databases have the same structure? – Guy Bouallet Jan 04 '16 at 14:55
  • Guy I have 2 postgresql in the same server but in diff db – Fabio Jan 04 '16 at 16:56
  • Look at this example. It explains what you need [Multiple data source and schema creation in Spring Boot](http://stackoverflow.com/questions/28275448/multiple-data-source-and-schema-creation-in-spring-boot) – prabath Jan 05 '16 at 05:46

1 Answers1

0

If you are using auto configuration and if you have two, it will use with annotation - @Primary

user3444718
  • 1,485
  • 6
  • 22
  • 32