我试图在已经提出的问题以及一些用户推荐的这篇文章中找到答案:http : //www.operatornew.com/2012/11/automatic-db-migration-for-java-web.html但没有运气好的话。
问题是我使用 Maven 构建工具和 Postgres DB 为我的 Java 项目完整配置了 Liquibase,但即使我已经定义了 Hibernate 实体,Liquibase diff也没有考虑它们,并且不会基于 JPA 注释实体生成变更锁.
我尝试了所有方法,但使用空的changelock-master.xml并定义了 2 个实体,结果diff.xml为空。
这是我的pom.xml:
<!--LIQUIBASE-->
<dependency>
<groupId>org.liquibase</groupId>
<artifactId>liquibase-core</artifactId>
</dependency>
<dependency>
<groupId>org.liquibase</groupId>
<artifactId>liquibase-maven-plugin</artifactId>
<version>3.4.1</version>
</dependency>
...
<plugin>
<groupId>org.liquibase</groupId>
<artifactId>liquibase-maven-plugin</artifactId>
<version>3.5.3</version>
<dependencies>
<dependency>
<groupId>org.liquibase.ext</groupId>
<artifactId>liquibase-hibernate4</artifactId>
<version>3.6</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-beans</artifactId>
<version>4.1.7.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-jpa</artifactId>
<version>1.7.3.RELEASE</version>
</dependency>
</dependencies>
<configuration>
<propertyFile>src/main/resources/liquibase.properties</propertyFile>
<changeLogFile>src/main/resources/db/changelog/changelog-master.xml</changeLogFile>
</configuration>
</plugin>
Run Code Online (Sandbox Code Playgroud)
在这里,我定义了liquibase.properties:
referenceUrl=hibernate:spring:com.victus.applied.entity?dialect=org.hibernate.dialect.PostgreSQLDialect
referenceDriver=liquibase.ext.hibernate.database.connection.HibernateDriver
referenceUsername=testusername
referencePassword=
driver=org.postgresql.Driver
url=jdbc:postgresql://localhost:5432/applied
username=testusername …Run Code Online (Sandbox Code Playgroud) 我正在尝试为我重构的方法编写一个Junit测试,以确保该方法仍然按预期运行.我注意到一些我无法弄清楚的奇怪行为.
为什么Java ByteArrayOutputStream.toByteArray()会返回一些随机字节?我想这可能与记忆有关.数组中的11个字节始终是随机的.任何见解?
这是我重构的方法.
package foo;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.util.Map;
import java.util.zip.ZipEntry;
import java.util.zip.ZipOutputStream;
public class ZipUtil {
public static byte[] createZip(Map<String, byte[]> files) throws IOException {
final ByteArrayOutputStream bos = new ByteArrayOutputStream();
final ZipOutputStream zipfile = new ZipOutputStream(bos);
String fileName = null;
ZipEntry zipentry = null;
for (Map.Entry<String, byte[]> entry : files.entrySet()) {
fileName = entry.getKey();
zipentry = new ZipEntry(fileName);
zipfile.putNextEntry(zipentry);
zipfile.write(files.get(fileName));
}
zipfile.close();
return bos.toByteArray();
}
}
Run Code Online (Sandbox Code Playgroud)
测试类
package foo;
import …Run Code Online (Sandbox Code Playgroud) 我有以下代码:
class the_class {
private the_field;
function the_class() {
the_field = new other_class(); //has other_method()
}
function method() {
$this->the_field->other_method(); //This doesn't seem to work
}
}
Run Code Online (Sandbox Code Playgroud)
这里的语法有什么问题吗?方法调用似乎总是返回true,就好像方法调用有问题一样.或者方法调用是否正确,我应该调试other_method()本身?
TIA,彼得