小编vsz*_*bov的帖子

Spring Boot默认代理机制

最近我发现spring 文档页面说:

Spring AOP 使用 JDK 动态代理或 CGLIB 来为给定的目标对象创建代理。(只要有选择,JDK 动态代理都是首选)。

如果要代理的目标对象至少实现一个接口,则将使用 JDK 动态代理。

但我的申请中似乎并非如此。我想编写一个小型基准测试来比较两种代理类型的性能。

有两个类似的类。两者都有一种带有注释的方法@Transactional。一个类实现了该接口,而另一个类则没有:

@Service
public class Cglib {
    @Transactional
    public void method() {}
}
Run Code Online (Sandbox Code Playgroud)
public interface Dynamic {
    void method();
}
Run Code Online (Sandbox Code Playgroud)
@Service
public class DynamicImpl implements Dynamic {
    @Override
    @Transactional
    public void method() {}
}
Run Code Online (Sandbox Code Playgroud)

根据第一个类的文档,应该创建一个 CGLIB 代理,对于第二个类,应该创建一个 JDK 动态代理。

但就我而言,CGLIB 用于这两个类:

@Component
@RequiredArgsConstructor
public class Runner implements ApplicationRunner {
    private final Cglib cglib;
    private final Dynamic dynamic;

    @Override
    public void run(ApplicationArguments args) { …
Run Code Online (Sandbox Code Playgroud)

java proxy spring spring-boot

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

@GrpcClient 为 null spring boot 3

我正在使用 grpc 客户端net.devh.grpc-client-spring-boot-starter

客户:

@Service
public class SystemService {
    @GrpcClient("handyman-client")
    StatusServiceGrpc.StatusServiceBlockingStub handymanClient;

    public VersionResponse getHandymanVersion() {
        return handymanClient.getVersion(Empty.newBuilder().build());
    }
}
Run Code Online (Sandbox Code Playgroud)

应用程序.yaml:

grpc:
  client:
    handyman-client:
      address: static://localhost:8080
      negotiationType: plaintext
Run Code Online (Sandbox Code Playgroud)

在运行时handymanClientnull. 3.0.0尝试了从到 的Spring Boot 版本3.0.2。降低spring boot版本2.7.0解决问题——现在正在创建客户端。

有没有办法让它在 Spring Boot 3 上工作?

构建.gradle:

@Service
public class SystemService {
    @GrpcClient("handyman-client")
    StatusServiceGrpc.StatusServiceBlockingStub handymanClient;

    public VersionResponse getHandymanVersion() {
        return handymanClient.getVersion(Empty.newBuilder().build());
    }
}
Run Code Online (Sandbox Code Playgroud)

java spring grpc

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

按正则表达式拆分与多个单字符拆分性能

我使用此基准比较了通过正则表达式和多个单字符拆分来拆分字符串

import org.openjdk.jmh.annotations.*;

import java.io.IOException;
import java.util.concurrent.TimeUnit;

public class Test {
    static String start = "1, 2, 3, 4, 5, 6, 7, 8. 9. 10. 11. 12.1, 2, 3, 4, 5, 6, 7, 8. 9. 10. 11. 12.1, 2, 3, 4, 5, 6, 7, 8. 9. 10. 11. 12.1, 2, 3, 4, 5, 6, 7, 8. 9. 10. 11. 12.1, 2, 3, 4, 5, 6, 7, 8. 9. 10. 11. 12.1, 2, 3, 4, 5, 6, 7, 8. 9. 10. …
Run Code Online (Sandbox Code Playgroud)

java performance split jmh

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

标签 统计

java ×3

spring ×2

grpc ×1

jmh ×1

performance ×1

proxy ×1

split ×1

spring-boot ×1