Java 为spring项目配置liquibase

Java 为spring项目配置liquibase,java,spring,spring-boot,liquibase,Java,Spring,Spring Boot,Liquibase,我有下一个db.changelog master.xml文件: <?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:schemaLocati

我有下一个db.changelog master.xml文件:

<?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>

所以我希望应该创建新表。但是我的数据库还是空的。我在日志中没有看到任何错误,我做错了什么?我应该更改spring配置类吗?

好的,我想我已经解决了这个问题。每次运行脚本时,都应该更改db.changelog master.xml文件中的
id
标记。

根据标记判断,您使用的是Spring Boot。为什么您要创建自己的数据源和Liquibase bean,而不是让Boot为您创建和配置它们?因为在这种情况下,Spring Boot将使用默认的yaml文件格式,但我不喜欢这种格式。您可以在Spring Boot中使用XML配置Liquibase,而无需声明自己的bean。只需将
liquibase.changeLog=classpath:db.changeLog master.xml
添加到您的
应用程序.properties
@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;
    }
}