Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

你确定你这代码可以跑吗? #3

Closed
yangfeng20 opened this issue Apr 23, 2024 · 9 comments
Closed

你确定你这代码可以跑吗? #3

yangfeng20 opened this issue Apr 23, 2024 · 9 comments
Labels
question Further information is requested

Comments

@yangfeng20
Copy link

image

@zhangjh
Copy link
Owner

zhangjh commented Apr 23, 2024

提issue请带上上下文和复现场景,就贴个图神仙能知道你什么问题。。
你可以先跑我代码里提供的单测用例

@yangfeng20
Copy link
Author

  1. 你的GeminiServiceImpl使用@component注册时无效的,需要自己注册。作为第三方使用时我们的包名不可能是me.zhangjh.gemini.service。详情了解@SpringBootApplication中的@componentscan
  2. 第二点截图里面也看的很清楚。你的包中依赖的okhttp:3.14.9中没的RequestBody类的create方法,没有一个签名是(String, MediaType)。
    image
    a. 只有一个接近的。是(MediaType, String)

image

@zhangjh
Copy link
Owner

zhangjh commented Apr 24, 2024

  1. 外部项目依赖的时候扫包路径肯定要加我的项目包路径的,这个我以为是常识。。怪我文档没有这么细致,我加到README里
  2. 你自查一下你的项目有没有引入okhttp的依赖,如果是我的项目依赖的话,我的项目里依赖版本是4.10.0。。
    image
    image

@yangfeng20
Copy link
Author

好的,感谢你的回复。不过我觉得外部项目依赖添加扫描目录这并不是一个常识操作,大部分的开发者会通过spring spi来实现这样的starter。
针对第二点问题。我觉得可能得原因是你的项目并没有在打包是将把okhttp依赖添加到jar包中。最终项目中使用的okhttp依赖来源于项目中的依赖。这样可能很不兼容。可能需要几个特定的springboot版本才能运行。

例如我下面是一个纯净的springboot项目。就依赖了gemini_sdk.他的okHttp依赖版本就是3.14.9.这最终导致的结果就是代码和字节码不匹配,没有这样的方法报错,导致不能使用。
image

@zhangjh
Copy link
Owner

zhangjh commented Apr 24, 2024

另一个项目就是starter机制的,不用starter机制还是想给外部项目一个更透明的使用方式,开源starter可能需要使用者对源码阅读有一定要求,否则会怀疑作者是否会引入恶意代码什么的。
我看了下你的截图,你的sdk版本还是1.0,你可以升级到最新版1.4看一下
image

@yangfeng20
Copy link
Author

好的,感谢。升级为1.4版本也是不行的,因为你的jar包并不包含okhttp的依赖,实际使用的依赖来源于当前项目,也就是当前springboot项目的okhttp版本。因为在我的项目中,使用的springboot 2.3.9.RELEASE,他的父依赖定义的okhttp版本为3.14.9
image
image

除非是我显式依赖okhttp并指定版本。
image

这个问题仅是说不能够很优雅的使用。我想咨询你另外一个问题,就是如何指定代理。有提供这样的时机吗

@zhangjh
Copy link
Owner

zhangjh commented Apr 24, 2024

首先你所说的“因为你的jar包并不包含okhttp的依赖”是不正确的,你可以看到我的源码pom里okhttp的依赖并无任何provided的scope排除打包,而且上面maven中央仓库的截图也可以看出,我的sdk包里的okhttp版本是4.10.0。
至于你在SpringBoot项目里依赖,依赖版本未生效的问题应该是依赖仲裁机制的问题,我猜测是由于你依赖的SpringBoot框架引入的OkHttp版本优先于我这个“三方sdk依赖”。
可能由于Spring Boot的父项目中定义了依赖管理(dependency management)部分,这部分会覆盖子项目中相同的依赖。你可以通过直接依赖或者排除SpringBoot框架引入的依赖解决。

关于代理,第一种你可以在部署的服务器上部署全局代理,或者我SDK里也提供了代理方式,只是我没有明确写到README里,你可以参考代码me.zhangjh.gemini.util.HttpClientUtil
image

@zhangjh
Copy link
Owner

zhangjh commented Apr 24, 2024

后续如果还有其他问题,请开辟新的issue,避免在一个主题的issue下面讨论不相关的内容。
这个issue我先关闭了

@zhangjh zhangjh closed this as completed Apr 24, 2024
@zhangjh zhangjh added the question Further information is requested label Apr 24, 2024
@zhangjh
Copy link
Owner

zhangjh commented Apr 24, 2024

代理相关的问题我回答过:
#2
可以先查看一下相关的issue有没有类似问题

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants