2016-05-23 86 views
0

是否可以將包含db連接詳細信息的hibernate配置文件移到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"})

回答

1

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".

你只需要如果您正在使用Spring啓動的前綴變爲file:

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

謝謝,是逃避字符串中字符所需的雙\\字符? – java123999

+0

@ java123999只需使用'/'而不是\\。 –

+0

當我這樣做時,我得到「類路徑資源無法打開,因爲它不存在」?謝謝 – java123999