0

构建.gradle.kts

import org.gradle.api.tasks.testing.logging.TestExceptionFormat.FULL
import org.gradle.api.tasks.testing.logging.TestLogEvent.*
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile

repositories {
    mavenCentral()
}


plugins {
    id("org.springframework.boot") version "2.5.0"
    kotlin("jvm") version "1.5.10"
    kotlin("plugin.spring") version "1.5.10"
    kotlin("plugin.jpa") version "1.5.10"
}


group = "com.open.opto.money"
version = "0.0.1-SNAPSHOT"
java.sourceCompatibility = JavaVersion.VERSION_1_8
java.targetCompatibility = JavaVersion.VERSION_1_8

val compileKotlin: KotlinCompile by tasks
compileKotlin.kotlinOptions.freeCompilerArgs = listOf("-Xjsr305=strict", "-Xjvm-default=enable")
compileKotlin.kotlinOptions.jvmTarget = "1.8"

apply(plugin = "io.spring.dependency-management")

configurations.forEach { it.exclude("org.springframework.boot", "spring-boot-starter-tomcat") }

dependencies {
    implementation("org.springframework.boot:spring-boot-starter-undertow")
    implementation("org.springframework.boot:spring-boot-starter-data-jpa")
    implementation("org.springframework.boot:spring-boot-starter-data-rest")
    implementation("org.springframework.boot:spring-boot-starter-security")
    implementation("org.keycloak:keycloak-spring-boot-starter:12.0.4")

    implementation("com.auth0:auth0-spring-security-api:1.4.0")
    implementation("org.jetbrains.kotlin:kotlin-stdlib-jdk8")
    implementation("org.jetbrains.kotlin:kotlin-reflect")
    implementation("com.amazonaws:aws-java-sdk-s3:1.11.992")
    implementation("com.amazonaws:aws-java-sdk-secretsmanager:1.11.992")
    implementation("com.amazonaws:aws-java-sdk-sts:1.11.992")
    implementation("com.github.derjust:spring-data-dynamodb:5.0.3")

    implementation("org.javers:javers-spring-boot-starter-sql:6.1.0")



    implementation("cz.jirutka.rsql:rsql-parser:2.1.0")
    implementation("com.github.tennaito:rsql-jpa:2.0.2")


    implementation("org.flywaydb:flyway-core:7.5.3")
    implementation("com.vladmihalcea:hibernate-types-52:2.4.3")


    implementation("com.fasterxml.jackson.module:jackson-module-kotlin:2.12.1")



    implementation("com.univocity:univocity-parsers:2.5.9")
    implementation ("com.monitorjbl:xlsx-streamer:2.2.0")
    implementation("org.apache.poi:poi:4.1.2")
    implementation("org.apache.poi:poi-ooxml:4.1.2")
    implementation("org.apache.poi:poi-ooxml-schemas:4.1.2")
    implementation("org.springframework.hateoas:spring-hateoas:1.3.1")

    implementation("org.apache.commons:commons-lang3:3.8")
    implementation("org.reflections:reflections:0.9.10")

    implementation("org.apache.commons:commons-text:1.6")
    implementation("commons-io:commons-io:2.8.0")

    implementation("org.elasticsearch:elasticsearch:7.9.0")
    implementation("org.elasticsearch.client:elasticsearch-rest-high-level-client:7.9.0")
    implementation("org.springframework.data:spring-data-elasticsearch:4.1.3")

    //Pubnub
    implementation("com.pubnub:pubnub-gson:5.1.0")

    //For API Docs
    implementation("io.springfox:springfox-boot-starter:3.0.0")

    implementation("com.github.doyaaaaaken:kotlin-csv-jvm:0.15.1")


    implementation("javax.inject:javax.inject:1")
    implementation("javax.validation:validation-api:2.0.1.Final")

    implementation("org.postgresql:postgresql")

    testImplementation("org.springframework.boot:spring-boot-starter-test")
    testImplementation("ru.yandex.qatools.embed:postgresql-embedded:2.10")



    testImplementation("org.jetbrains.kotlin:kotlin-test-junit")
    testImplementation("org.jetbrains.kotlin:kotlin-test")
    testImplementation("org.codelibs:elasticsearch-cluster-runner:7.9.0.0")
}

tasks{
    test{
        failFast = true

        testLogging {
            events (FAILED, STANDARD_ERROR, SKIPPED, PASSED)
            exceptionFormat = FULL
            showExceptions = true
            showCauses = true
            showStackTraces = true
            showStandardStreams = true
        }
    }
}

模型类

package com.open.opto.money.model

import com.amazonaws.services.dynamodbv2.datamodeling.*
import org.springframework.data.annotation.Id
//import java.util.*

@DynamoDBTable(tableName = "CommentsInfo")
data class Comment (
        @field:Id
        @DynamoDBIgnore
        val id : CompositeKey = CompositeKey(),
        @get:DynamoDBAttribute
        var text: String? = null,

        @get:DynamoDBAttribute
        var commentedBy: String? = null

)
{
    @DynamoDBHashKey(attributeName = "commentId")
    fun getCommentId() = id.commentId
    fun setCommentId(commentId : PartitionKey)
    {
        id.commentId = commentId
    }
    @DynamoDBRangeKey(attributeName = "commentDate")
    fun getCommentDate() = id.systemTimeInMillis
    fun setCommentDate(systemTimeInMillis : Long)
    {
        id.systemTimeInMillis = systemTimeInMillis
    }
}

复合键类

package com.open.opto.money.model

//import com.amazonaws.services.dynamodbv2.datamodeling.DynamoDBDocument
import com.amazonaws.services.dynamodbv2.datamodeling.*
import java.io.Serializable
import java.util.*
import javax.persistence.EnumType
import javax.persistence.Enumerated

//composite primary key for comment
//@DynamoDBDocument
data class CompositeKey(
        //partition key or hash key
        @field:DynamoDBAutoGeneratedKey
        @field:DynamoDBHashKey
        var commentId: PartitionKey? = null,
        //sort key or range key
        @field:DynamoDBRangeKey
        //var commentDate : Date? = null
        var systemTimeInMillis: Long? = null

        ) : Serializable
data class PartitionKey
(
        @DynamoDBAttribute
        @Enumerated(EnumType.STRING)
        var entityType : CommentedEntity? = null,
        @DynamoDBAttribute
        var entityId : String? =null
)
enum class CommentedEntity
{
        SALESINVOICE,
        PURCHASEINVOICE,
        SUPPLIER,
        CUSTOMER
}

存储库类

package com.open.opto.money.repository.dynamodb

import com.open.opto.money.model.Comment
import com.open.opto.money.model.CompositeKey
import org.socialsignin.spring.data.dynamodb.repository.EnableScan
import org.springframework.data.repository.CrudRepository
import org.springframework.stereotype.Repository


@Repository
@EnableScan
interface CommentRepo: CrudRepository<Comment, CompositeKey>

控制器类

package com.open.opto.money.controller

import com.open.opto.money.repository.dynamodb.CommentRepo
import org.springframework.data.rest.webmvc.RepositoryRestController
import org.springframework.web.bind.annotation.RestController

@RestController
@RepositoryRestController
class CommentController(val commentsRepo : CommentRepo)

DynamoBDConfig 类

package com.open.opto.money.config

import com.amazonaws.auth.AWSCredentials
import com.amazonaws.auth.AWSCredentialsProvider
import com.amazonaws.auth.AWSStaticCredentialsProvider
import com.amazonaws.auth.BasicAWSCredentials
import com.amazonaws.client.builder.AwsClientBuilder
import com.amazonaws.services.dynamodbv2.AmazonDynamoDB
import com.amazonaws.services.dynamodbv2.AmazonDynamoDBClientBuilder
import com.amazonaws.services.dynamodbv2.datamodeling.DynamoDBMapper
import com.amazonaws.services.dynamodbv2.datamodeling.DynamoDBMapperConfig
import org.socialsignin.spring.data.dynamodb.repository.config.EnableDynamoDBRepositories
import org.springframework.beans.factory.annotation.Value
import org.springframework.context.annotation.Bean
import org.springframework.context.annotation.Configuration


@Configuration
@EnableDynamoDBRepositories(basePackages = ["com.open.opto.money.repository.dynamodb"])
class DynamoDBConfig {

    @Value("\${amazon.aws.accesskey}")
    private val amazonAWSAccessKey: String? = null

    @Value("\${amazon.aws.secretkey}")
    private val amazonAWSSecretKey: String? = null
    fun amazonAWSCredentialsProvider(): AWSCredentialsProvider {
        return AWSStaticCredentialsProvider(amazonAWSCredentials())
    }

    @Bean
    fun amazonAWSCredentials(): AWSCredentials {
        return BasicAWSCredentials(amazonAWSAccessKey, amazonAWSSecretKey)
    }

    @Bean
    fun dynamoDBMapperConfig(): DynamoDBMapperConfig {
        return DynamoDBMapperConfig.DEFAULT
    }

    @Bean
    fun dynamoDBMapper(amazonDynamoDB: AmazonDynamoDB?, config: DynamoDBMapperConfig?): DynamoDBMapper {
        return DynamoDBMapper(amazonDynamoDB, config)
    }


    // Only needed to load localhost endpoint for development
    // With established AWS configuration, endpoint isn't needed
    @Value("\${aws.dynamodb.endpoint:}")
    var amazonDynamoDBEndpoint: String? = null

    @Bean
    fun amazonDynamoDB(): AmazonDynamoDB {
        val builder = AmazonDynamoDBClientBuilder.standard()

        println ( "DB aws.dynamodb.endpoint = $amazonDynamoDBEndpoint" )

        if (amazonDynamoDBEndpoint?.isNotBlank() ?: false) {
            println ( "Using local Dynamo DB." )
            builder.withEndpointConfiguration(
                    AwsClientBuilder.EndpointConfiguration(amazonDynamoDBEndpoint, "us-east-1"))
        }

        return builder.build()
    }
}

应用类

package com.open.opto.money


import com.open.opto.money.repository.JpaRepositoryImpl
import org.springframework.boot.autoconfigure.SpringBootApplication
import org.springframework.boot.runApplication
import org.springframework.data.jpa.repository.config.EnableJpaRepositories
import org.springframework.transaction.annotation.EnableTransactionManagement

@SpringBootApplication
@EnableJpaRepositories(repositoryBaseClass = JpaRepositoryImpl::class)
@EnableTransactionManagement
class Application

    fun main(args: Array<String>)
    {
        runApplication<Application>(*args)
    }

在创建模型之后,我正在尝试编写空控制器和 repo,当我尝试检查 swagger ui 中的输出(用于获取默认控制器)时,它给出了上述错误, 这是我得到的错误

4

0 回答 0