[英]Configuring liquibase for spring project
I have next db.changelog-master.xml file: 我有下一个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>
My Spring configuration file is looking like this: 我的Spring配置文件如下所示:
@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?
我应该更改我的spring配置类吗?
Okay, I think I fixed this problem. 好吧,我想我已经解决了这个问题。 Everytime when you run your script you should change
id
tag in db.changelog-master.xml file. 每次运行脚本时,都应在db.changelog-master.xml文件中更改
id
标记。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.