ソースを参照

all properties read from file

master
bart.de.lepeleer@breedbeeld.cc 3年前
コミット
e76fc7c00f

+ 2
- 5
src/main/java/be/syntra/common/AppConfig.java ファイルの表示

@@ -1,9 +1,6 @@
package be.syntra.common;

import be.syntra.cowsay.CowSay;
import be.syntra.cowsay.OriginalCowSay;
import be.syntra.cowsay.QuoteDao;
import be.syntra.cowsay.QuoteDaoDummy;
import be.syntra.cowsay.*;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.PropertySource;
@@ -22,7 +19,7 @@ public class AppConfig {
//define bean for Dao
@Bean
public QuoteDao quoteDao() { //-> the method name is the "Bean id"
return new QuoteDaoDummy();
return new QuoteDaoMysql();
}

//define Bean for swim coach AND dependency injection

+ 8
- 14
src/main/java/be/syntra/cowsay/QuoteDaoMysql.java ファイルの表示

@@ -1,26 +1,20 @@
package be.syntra.cowsay;

import org.springframework.beans.factory.annotation.Value;

import java.io.IOException;
import java.io.InputStream;
import java.sql.*;
import java.util.Properties;

public class QuoteDaoMysql implements QuoteDao {
private static String url;
private static String usr;
private static String pass;
@Value("${db.url}")
private String url;
@Value("${db.usr}")
private String usr;
@Value("${db.pass}")
private String pass;

static {
try (InputStream in = QuoteDaoMysql.class.getResourceAsStream("/app.properties")) {
Properties properties = new Properties();
properties.load(in);
url = properties.getProperty("url");
usr = properties.getProperty("usr");
pass = properties.getProperty("pass");
} catch (IOException e) {
e.printStackTrace();
}
}

@Override
public Quote getRandomQuote() {

読み込み中…
キャンセル
保存