小编Erm*_*tar的帖子

BootJar + MavenJar。工件不是由这个构建产生的

我有一个具有以下层次结构的示例项目:

Sample (root)
   -- model (simple jar)
   -- api   (springboot jar)
Run Code Online (Sandbox Code Playgroud)

我想将两个生成的 jars:plain jar 和 bootJar 发布到我的 localRepository。

gradlew clean build -xTest publishToMavenLocal    
Run Code Online (Sandbox Code Playgroud)

但是,出现以下错误:

* What went wrong:
Execution failed for task ':api:publishMavenJavaPublicationToMavenLocal'.
> Failed to publish publication 'mavenJava' to repository 'mavenLocal'
   > Artifact api.jar wasn't produced by this build.
Run Code Online (Sandbox Code Playgroud)

根 build.gradle 如下:

plugins {
    id 'java'
    id "org.springframework.boot" version "2.2.5.RELEASE" apply false
    id 'io.spring.dependency-management' version '1.0.9.RELEASE'
}
group 'sample'
version '1.0-SNAPSHOT'

apply plugin: 'java'

sourceCompatibility = 1.8

repositories { …
Run Code Online (Sandbox Code Playgroud)

gradle maven-publish spring-boot-gradle-plugin

13
推荐指数
4
解决办法
8417
查看次数

Liquibase for/foreach操作(迁移表数据)

我正在使用 Liquibase,我需要在一个表中插入数据,具体取决于另一个表中的条目(创建外键引用)

Table: Entities (currently empty)
PK id
INT data

Table: Existing_table (contains data)
PK id
... data
FK entities_id (references Entities.id)
Run Code Online (Sandbox Code Playgroud)

对于中的每个条目,Existing_table我需要使用Entities创建entities_id的.Existing_tableEntities.id key

我怎样才能实现这个目标?

sql liquibase

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

包中的 Jacoco 类与事务方法不匹配

我正在使用 JUnit5 测试应用程序并使用 Jacoco 进行覆盖率报告。测试执行正常,并提供测试报告。

但是,如果服务包含方法,Jacoco 报告有以下日志,用@Transactional 注释

[ant:jacocoReport] Classes in bundle 'my-service' do no match with execution data. For report generation the same class files must be used as at runtime.
[ant:jacocoReport] Execution data for class mypackage/SampleService does not match. 
Run Code Online (Sandbox Code Playgroud)

所有@Service 类方法都会发生此错误,用@Transactional 注释,普通类覆盖率计算正常。

这是一个示例测试:

@SpringBootTest
@ExtendWith(SpringExtension.class)
public class MyServiceTest {

    @Autowired
    private SampleService sampleService;

    @Test
    public void doWork(){
        sampleService.doWork();
    }
}
Run Code Online (Sandbox Code Playgroud)

工作正常。覆盖率非零:

public class SampleService {

    public void doWork(){
        System.out.println("HEY");
    }
}
Run Code Online (Sandbox Code Playgroud)

0% 覆盖率:

public class SampleService {

    @Transactional …
Run Code Online (Sandbox Code Playgroud)

java spring gradle jacoco spring-boot

6
推荐指数
1
解决办法
1058
查看次数

手动更改多租户会话

我需要创建一个多租户应用程序,能够在我的 java 代码中的模式之间切换(不基于用户请求)。

我读过文章: https ://fizzylogic.nl/2016/01/24/make-your-spring-boot-application-multi-tenant-aware-in-2-steps/ http://www.greggbolinger。 当架构在 Rest-request 中传递时,com/tenant-per-schema-with-spring-boot/解决方案工作正常。

但是我需要实现以下逻辑:

public void compare(String originalSchema, String secondSchema){
    TenantContext.setCurrentTenant(originalSchema);
    List<MyObject> originalData = myRepository.findData();

    TenantContext.setCurrentTenant(secondSchema);
    List<MyObject> migratedData = myRepository.findData();
}
Run Code Online (Sandbox Code Playgroud)

关键是,当我手动设置 TenenantContext 时,该连接不会切换。MultiTenantConnectionProviderImpl.getConnection 仅在第一次调用我的存储库时调用。

 @Component
 public class MultiTenantConnectionProviderImpl implements  MultiTenantConnectionProvider {

     @Override
     public Connection getConnection(String tenantIdentifier) throws SQLException {
          final Connection connection = getAnyConnection();
          try {
               connection.createStatement().execute( "ALTER SESSION SET CURRENT_SCHEMA = " + tenantIdentifier );
          }
          catch ( SQLException e ) {
              throw new HibernateException(
      "Could not alter JDBC …
Run Code Online (Sandbox Code Playgroud)

spring hibernate spring-data-jpa spring-boot

5
推荐指数
1
解决办法
1631
查看次数

Swagger 引用 externalFile 中的定义

我有很多 swagger 文件,使用相同的定义。我想将此定义移动到一个单独的文件并引用它们。

主要 swagger 文件如下所示:

swagger: '2.0'
info:
  version: 1.0.0
basePath: /api
tags:
  - name: MyClient
schemes:
  - http
consumes:
  - application/json
produces:
  - application/json
paths:
  /v1/myrequest:
    post:
      tags:
        - PassportCheck
      summary: ????????? ??????? ??
      operationId: passportCheck
      produces:
        - application/json
      parameters:
        - name: Body
          in: body
          required: true
          description: ''
          schema:
            $ref: '#/definitions/MyRequest'
      responses:
        '200':
          description: OK
          schema:
            $ref: '#/definitions/MyResponse'
        '400':
          description: Bad request
          schema:
            $ref: '#/definitions/Errors'

definitions: 
  MyRequest:
    type: object
    properties:
      some properties
Run Code Online (Sandbox Code Playgroud)

我尝试导入的文件保存到 exceptions.yaml(并保存到同一位置),看起来像:

swagger: '2.0'
info: …
Run Code Online (Sandbox Code Playgroud)

swagger swagger-2.0 swagger-codegen

5
推荐指数
1
解决办法
1663
查看次数

骆驼发送多部分/表单数据请求

我有一个应用程序,它发送一个 multipart/form-data 和一个接收 multipart/form-data 请求的应用程序。

在接收器中处理:

    InputStreamCache postBody = exchange.getIn().getBody(InputStreamCache.class);
    MultipartUploadContext mux = new MultipartUploadContext(postBody, exchange.getIn().getHeader("Content-Type",String.class));
    Map<String,Object> params = mux.parseRequest();
Run Code Online (Sandbox Code Playgroud)

解析请求,从 Postman/Swagger 发送工作正常。我在将骆驼发送器与骆驼接收器集成在一起时遇到了麻烦。

这是发件人路线:

from("direct:uploadFileToRest").routeId("uploadFileToRest").
    process("uploadFileRequestProcessor").
    setHeader(Exchange.HTTP_METHOD, simple("POST")).
    setHeader(Exchange.CONTENT_TYPE, constant("multipart/form-data")).
    to("myrecieverapp/full_upload").
    id("fileUploadRestSending").
    log(LoggingLevel.DEBUG, "RESPONSE BODY ${body}").
end();
Run Code Online (Sandbox Code Playgroud)

发件人处理器:

MultipartEntityBuilder multipartEntityBuilder = MultipartEntityBuilder
                .create()
                .addTextBody("name", "SomeName")
                .addBinaryBody("content", array_with_byte_content_here);
exchange.getOut().setBody(multipartEntityBuilder.build());
Run Code Online (Sandbox Code Playgroud)

出现以下错误:

 No body available of type: java.io.InputStream but has value: org.apache.http.entity.mime.MultipartFormEntity@35315261 of type: org.apache.http.entity.mime.MultipartFormEntity on: Message[ID-VRN26-1529401997491-0-3]. Caused by: No type converter available to convert from type: org.apache.http.entity.mime.MultipartFormEntity to the required type: java.io.InputStream …
Run Code Online (Sandbox Code Playgroud)

java apache-camel

3
推荐指数
1
解决办法
6664
查看次数

Reactor 和 Webflux 中的 Mono 链超时算子到底测量了什么?

我正在使用 Spring Webflux 并试图理解 Monos 链的超时概念。

例如,有一系列 Mono 调用:

myService.firstOperation()
.then(myService.secondOperation())
...
.then(myService.nOperation())
.timeout(3000L)
Run Code Online (Sandbox Code Playgroud)

如何应用超时:

1) 对于一般操作(操作总时间)

2)对于ech操作(每个操作的时间不应超过超时时间)

3) 仅针对最后一次操作(nOperation)

我几乎可以肯定超时适用于最后一个发布者。如果是这样,如何将超时应用于操作的总和?

java spring reactive-programming project-reactor spring-webflux

3
推荐指数
1
解决办法
2695
查看次数

C#传递一个Class作为参数

我有一个接口,有一些方法

interface IFunction
{
    public double y(double x);

    public double yDerivative(double x);
}
Run Code Online (Sandbox Code Playgroud)

我有静态类,正在实现它.

static class TemplateFunction:IFunction
{
    public static double y(double x)
    {
        return 0;
    }

    public static double yDerivative(double x)
    {
        return 0;
    }
}
Run Code Online (Sandbox Code Playgroud)

我想将这些类作为参数传递给另一个函数.

 AnotherClass.callSomeFunction(TemplateFunction);
Run Code Online (Sandbox Code Playgroud)

以及其他一些捕获请求的类

class AnotherClass
{
    IFunction function;
    public void callSomeFunction(IFunction function)
    {
        this.fuction = function;
    }
}
Run Code Online (Sandbox Code Playgroud)

好吧,它不起作用......我试图使用Type表达式,但是接缝打破了使用接口的想法.有没有人有想法,如何纠正代码?

c# parameters methods interface class

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