我正在研究一个dropwizard应用程序和js ui来与api交互.我需要加载json数据来更新视图,但我必须在之前启用dropwizard中的cors.我做了一些工作人员,但似乎没有工作因为dropwizard总是返回204没有内容.
@Override
public void run(final BGConfiguration configuration, final Environment environment) throws Exception {
final Map<String, String> params = new HashMap<>();
params.put("Access-Control-Allow-Origin", "/*");
params.put("Access-Control-Allow-Credentials", "true");
params.put("Access-Control-Expose-Headers", "true");
params.put("Access-Control-Allow-Headers", "Content-Type, X-Requested-With");
params.put("Access-Control-Allow-Methods", "GET, POST, PUT, DELETE, OPTIONS");
environment.servlets().addFilter("cors", CrossOriginFilter.class).setInitParameters(params);
}
Run Code Online (Sandbox Code Playgroud) 我正在使用 liquibase 和 Maven,并且我有一个单元测试配置
<configuration>
<changeLogFile>src/main/resources/db/changelog/changelog-master.xml</changeLogFile>
<driver>org.hsqldb.jdbcDriver</driver>
<url>jdbc:hsqldb:mem:testdb;shutdown=true</url>
<referenceUrl>persistence:webapp</referenceUrl>
<username>sa</username>
<password></password>
</configuration>
Run Code Online (Sandbox Code Playgroud)
在我的变更日志中,我使用 sqlFile 标签来执行插入语句。
<changeSet id="18" author="naslami">
<sqlFile path="src/main/resources/db/changelog/inserts.sql" />
</changeSet>
Run Code Online (Sandbox Code Playgroud)
但是当我查看日志时,insert.sql文件从未被执行。您知道为什么 liquibase 不执行insert.sql文件吗?
<plugin>
<groupId>org.liquibase</groupId>
<artifactId>liquibase-maven-plugin</artifactId>
<version>${liquibase.version}</version>
<executions>
<execution>
<id>install</id>
<phase>install</phase>
<goals>
<goal>update</goal>
</goals>
<configuration>
<changeLogFile>src/main/resources/db/changelog/changelog-master.xml</changeLogFile>
<driver>com.mysql.jdbc.Driver</driver>
<url>jdbc:mysql://localhost:3306/mydb</url>
<referenceUrl>persistence:webapp</referenceUrl>
<username>user</username>
<password>password</password>
</configuration>
</execution>
<execution>
<id>test</id>
<phase>test</phase>
<goals>
<goal>update</goal>
</goals>
<configuration>
<changeLogFile>src/main/resources/db/changelog/changelog-master.xml</changeLogFile>
<driver>org.hsqldb.jdbcDriver</driver>
<url>jdbc:hsqldb:mem:testdb;shutdown=true</url>
<referenceUrl>persistence:webapp</referenceUrl>
<username>sa</username>
<password></password>
</configuration>
</execution>
</executions>
</plugin>
Run Code Online (Sandbox Code Playgroud)