commit 54ffba0468cf4b6981ee80d14413a9770210c46a
Author: Ondřej Váně <onry.vane@gmail.com>
Date:   Wed Apr 7 12:23:31 2021 +0200

    Read application properties from properties file

diff --git a/src/main/java/cz/zcu/fav/kiv/antipatterndetectionapp/ApplicationProperties.java b/src/main/java/cz/zcu/fav/kiv/antipatterndetectionapp/ApplicationProperties.java
new file mode 100644
index 0000000..997e53c
--- /dev/null
+++ b/src/main/java/cz/zcu/fav/kiv/antipatterndetectionapp/ApplicationProperties.java
@@ -0,0 +1,24 @@
+package cz.zcu.fav.kiv.antipatterndetectionapp;
+
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.core.env.Environment;
+import org.springframework.stereotype.Component;
+
+@Component
+public class ApplicationProperties {
+
+    @Autowired
+    private Environment environment;
+
+    public String getDataSourceUrl () {
+        return environment.getProperty("spring.datasource.url");
+    }
+
+    public String getDataSourceUsername() {
+        return environment.getProperty("spring.datasource.username");
+    }
+
+    public String getDataSourcePassword() {
+        return environment.getProperty("spring.datasource.password");
+    }
+}
diff --git a/src/main/java/cz/zcu/fav/kiv/antipatterndetectionapp/SpringApplicationContext.java b/src/main/java/cz/zcu/fav/kiv/antipatterndetectionapp/SpringApplicationContext.java
new file mode 100644
index 0000000..d180233
--- /dev/null
+++ b/src/main/java/cz/zcu/fav/kiv/antipatterndetectionapp/SpringApplicationContext.java
@@ -0,0 +1,23 @@
+package cz.zcu.fav.kiv.antipatterndetectionapp;
+
+import org.springframework.beans.BeansException;
+import org.springframework.context.ApplicationContext;
+import org.springframework.context.ApplicationContextAware;
+import org.springframework.context.annotation.Configuration;
+
+@Configuration
+public class SpringApplicationContext implements ApplicationContextAware {
+
+    static ApplicationContext applicationContext = null;
+
+    public void setApplicationContext(ApplicationContext context)    throws BeansException {
+        applicationContext = context;
+    }
+
+    /**
+     * Note that this is a static method which expose ApplicationContext
+     **/
+    public static ApplicationContext getContext(){
+        return applicationContext;
+    }
+}
diff --git a/src/main/java/cz/zcu/fav/kiv/antipatterndetectionapp/controller/AppController.java b/src/main/java/cz/zcu/fav/kiv/antipatterndetectionapp/controller/AppController.java
index e1fba1b..774af95 100644
--- a/src/main/java/cz/zcu/fav/kiv/antipatterndetectionapp/controller/AppController.java
+++ b/src/main/java/cz/zcu/fav/kiv/antipatterndetectionapp/controller/AppController.java
@@ -8,6 +8,7 @@ import cz.zcu.fav.kiv.antipatterndetectionapp.model.Project;
 import cz.zcu.fav.kiv.antipatterndetectionapp.model.Query;
 import cz.zcu.fav.kiv.antipatterndetectionapp.repository.ProjectRepository;
 import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.core.env.Environment;
 import org.springframework.stereotype.Controller;
 import org.springframework.ui.Model;
 import org.springframework.web.bind.annotation.*;
diff --git a/src/main/java/cz/zcu/fav/kiv/antipatterndetectionapp/detecting/DatabaseConnection.java b/src/main/java/cz/zcu/fav/kiv/antipatterndetectionapp/detecting/DatabaseConnection.java
index e477e7d..67ac354 100644
--- a/src/main/java/cz/zcu/fav/kiv/antipatterndetectionapp/detecting/DatabaseConnection.java
+++ b/src/main/java/cz/zcu/fav/kiv/antipatterndetectionapp/detecting/DatabaseConnection.java
@@ -1,25 +1,29 @@
 package cz.zcu.fav.kiv.antipatterndetectionapp.detecting;
 
+import cz.zcu.fav.kiv.antipatterndetectionapp.ApplicationProperties;
+import cz.zcu.fav.kiv.antipatterndetectionapp.SpringApplicationContext;
+
 import java.sql.Connection;
 import java.sql.DriverManager;
 import java.sql.SQLException;
 
 public class DatabaseConnection {
 
-    private static final String connectionUrl = "jdbc:mysql://localhost:3306/ppicha";
-    private static final String user = "root";
-    private static final String password = "";
-
     private Connection databaseConnection;
 
     public DatabaseConnection() {
-        this.databaseConnection = createConnection();
+        ApplicationProperties applicationProperties = ((ApplicationProperties) SpringApplicationContext.getContext()
+                .getBean("applicationProperties"));
+        String connectionUrl = applicationProperties.getDataSourceUrl();
+        String dataSourceUsername = applicationProperties.getDataSourceUsername();
+        String dataSourcePassword = applicationProperties.getDataSourcePassword();
+        this.databaseConnection = createConnection(connectionUrl, dataSourceUsername, dataSourcePassword);
     }
 
-    private Connection createConnection() {
+    private Connection createConnection(String connectionUrl, String dataSourceUsername, String dataSourcePassword) {
         Connection conn = null;
         try {
-             conn = DriverManager.getConnection(connectionUrl, user, password);
+            conn = DriverManager.getConnection(connectionUrl, dataSourceUsername, dataSourcePassword);
 
         } catch (SQLException e) {
             e.printStackTrace();
