A self hosted chat application with end-to-end encrypted messaging.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

45 lines
1.5 KiB

  1. package org.ros.chatto.config;
  2. import javax.sql.DataSource;
  3. import org.springframework.beans.factory.annotation.Value;
  4. import org.springframework.boot.jdbc.DataSourceBuilder;
  5. import org.springframework.context.annotation.Bean;
  6. import org.springframework.context.annotation.Configuration;
  7. import org.springframework.stereotype.Component;
  8. import lombok.Getter;
  9. import lombok.extern.slf4j.Slf4j;
  10. @Configuration
  11. @Component
  12. // @ConfigurationProperties(prefix = "chatto.datasource")
  13. @Getter
  14. // @Setter
  15. @Slf4j
  16. public class DataSourceConfig {
  17. // jdbc:mysql://localhost:3306/chatto_db?useSSL=false
  18. private final String DATASOURCE_URL = "jdbc:mysql://localhost:3306/%s?useSSL=false";
  19. private final String username;
  20. private final String password;
  21. private final String databaseName;
  22. public DataSourceConfig(@Value("${chatto.datasource.username}") String username,
  23. @Value("${chatto.datasource.password}") String password,
  24. @Value("${chatto.datasource.database-name}") String databaseName) {
  25. this.username = username;
  26. this.password = password;
  27. this.databaseName = databaseName;
  28. }
  29. @Bean
  30. public DataSource getDataSource() {
  31. final DataSourceBuilder<?> dataSourceBuilder = DataSourceBuilder.create();
  32. dataSourceBuilder.url(String.format(DATASOURCE_URL, databaseName));
  33. dataSourceBuilder.username(username);
  34. dataSourceBuilder.password(password);
  35. return dataSourceBuilder.build();
  36. }
  37. }