Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>If you are configuring using XML you can use <a href="http://docs.spring.io/spring/docs/3.2.x/javadoc-api/org/springframework/beans/factory/config/MethodInvokingFactoryBean.html" rel="nofollow">org.springframework.beans.factory.config.MethodInvokingFactoryBean</a>. For example:</p> <pre><code>public class AESEncryptor { private static String password; static void setPassword(String newPass) { password = newPass; } } &lt;bean class="org.springframework.beans.factory.config.MethodInvokingFactoryBean"&gt; &lt;property name="staticMethod" value="sample.AESEncryptor.setPassword"/&gt; &lt;property name="arguments"&gt; &lt;list&gt; &lt;value&gt;secret&lt;/value&gt; &lt;/list&gt; &lt;/property&gt; &lt;/bean&gt; </code></pre> <p>To integrate this with profiles you have a number of options. In its simplest for you would simply wrap the MethodInvokingFactoryBean definition with profile definitions. For example:</p> <pre><code>&lt;beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:jdbc="http://www.springframework.org/schema/jdbc" xmlns:jee="http://www.springframework.org/schema/jee" xsi:schemaLocation="..."&gt; &lt;beans profile="dev"&gt; &lt;bean class="org.springframework.beans.factory.config.MethodInvokingFactoryBean"&gt; &lt;property name="staticMethod" value="sample.AESEncryptor.setPassword"/&gt; &lt;property name="arguments"&gt; &lt;list&gt; &lt;value&gt;secretForDev&lt;/value&gt; &lt;/list&gt; &lt;/property&gt; &lt;/bean&gt; &lt;/beans&gt; &lt;beans profile="stage"&gt; &lt;bean class="org.springframework.beans.factory.config.MethodInvokingFactoryBean"&gt; &lt;property name="staticMethod" value="sample.AESEncryptor.setPassword"/&gt; &lt;property name="arguments"&gt; &lt;list&gt; &lt;value&gt;secretForStage&lt;/value&gt; &lt;/list&gt; &lt;/property&gt; &lt;/bean&gt; &lt;/beans&gt; &lt;beans profile="prod"&gt; &lt;bean class="org.springframework.beans.factory.config.MethodInvokingFactoryBean"&gt; &lt;property name="staticMethod" value="sample.AESEncryptor.setPassword"/&gt; &lt;property name="arguments"&gt; &lt;list&gt; &lt;value&gt;secretForProd&lt;/value&gt; &lt;/list&gt; &lt;/property&gt; &lt;/bean&gt; &lt;/beans&gt; &lt;/beans&gt; </code></pre> <p>You can then activate the profiles by setting the spring.profiles.active system property. </p> <p>However, it may be better to use an easier approach. From the <a href="https://spring.io/blog/2011/02/11/spring-framework-3-1-m1-released/" rel="nofollow">Spring blog</a></p> <blockquote> <p>Do not use profiles if a simpler approach can get the job done. If the only thing changing between profiles is the value of properties, Spring's existing PropertyPlaceholderConfigurer / may be all you need.</p> </blockquote> <p>To do this, you could use a configuration similar to the following:</p> <pre><code>&lt;bean class="org.springframework.beans.factory.config.MethodInvokingFactoryBean"&gt; &lt;property name="staticMethod" value="sample.AESEncryptor.setPassword"/&gt; &lt;property name="arguments"&gt; &lt;list&gt; &lt;value&gt;${security.encrypt.secret}&lt;/value&gt; &lt;/list&gt; &lt;/property&gt; &lt;/bean&gt; &lt;util:properties location="classpath:environment.properties"/&gt; </code></pre> <p>You would then have a <strong>environment.properties</strong> file that is included on the classpath for each environment. An example for dev might look like the following:</p> <pre><code>security.encrypt.secret=secretForDev </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload