How to include properties from external file to hibernate.cfg.xml?

后端 未结 3 1539
渐次进展
渐次进展 2020-12-07 02:52

I need to be able to store database config properties in src|main|java|dbConnection.properties and include it to hibernate.cfg.xml in form of

3条回答
  •  囚心锁ツ
    2020-12-07 03:41

    Following this, this and this I came up with the following Maven configuration that replaces/filters placeholders from your hibernate.cfg.xml file with properties from a properties file:

    
        
            
                org.apache.maven.plugins
                maven-resources-plugin
                2.6
                
    
                    
                        copy-resources
                        
                        validate
                        
                            copy-resources
                        
                        
                            ${basedir}/target/extra-resources
                            
                                
                                    src/main/resources
                                    true
                                
                            
                        
                    
                
    
            
        
    
        
        
            src/main/resources/dbConnection.properties
        
        
            
                src/main/resources
                true
                
                    *
                
                
                    hibernate.cfg.xml
                
            
        
    
    

    With this configuration, you can run the validate Maven goal to generate the filtered files and see if they are relpaced correctly

    This is of course useful if you are using Maven.

提交回复
热议问题