繁体   English   中英

将休眠属性配置文件移到项目之外?

[英]Moving hibernate properties configuration file outside of project?

是否可以将包含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"})

来自PropertySource的JavaDocs

指示要加载的属性文件的资源位置。 例如,“ classpath:/com/myco/app.properties”或“ file:/ path / to / file”。

您只需要更改file:的前缀即可file:

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

如果您使用的是Spring Boot,则可以将属性放在application.properties并且可以将该文件放在JAR中,也可以通过将其放在config子文件夹(相对于运行目录)中来覆盖它。

有关更多信息,请参见http://docs.spring.io/spring-boot/docs/current/reference/html/boot-features-external-config.html#boot-features-external-config-application-property-files

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM