0
私はSpring Webアプリケーションを開発中です。アプリケーションは、Stripe APIを使用して支払い処理を処理します。簡単に言えば、私はストライプを設定するこれらの2つのアプローチのうちのどれに意見を求めたかったのです。アプリケーションが「ライブ」であるか「プロダクション」であるかによって、ストライプ構成の一部として異なる公開鍵と秘密鍵が使用されます。私はこれらの2つのアプローチを検討しています。過度のプロファイルを使用しますか?環境ベースのコンフィグレーションを実装する
@Configuration
@Profile("live")
public class StripeConfigLive{
@Bean
public MyStripeOperationsHandler getStripeOpsHandler() {
return new MyStripeOperationsHandler(livePrivKey, livePubKey);
}
}
@Configuration
@Profile("dev")
public class StripeConfigDev{
@Bean
public MyStripeOperationsHandler getStripeOpsHandler() {
return new MyStripeOperationsHandler(devPrivKey, devPubKey);
}
}
@Controller
public class MyController {
@Autowired
private MyStripeOperationsHandler stripeOperationsHandler;
//use the handler to respond to requests
}
それとも、単にweb.xmlのコンテキストのparamとして実行モードを指定:
public class MyController implements ServletContextAware {
private MyStripeOperationsHandler stripeOperationsHandler;
private ServletContext servletContext;
@PostConstruct
public void init() {
RunMode runMode = RunMode.valueOf(servletContext.getInitParameter("runMode"));
switch (runMode) {
//init the MyStripeOperationsHandler
}
}
@Override
public void setServletContext(ServletContext servletContext) {
this.servletContext = servletContext;
}
//use the handler to respond to requests
}