简体   繁体   中英

Moving hibernate properties configuration file outside of project?

Is it possible to move a hibernate configuration file containing the db connection details outside of the hibernate project and connect to it?

My current configuration is as follows, but I would like to move my file from outside the project and still connect to my data sources . How can I do so?

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

//configuration methods

}

Do I need to make a change to line: @PropertySource({"classpath:hibernate.properties"}) ?

From the JavaDocs of 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".

You just need to change a prefix to file:

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

If you are using Spring Boot, you can put the properties in application.properties and you can have that file in your JAR, but also override it by putting it in a config sub-folder (relative to your running directory).

See http://docs.spring.io/spring-boot/docs/current/reference/html/boot-features-external-config.html#boot-features-external-config-application-property-files for more info.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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