生産権の回復以来、問題が同時に起こる:一貫性のないテスト・データベースと本番データベースは、生産テストクラスタ構成とクラスタ構成ファイルには一貫性がなく、その上、非常に不快です,,,
私は認める、非標準の開発の前に、ええと、ええと、ええと。。。
カプセル化された設定ファイルを読み込むために選んだScalaの瓶:
(1)新規およびリソースのディレクトリの下にプロのテストサブディレクトリ
に新しいファイルconfig.properties
hive.database = test
(2)のpom.xmlを修正するには、パッケージ化されている
新しいプロファイルを
<profiles>
<profile>
<!-- 测试环境 -->
<id>test</id>
<properties>
<profiles.active>test</profiles.active>
</properties>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
</profile>
<profile>
<!-- 生产环境 -->
<id>pro</id>
<properties>
<profiles.active>pro</profiles.active>
</properties>
</profile>
</profiles>
修正、ビルドリソースの下で
<resources>
<resource>
<directory>src/main/resources</directory>
<excludes>
<exclude>test/*</exclude>
<exclude>pro/*</exclude>
</excludes>
</resource>
<resource>
<directory>src/main/resources/${profiles.active}</directory>
</resource>
</resources>
(3)包装クラスCONFIGMANAGER
import java.util.Properties
object ConfigManager {
def main(args: Array[String]): Unit = {
println(getConfigValue("hive.database","pro/config.properties"))
}
/**
* 获取配置名称
*/
def getConfigValue(key : String,path:String="config.properties"): String = {
val stream =Thread.currentThread.getContextClassLoader.getResourceAsStream(path)
val prop : Properties= new Properties()
prop.load(stream)
prop.getProperty(key)
}
}
pom.xmlテストやプロのプロファイルを変更することで切り替えられる、
ローカルテスト&プレイクラスタテストはOK、完璧なソリューションと、より環境問題です-