2016-06-23 6 views
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 

    } 

答えて

0

私は '春のプロフィール' を使用することをお勧めいたしますでしょう春のプロファイルを使用して

。明日は、異なる環境で異なる 'データソース'を使用するような機能を強化したい場合は、複数の目的を達成するために同じ手法(スプリングプロファイリング)を使用できます。

関連する問題