#35 springboot: @Profile
This commit is contained in:
@@ -13,7 +13,9 @@ import org.springframework.context.annotation.Import;
|
||||
//@Import(MyDataSourceConfigV1.class)
|
||||
//@Import(MyDataSourceConfigV2.class)
|
||||
@Import(MyDataSourceConfigV3.class)
|
||||
@SpringBootApplication(scanBasePackages = "hello.datasource")
|
||||
@SpringBootApplication(
|
||||
scanBasePackages = {"hello.datasource", "hello.pay"}
|
||||
)
|
||||
@ConfigurationPropertiesScan
|
||||
public class ExternalReadApplication {
|
||||
|
||||
|
||||
@@ -0,0 +1,11 @@
|
||||
package hello.pay;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
@Slf4j
|
||||
public class LocalPayClient implements PayClient {
|
||||
@Override
|
||||
public void pay(int money) {
|
||||
log.info("로컬 결제 money={}", money);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
package hello.pay;
|
||||
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.boot.ApplicationArguments;
|
||||
import org.springframework.boot.ApplicationRunner;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@Component
|
||||
@RequiredArgsConstructor
|
||||
public class OrderRunner implements ApplicationRunner {
|
||||
|
||||
private final OrderService orderService;
|
||||
|
||||
@Override
|
||||
public void run(ApplicationArguments args) throws Exception {
|
||||
orderService.order(1000);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
package hello.pay;
|
||||
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
public class OrderService {
|
||||
|
||||
private final PayClient payClient;
|
||||
|
||||
public void order(int money) {
|
||||
payClient.pay(money);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
package hello.pay;
|
||||
|
||||
public interface PayClient {
|
||||
void pay(int money);
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
package hello.pay;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.context.annotation.Profile;
|
||||
|
||||
@Slf4j
|
||||
@Configuration
|
||||
public class PayConfig {
|
||||
|
||||
@Bean
|
||||
@Profile("default")
|
||||
public LocalPayClient localPayClient() {
|
||||
log.info("LocalPayClient 빈 등록");
|
||||
return new LocalPayClient();
|
||||
}
|
||||
|
||||
@Bean
|
||||
@Profile("prod")
|
||||
public ProdPayClient prodPayClient() {
|
||||
log.info("ProdPayClient 빈 등록");
|
||||
return new ProdPayClient();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
package hello.pay;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
@Slf4j
|
||||
public class ProdPayClient implements PayClient {
|
||||
@Override
|
||||
public void pay(int money) {
|
||||
log.info("운영 결제 money={}", money);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user