简体   繁体   中英

Configuring liquibase for spring project

I have next db.changelog-master.xml file:

<?xml version="1.0" encoding="UTF-8"?>

<databaseChangeLog
        xmlns="http://www.liquibase.org/xml/ns/dbchangelog/1.7"
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog/1.7
         http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-1.7.xsd">
    <changeSet id="19082014-1" author="autor">
        <sql>
            CREATE TABLE testings (
            id character varying(80) NOT NULL
            )
        </sql>
    </changeSet>
</databaseChangeLog>

My Spring configuration file is looking like this:

@Configuration
@PropertySource("classpath:user.properties")
public class LiquibaseConfig {

    @Autowired
    private Environment env;

    @Bean
    public DataSource dataSource()  {
        DriverManagerDataSource dataSource = new DriverManagerDataSource();

            dataSource.setDriverClassName(env.getProperty("spring.datasource.drivername"));
            dataSource.setUrl(env.getProperty("spring.datasource.url"));
            dataSource.setUsername(env.getProperty("spring.datasource.username"));
            dataSource.setPassword(env.getProperty("spring.datasource.password"));

        return dataSource;
    }

    @Bean
    public SpringLiquibase liquibase()  {
        SpringLiquibase liquibase = new SpringLiquibase();

        liquibase.setDataSource(dataSource());
        liquibase.setChangeLog("classpath:db.changelog-master.xml");

        return liquibase;
    }
}

So I'm expecting that new table should be created. But my database is still empty. I don't see any errors in logs, what am I doing wrong? Should I change my spring configuration class?

Okay, I think I fixed this problem. Everytime when you run your script you should change id tag in db.changelog-master.xml file.

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