Advertisement
Guest User

Untitled

a guest
May 16th, 2016
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.15 KB | None | 0 0
  1. spring.datasource.url= jdbc:postgresql://localhost:5432/data1
  2. spring.datasource.username=postgres
  3. spring.datasource.password=pass
  4.  
  5. spring.secondDatasource.url= jdbc:mysql://localhost:3306/data2
  6. spring.secondDatasource.username=root
  7. spring.secondDatasource.password=pass
  8.  
  9.  
  10. spring.jpa.hibernate.ddl-auto=create-drop
  11.  
  12. @Configuration
  13. public class DatabaseConfiguration {
  14.  
  15. @Bean
  16. @Primary
  17. @ConfigurationProperties(prefix="spring.datasource")
  18. public DataSource primaryDataSource() {
  19. return DataSourceBuilder.create().build();
  20. }
  21.  
  22. @Bean
  23. @ConfigurationProperties(prefix="spring.secondDatasource")
  24. public DataSource secondaryDataSource() {
  25. return DataSourceBuilder.create().build();
  26. }
  27. }
  28.  
  29. public interface MessageRepository extends CrudRepository<Message, Long>{
  30.  
  31. }
  32.  
  33. @Controller
  34. @RequestMapping("/messages")
  35. public class MessageController {
  36.  
  37. @Autowired
  38. private MessageRepository repositoryPostGreSQL;
  39.  
  40. @RequestMapping(value="", method = RequestMethod.GET)
  41. public String listPosta(Model model){
  42. model.addAttribute("messages", repositoryPostGreSQL.findAll());
  43. return "messages/list";
  44. }
  45. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement