Created
May 25, 2019 16:03
-
-
Save yusufcakal/298716e7f24db26090caf46f64e721e2 to your computer and use it in GitHub Desktop.
Config class for liquibase
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="UTF-8"?> | |
<databaseChangeLog | |
xmlns="http://www.liquibase.org/xml/ns/dbchangelog" | |
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | |
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog | |
http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-3.1.xsd"> | |
</databaseChangeLog> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import liquibase.integration.spring.SpringLiquibase; | |
import org.springframework.beans.factory.annotation.Autowired; | |
import org.springframework.context.annotation.Bean; | |
import org.springframework.context.annotation.Configuration; | |
import org.springframework.core.io.Resource; | |
import org.springframework.core.io.ResourceLoader; | |
import org.springframework.util.Assert; | |
import javax.sql.DataSource; | |
@Configuration | |
public class LiquibaseConfig { | |
private static final String DATABASE_CHANGELOG_FILE_PATH = "classpath:/database/changelog/database-changelog.xml"; | |
@Autowired | |
private DataSource dataSource; | |
@Autowired | |
private ResourceLoader resourceLoader; | |
@Bean | |
public SpringLiquibase liquibase() { | |
String changelogFile = DATABASE_CHANGELOG_FILE_PATH; | |
Resource resource = resourceLoader.getResource(changelogFile); | |
Assert.state(resource.exists(), "Unable to find file: " + resource.getFilename()); | |
SpringLiquibase liquibase = new SpringLiquibase(); | |
liquibase.setChangeLog(changelogFile); | |
liquibase.setDataSource(dataSource); | |
return liquibase; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment