-
Notifications
You must be signed in to change notification settings - Fork 67
/
AppConfig.java
49 lines (38 loc) · 1.34 KB
/
AppConfig.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
package com.levent.consultantapi.config;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.PropertySource;
import com.levent.consultantapi.service.InfoService;
import com.levent.consultantapi.service.info.impl.InfoServiceImpl1;
import com.levent.consultantapi.service.info.impl.InfoServiceImpl2;
import com.levent.consultantapi.service.info.impl.InfoServiceImpl3;
import com.levent.consultantapi.service.info.impl.InfoServiceImpl4;
@Configuration
//@PropertySource(value = "classpath:implementation.properties") // Use his when file is in classpath, ex: main/src/resources
@PropertySource("file:./config/implementation.properties")
public class AppConfig {
@Value("${greeter.implementation}")
String impl;
@Bean
public InfoService getImplementationFromPropertiesFile() {
System.out.println("Implementation: " + impl);
switch(impl) {
case "impl1": {
return new InfoServiceImpl1();
}
case "impl2": {
return new InfoServiceImpl2();
}
case "impl3": {
return new InfoServiceImpl3();
}
case "impl4": {
return new InfoServiceImpl4();
}
default: {
throw new IllegalStateException("No such implementation: " + impl);
}
}
}
}