設定を配置する場所は議論の余地があり、好みによって異なります。 Mavenリソースフィルタに依存するためには、すべての展開で戦争を再度パッケージ化する必要があります。私にとって、それは選択肢ではありません。あなたの展開設定に応じて異なる春のプロファイルを定義し、例えば、残りのサービスが展開されているプロパティファイルに定義することができ
オプション1つの春プロファイル
。
<beans profile="develop">
<context:property-placeholder location="classpath:develop-config.properties" />
</beans>
<beans profile="production">
<context:property-placeholder location="classpath:production-config.properties" />
</beans>
<jaxws:client id="wsClient" serviceClass="com.foo.WebServiceInterface" address="${address}" />
production-config.propertiesが持っている可能性があります。アクティブお気に入りのプロファイルに
address=http://localhost:8092/WSApp/WebServiceImplPort
を:-Dspring.profiles.active =生産
オプション2春のenviromentsを使用してアプリケーションを起動し
Springでは、有効またはアクティブなプロファイルp文法的に。これは、すべての環境に異なる設定ファイルを読み込むために使用できます。あるいは、あなたのスプリングコンテキストのjavaシステム変数または有効なシステム環境変数を利用できるようにすることができます。 設定についてに従ってください。彼らは、設定は環境変数に置くべきだと言います。 またはむしろ1戦争より多くの展開アプローチを好む。これはあなたの選択です。あなたのWebに追加することを忘れないでください
:
import org.springframework.context.ApplicationContextInitializer;
import org.springframework.core.env.ConfigurableEnvironment;
import org.springframework.core.env.MapPropertySource;
import org.springframework.core.io.support.ResourcePropertySource;
import org.springframework.web.context.ConfigurableWebApplicationContext;
public class EnviromentDiscovery implements org.springframework.context.ApplicationContextInitializer.ApplicationContextInitializer<org.springframework.context.ApplicationContextInitializer.ConfigurableWebApplicationContext> {
public void initialize(ConfigurableWebApplicationContext ctx) {
ConfigurableEnvironment environment = ctx.getEnvironment();
// This variable has the same meaning as host, but i can be redefined in
// case of cluster deployment.
String hostname= InetAddress.getLocalHost().getHostName();
logger.info("Application deployed int host {} using context path: {}", engineName, contextPath);
// You should define a method which load your config.properties according your own criteria depending for example on your hostname.
InputStream configurationSource = getResourceAsStream(hostname);
Properties config = new Properties();
config.load(configurationSource);
// Take your address endpoint
String address = config.getProperty("address");
Map<String, Object> props = new HashMap<>();
props.put("address", address);
MapPropertySource mapSource = new MapPropertySource("props", props);
// Voilá! your property address is available under spring context!
environment.getPropertySources().addLast(mapSource);
ctx.registerShutdownHook();
}
}
今すぐあなたのコンテキストファイルは次のようになります。XML
<context-param>
<param-name>contextInitializerClasses</param-name>
<param-value>net.sf.gazpachoquest.bootstrap.EnviromentDiscovery</param-value>
</context-param>
詳細情報についてSpring environment here:またはあなたがmy proof of concept hereをチェックアウトしたい場合。