带有springboot的Corda构建JAR

时间:2018-10-24 17:20:23

标签: corda

我正在尝试与Spring Boot集成Corda。

我在互联网上找不到几个例子。

我在enter link description here上遵循了示例“ joeldudleyr3 / spring-observable-stream”。

我已尝试使用带有上述示例的Corda样品irs-demo制作胖罐。但它给出运行时错误为:

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'rpcClient' defined in class path resource [net/corda/server/serviceExample.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [net.corda.core.messaging.CordaRPCOps]: Factory method 'rpcClient' threw exception; nested exception is java.lang.NoClassDefFoundError: org/apache/activemq/artemis/api/core/RoutingType
    at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:599) ~[classes!/:?]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateUsingFactoryMethod(AbstractAutowireCapableBeanFactory.java:1173) ~[classes!/:?]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1067) ~[classes!/:?]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:513) ~[classes!/:?]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:483) ~[classes!/:?]
    at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:306) ~[classes!/:?]
    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230) ~[classes!/:?]
    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:302) ~[classes!/:?]
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197) ~[classes!/:?]
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:761) ~[classes!/:?]
    at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:867) ~[classes!/:?]
    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:543) ~[classes!/:?]
    at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.refresh(EmbeddedWebApplicationContext.java:122) ~[classes!/:?]
    at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:693) [classes!/:?]
    at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:360) [classes!/:?]
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:303) [classes!/:?]
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:1118) [classes!/:?]
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:1107) [classes!/:?]
    at net.corda.server.Server$Companion.main(Server.kt:35) [classes!/:?]
    at net.corda.server.Server.main(Server.kt) [classes!/:?]
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0_181]
    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0_181]
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0_181]
    at java.lang.reflect.Method.invoke(Unknown Source) ~[?:1.8.0_181]
    at org.springframework.boot.loader.MainMethodRunner.run(MainMethodRunner.java:48) [webserver-0.1.jar:?]
    at org.springframework.boot.loader.Launcher.launch(Launcher.java:87) [webserver-0.1.jar:?]
    at org.springframework.boot.loader.Launcher.launch(Launcher.java:50) [webserver-0.1.jar:?]
    at org.springframework.boot.loader.JarLauncher.main(JarLauncher.java:51) [webserver-0.1.jar:?]
    ... 27 more

编辑: 父Gradle文件:

buildscript {
    ext.corda_release_version = '3.2-corda'
    ext.corda_release_group = 'net.corda'
    ext.corda_release_distribution = 'net.corda'
    ext.corda_gradle_plugins_version = '3.0.9'
    ext.kotlin_version = '1.1.60'
    ext.junit_version = '4.12'
    ext.quasar_version = '0.7.9'
    ext.jolokia_version = '1.3.7'
    ext.spring_boot_version = '1.5.7.RELEASE'

    repositories {
        mavenLocal()
        mavenCentral()
        jcenter()
        maven { url 'https://ci-artifactory.corda.r3cev.com/artifactory/corda-releases' }
    }

    dependencies {
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
        classpath "net.corda.plugins:cordapp:$corda_gradle_plugins_version"
        classpath "net.corda.plugins:publish-utils:$corda_gradle_plugins_version"
        classpath "net.corda.plugins:cordformation:$corda_gradle_plugins_version"
        classpath "net.corda.plugins:quasar-utils:$corda_gradle_plugins_version"
        classpath "org.springframework.boot:spring-boot-gradle-plugin:$spring_boot_version"
        classpath "io.spring.gradle:dependency-management-plugin:1.0.4.RELEASE"
        classpath "org.jetbrains.kotlin:kotlin-allopen:$kotlin_version"
    }

}

apply plugin: 'kotlin'
apply plugin: 'idea'
apply plugin: 'application'

spring boot服务器的升级文件是:

buildscript {
    ext.spring_boot_version = '1.5.7.RELEASE'
    ext.spring_version = '4.3.11.RELEASE'
}

plugins {
    id 'com.craigburke.client-dependencies' version '1.4.0'
}

repositories {
    mavenLocal()
    jcenter()
    mavenCentral()
    maven { url 'https://dl.bintray.com/kotlin/exposed' }
    maven { url 'https://jitpack.io' }
    maven { url 'https://ci-artifactory.corda.r3cev.com/artifactory/corda-releases' }
}

apply plugin: 'kotlin'
apply plugin: 'net.corda.plugins.cordapp'
apply plugin: 'net.corda.plugins.cordformation'
apply plugin: 'org.springframework.boot'
apply plugin: 'kotlin-spring'
apply plugin: 'application'

sourceSets {
    main {
        resources {
            srcDir "../config/dev"
        }
    }
}

dependencies {
    compile('org.springframework.boot:spring-boot-starter-web') {
            exclude module: "spring-boot-starter-logging"
            exclude module: "logback-classic"
    }
    compile "org.jetbrains.kotlin:kotlin-stdlib-jre8:$kotlin_version"
    testCompile "org.jetbrains.kotlin:kotlin-test:$kotlin_version"
    testCompile "junit:junit:$junit_version"

    // Corda integration dependencies

    cordaCompile "$corda_release_distribution:corda-core:$corda_release_version"
    cordaCompile "$corda_release_distribution:corda-finance:$corda_release_version"
    cordaCompile "$corda_release_distribution:corda-jackson:$corda_release_version"
    cordaCompile "$corda_release_distribution:corda-rpc:$corda_release_version"
    cordaRuntime "$corda_release_distribution:corda:$corda_release_version"
    testCompile  "$corda_release_distribution:corda-node-driver:$corda_release_version"

    // testCompile "$corda_release_distribution:corda-node-driver:$corda_release_version"

    compile("org.springframework.boot:spring-boot-starter-websocket:$spring_boot_version") {
        exclude group: "org.springframework.boot", module: "spring-boot-starter-logging"
    }
    compile "org.springframework.boot:spring-boot-starter-log4j2:$spring_boot_version"
    compile "org.apache.logging.log4j:log4j-web:2.7"


    cordapp project(":cordapp")
}

bootRepackage {
    enabled = true
}

jar {
    from sourceSets.test.output
    dependsOn clientInstall
}

tasks.withType(org.jetbrains.kotlin.gradle.tasks.KotlinCompile).all {
    kotlinOptions {
        languageVersion = "1.1"
        apiVersion = "1.1"
        jvmTarget = "1.8"
        javaParameters = true   // Useful for reflection.
    }
}

task runBank1WebServer(type: JavaExec) {
    classpath = sourceSets.main.runtimeClasspath
    main = 'net.corda.server.ServerKt'
    environment "server.port", "8080"
    environment "config.rpc.port", "10008"
}


task runBank2WebServer(type: JavaExec) {
    classpath = sourceSets.main.runtimeClasspath
    main = 'net.corda.server.ServerKt'
    environment "server.port", "8081"
    environment "config.rpc.port", "10011"
}

task runObserverWebServer(type: JavaExec) {
    classpath = sourceSets.main.runtimeClasspath
    main = 'net.corda.server.ServerKt'
    environment "server.port", "8082"
    environment "config.rpc.port", "10014"
}

task deployWebapps(type: Copy, dependsOn: ['jar', 'bootRepackage']) {
    ext.webappDir = file("build/webapps")

    from(jar.outputs)
    from("src/test/resources/scripts/") {
        filter { it
                .replace('#JAR_PATH#', jar.archiveName)
                .replace('#DIR#', ext.webappDir.getAbsolutePath())
        }
    }
    into ext.webappDir
}

1 个答案:

答案 0 :(得分:1)

通常,如果您只想为Spring Server Client构建一个胖jar,而不是使用gradle任务,则可以使用./gradlew assemble为客户端构建jar。它将位于/clients/build/lib/文件夹中。

然后,您可以使用命令行参数args运行客户端:

java -jar clients-0.1.jar --server.port=8080 --config.rpc.host=localhost --config.rpc.port=10006 --config.rpc.username=user1 --config.rpc.password=test

以上内容是基于您遵循此处https://github.com/corda/cordapp-template-kotlin/tree/release-V4/clients/src/main/kotlin/com/template

的cordapp模板中提供的结构的假设得出的。