小编ima*_*088的帖子

Flyway和Spring Boot集成

我试图在Spring Boot项目中使用Hibernate和Spring JPA集成Flyway进行迁移.我得到以下例外:

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'flyway' defined in class path resource [org/springframework/boot/autoconfigure/flyway/FlywayAutoConfiguration$FlywayConfiguration.class]: Invocation of init method failed; nested exception is org.flywaydb.core.api.FlywayException: Found non-empty schema "PUBLIC" without metadata table! Use init() or set initOnMigrate to true to initialize the metadata table.
Run Code Online (Sandbox Code Playgroud)

pom.xml看起来像这样:

<dependency>
  <groupId>org.flywaydb</groupId>
  <artifactId>flyway-core</artifactId>
  <version>3.2</version>
</dependency>
Run Code Online (Sandbox Code Playgroud)

我正在使用Hibernate和一个用于postgres(开发阶段)和h2(本地)的配置java文件.签名看起来像这样:

  @Bean(initMethod = "migrate")
  public Flyway flyway() {
    Flyway fly = new Flyway();
    fly.clean();
    fly.init();
    //flyway.setInitOnMigrate(true);
    fly.setSchemas("SBA_DIALOG");
    //flyway.setLocations("filesystem:src/main/resources/db/migration");
    fly.setDataSource(this.dataSource());
    fly.migrate();
    return fly;
  }
@Bean(name = "sbaEntityManagerFactory") @DependsOn("flyway")
  public …
Run Code Online (Sandbox Code Playgroud)

java spring hibernate flyway spring-boot

24
推荐指数
2
解决办法
6万
查看次数

用于使用 testcontainers 和 gradle 运行测试的 github 操作

我是 github actions 的新手(来自 gitlab-ci),我正在尝试使用管道中的 testcontainers 运行集成测试,但我陷入了困境。这是我目前的定义。

name: Run Gradle
on: push
jobs:
  gradle:
    strategy:
      matrix:
        os: [ ubuntu-18.04  ]
    runs-on: ${{ matrix.os }}
    steps:
      - uses: actions/checkout@v1
      - uses: actions/setup-java@v1
        with:
          java-version: 11
      - uses: eskatos/gradle-command-action@v1
        with:
          build-root-directory: backend
          wrapper-directory: backend
          arguments: check assemble
Run Code Online (Sandbox Code Playgroud)

如何确保 testcontainers 项目的 docker deamon 在运行期间可用?

continuous-integration gradle testcontainers github-actions

9
推荐指数
1
解决办法
8334
查看次数

反序列化多个Java对象

亲爱的同事们,

我有一个Garden类,我在其中序列化和反序列化多个Plant类对象.序列化正在运行,但是如果想要在mein静态方法中将其分配给调用变量,则反序列化不起作用.

public void searilizePlant(ArrayList<Plant> _plants) {
    try {
        FileOutputStream fileOut = new FileOutputStream(fileName);
        ObjectOutputStream out = new ObjectOutputStream(fileOut);
        for (int i = 0; i < _plants.size(); i++) {
            out.writeObject(_plants.get(i));
        }
        out.close();
        fileOut.close();
    } catch (IOException ex) {
    }
}
Run Code Online (Sandbox Code Playgroud)

反序列化代码:

public ArrayList<Plant> desearilizePlant() {
    ArrayList<Plant> plants = new ArrayList<Plant>();
    Plant _plant = null;
    try {
        ObjectInputStream in = new ObjectInputStream(new FileInputStream(fileName));
        Object object = in.readObject();

       // _plant = (Plant) object;


        // TODO: ITERATE OVER THE WHOLE STREAM
        while (object …
Run Code Online (Sandbox Code Playgroud)

java serialization outputstream deserialization

8
推荐指数
1
解决办法
2万
查看次数

gradle maven-publish 插件添加时间戳,如何避免放入后缀

我正在使用 gGradle 的“maven-publish”插件,它在实际版本之后添加了一个后缀,我想避免这种情况。因为在我的 CI 的下一步中,它尝试下载 .jar 并且 curl 命令没有下载任何内容。

我可以连接到我的 nexus 并通过上传,./gradlew publish Optional<VERSION=0.0.1>但插件(我认为)添加了一个时间戳,看起来像这样:

a/b/c/ARTIFACT-NAME/0.0.1-SNAPSHOT/ARTIFACT-NAME-0.0.1-20190114.134142-8.jar
Run Code Online (Sandbox Code Playgroud)

如何禁用插件中的时间戳功能?

这是我的发布任务:

publishing {
    publications {
        mavenJava(MavenPublication) {
            from components.java
        }
    }
    repositories {
        maven {
            if (project.version.endsWith('-SNAPSHOT')) {
                url deployNexusSnapshotUrl
            } else {
                url deployNexusReleaseUrl
            }
            credentials {
                username = deployNexusUsername
                password = deployNexusPassword
            }
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

java nexus gradle maven

7
推荐指数
1
解决办法
1893
查看次数

使用 r2dbc 和 flyway 在 Spring Boot 应用程序中设置 h2

我正在玩 Spring Boot 和称为 r2dbc 的反应式 jdbc 驱动程序。在我的主应用程序中,我使用 Postgres 作为数据库,现在我想使用 h2 进行测试。Flyway 迁移正在与设置一起工作,但是当 Spring 应用程序能够插入记录时。

这是我的设置和代码

@SpringBootTest
class CustomerRepositoryTest {

    @Autowired
    CustomerRepository repository;

    @Test
    void insertToDatabase() {
        repository.saveAll(List.of(new Customer("Jack", "Bauer"),
                new Customer("Chloe", "O'Brian"),
                new Customer("Kim", "Bauer"),
                new Customer("David", "Palmer"),
                new Customer("Michelle", "Dessler")))
                .blockLast(Duration.ofSeconds(10));
    }
}
Run Code Online (Sandbox Code Playgroud)

这是我得到的错误

 :: Spring Boot ::        (v2.3.4.RELEASE)

2020-10-14 15:59:18.538  INFO 25279 --- [           main] i.g.i.repository.CustomerRepositoryTest  : Starting CustomerRepositoryTest on imalik8088.fritz.box with PID 25279 (started by imalik in /Users/imalik/code/private/explore-java/spring-example)
2020-10-14 15:59:18.540  INFO 25279 --- [           main] …
Run Code Online (Sandbox Code Playgroud)

java flyway spring-boot spring-data-r2dbc

7
推荐指数
2
解决办法
2764
查看次数

react-native fetch async/await response filtering

我有来自我的服务器的响应buildings : [record1, record2, ...],我想只得到该响应的数组.我怎样才能从Promise获得数组?我尝试了一些异步/等待的东西,但我不明白如何在这段代码中使用它:

setupImpagination() {
    ....
    fetch(pageOffset, pageSize, stats) {
        return fetch(`http://localhost:3000/api/building/all?skip=${pageOffset}&limit=${pageSize}`)
            .then(response => {
            console.log('response.json() => ',response.json());
            response.json()
            })
            .catch((error) => {
            console.error(error);
            });

    }
    });
}
Run Code Online (Sandbox Code Playgroud)

javascript promise async-await react-native fetch-api

4
推荐指数
1
解决办法
5362
查看次数

GSON java.lang.IllegalArgumentException:类'xx'声明名为'XX'的多个JSON字段和StackOverflowError

我想将映射到非常复杂的Object的sqlResult转换为JSON,以便将其保存到redis数据库中.现在我得到了错误

java.lang.IllegalArgumentException: class 'xx' declares multiple JSON fields named 'XX'
Run Code Online (Sandbox Code Playgroud)

如何在不修改错误'xx'中提到的类的情况下解决这个问题?
或者是其他可用的库,支持将对象转换为JSON并从JSON转换支持多个JSON字段名称,例如json-io?


我使用以下建议的类A更新了我的项目A声明了多个JSON字段以避免多个JSON字段.

但是现在我有另一个问题
嵌套异常是:java.lang.StackOverflowError对这个问题的任何建议?因为我使用非常大的集合/对象进行转换.

java json gson

1
推荐指数
1
解决办法
2万
查看次数