Tomcat7 サーバーで 4 つのアプリケーションを実行しています。既存のアプリケーションは Hibernate と Spring で動作します。バックエンドは 2 番目のデータベースに接続されており、いくつかの古いスキーマがここに保存されています。各スキーマは、xxx_live および xxx_test と呼ばれます。
Tomcat サーバーが起動すると、適切な環境用に JNDI プロパティが設定されます。
- テスト
- ローカル
- ライブ
プロパティは、PropertySourcesPlaceholderConfigurer クラスの拡張で解析されます。
public class GenericPropertySourcesPlaceholderConfigurer extends PropertySourcesPlaceholderConfigurer {
private String application;
private String environment;
private static final String ENVIRONMENT = "environment";
public GenericPropertySourcesPlaceholderConfigurer(String application) throws IOException {
this.application = application;
this.environment = System.getProperty(ENVIRONMENT);
if (this.environment == null) {
this.environment = System.getenv().get(ENVIRONMENT);
}
initPropertySources();
}
/**
* setup default properties configuration
* Default configuration properties look like :
* app-global.properties
* app-environment.properties
* jndi properties
*/
private void initPropertySources() throws IOException {
MutablePropertySources propertySources = new MutablePropertySources();
propertySources.addLast(new ResourcePropertySource(new ClassPathResource(MessageFormat.format("properties/{0}-global.properties", application))));
propertySources.addLast(new ResourcePropertySource(new ClassPathResource(MessageFormat.format("properties/{0}/{1}.properties", environment, application))));
propertySources.addLast(new NotFailingJndiPropertySource("jndi"));
setPropertySources(propertySources);
setIgnoreResourceNotFound(false);
setIgnoreUnresolvablePlaceholders(true);
}
}
現在、すべてを MyBatis に移行しています。これらのプロパティを XML 構成に挿入または解析する方法はありますか? 何かのようなもの:
<select id="findAllUsers" parameterType="list" resultType="user">
SELECT * FROM ${mybatis.default_schema}.USER
</select>