Advertisement
Guest User

Untitled

a guest
Jan 8th, 2016
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.48 KB | None | 0 0
  1.  
  2. package com.tcb.issue1.configuration;
  3.  
  4. import com.mysql.jdbc.jdbc2.optional.MysqlDataSource;
  5. import org.springframework.beans.factory.annotation.Value;
  6. import org.springframework.context.annotation.Bean;
  7. import org.springframework.context.annotation.Configuration;
  8. import org.springframework.transaction.annotation.EnableTransactionManagement;
  9.  
  10. import javax.sql.DataSource;
  11. import java.sql.SQLException;
  12.  
  13. /**
  14. * This class is the configuration class for the MySQL datasource.
  15. *
  16. * @author floriancourtial@gmail.com
  17. */
  18. @Configuration
  19. public class MySQLConfiguration {
  20.  
  21. @Value("${mysql.password}")
  22. private String password;
  23.  
  24. @Value("${mysql.user}")
  25. private String user;
  26.  
  27. @Value("${mysql.host}")
  28. private String dbHost;
  29.  
  30. @Value("${mysql.port}")
  31. private String dbPort;
  32.  
  33. @Value("${mysql.dbName}")
  34. private String dbName;
  35.  
  36.  
  37. /**
  38. * Creation of a MysqlDataSource instance according to properties extracted from the configuration file.
  39. *
  40. * @return a DataSource instance initialized according to the properties file.
  41. * @throws java.sql.SQLException
  42. */
  43. @Bean
  44. public DataSource provisioningDbDataSource() throws SQLException {
  45.  
  46. MysqlDataSource provisioningDbDataSource = new MysqlDataSource();
  47. provisioningDbDataSource.setURL("jdbc:mysql://" + dbHost + ":" + dbPort +"/" + dbName);
  48. provisioningDbDataSource.setUser(user);
  49. provisioningDbDataSource.setPassword(password);
  50.  
  51. return provisioningDbDataSource;
  52.  
  53. }
  54.  
  55. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement