Pergunta

I have a Spring Configuration java file in my project (i.e. with @Configuration annotation). Now I'm creating a bean of SpringLiquibase in this class. The main file of changelogs i.e. db.changelog.xml file is in resources folder. So directly it's accessible from resources folder if I use springLiquibaseObj.setChangeLog("classpath:db.changelog.xml"); method. But when I try to access other xml files from db.changelog.xml file with
<include file="src/main/config/db/db.changelog-main.xml" /> I get error that folder and file is not found.

Here, I want to keep db.changelog.xml file in resources folder and all other new changelog files in config folder which should be at same level as resources. The reason for this is, in resources folder, packages are there so folder structure config/1.0.0 is considered as config/1/0/0 which I don't want.

Is there any way to achieve this structure (shown below) with the current set up in my project?

  • config
    • 1.0.0
      • db.changelog.201412120101.xml
    • 1.1.0
    • 2.0.0
  • resources
    • db.changelog.xml

or

  • config
    • 1.0.0
      • db.changelog.201412120101.xml
    • 1.1.0
    • 2.0.0
    • db.changelog.xml
  • resources
Foi útil?

Solução

I found the solution for this. Before this, I had copied the folder src/main/config into src/main/resouces in netbeans so it took that folder as package. So the folder name - config/db/1.0.0 got changed to config/db/1/0/0, but when I created new folder in resources folder, it worked and all the files in folder 1.0.0 are accessible correctly. Now, my folder structure is like this:

  • resources
    • config
      • db
        • 1.0.0
          • db.changelog.201412120101.xml
        • 1.1.0
        • 2.0.0
    • db.changelog.xml

I can access db.changelog.xml file from my Spring class as,
springLiquibaseObj.setChangeLog("classpath:db.changelog.xml"); and other changelog files from db.changelog.xml file as,
<include file="classpath:config/db/1.0.0/db.changelog-201412120101.xml" relativeToChangelogFile="false" />.

Outras dicas

Liquibase uses the application classpath, so as long as config is in your classpath you should be able to load them as well.

They would have a path relative to config, so something like "src="1.0.0/db.changelog.201312120101.xml" in your example.

If config isn't in the classpath, you can use the relativeToChangeLog="true" attribute with a src="../../config/1.0.0/db.changelog.201412120101.xml" but having config directly accessible by liquibase is the cleaner option.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top