2016-05-23 12 views
0

hibernateプロジェクトの外部でdb接続の詳細を含むhibernate設定ファイルを移動して接続することはできますか?プロジェクトの外で休止状態のプロパティ設定ファイルを移動しますか?

私の現在の設定は次のとおりですが、私はプロジェクトの外からファイルを移動したいと思いますが、まだdata sourcesに接続しています。どうすればいいですか?

@Configuration 
@EnableTransactionManagement 
@PropertySource({"classpath:hibernate.properties"}) 
@EnableJpaRepositories(basePackages = "com.my.packages", entityManagerFactoryRef = "schemaOneManagerFactory", transactionManagerRef = "schemaOneTransactionManager") 
public class SchemaOneDataSourceConfig 
{ 

//configuration methods 

} 

回線に変更する必要がありますか:@PropertySource({"classpath:hibernate.properties"})?あなたはちょうどあなたが春のブートを使用している場合は、application.propertiesにプロパティを置くことができ、あなたが持つことができるfile:

@PropertySource({"file:/path/to/hibernate.properties"}) 

答えて

1

そのファイルをJARに追加するだけでなく、サブフォルダconfig(実行中のディレクトリからの相対パス)に入れて上書きすることもできます。

詳細はhttp://docs.spring.io/spring-boot/docs/current/reference/html/boot-features-external-config.html#boot-features-external-config-application-property-filesを参照してください。

+0

ありがとう、文字列の文字をエスケープするために二重の\\文字が必要ですか? – java123999

+0

@ java123999 \\の代わりに '/'を使うだけです。 –

+0

これを行うと、「クラスパスリソースが存在しないためオープンできません」というメッセージが表示されます。ありがとう – java123999

0

にプレフィックスを変更する必要がPropertySource

Indicate the resource location(s) of the properties file to be loaded. For example, "classpath:/com/myco/app.properties" or "file:/path/to/file".

ののJavaDocから