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

自定义项目my-jetcache-starter包后,jetcache无法使用starter包中的默认配置进行初始化 #853

Open
teqing6chu opened this issue Jan 18, 2024 · 4 comments

Comments

@teqing6chu
Copy link

您好,项目中有多个工程需要使用jetcache,所以抽取了 my-starter-jetcache包,并再start包中指定了默认jetcache配置文件但是不生效还需要各个项目单独配置,请问如何解决

@configuration
@EnableMethodCache(basePackages = "com.xxx")
@EnableCreateCacheAnnotation
@propertysource(factory = YamlPropertySourceFactory.class, value = "classpath:xx-jetcache.yml")
public class JetCacheConfiguration {
public JetCacheConfiguration() {
System.out.println("JetCacheConfiguration容器启动初始化244。。。");
}
}
debug代码看start包中的配置未被获取到,导致下边import未被初始化

@import({RedisAutoConfiguration.class,
CaffeineAutoConfiguration.class,
MockRemoteCacheAutoConfiguration.class,
LinkedHashMapAutoConfiguration.class,
RedisLettuceAutoConfiguration.class,
RedisSpringDataAutoConfiguration.class,
RedissonAutoConfiguration.class})
20240118161127

@areyouok
Copy link
Collaborator

starter是通过jetcache-autoconfigure/src/main/resources/META-INF下面的配置文件找到JetCacheAutoConfiguration的,不同的spring版本要的文件不一样,你自己看一下吧

你也可以不用starter,看下文档

@teqing6chu
Copy link
Author

大佬我可能没有描述清楚,我是要自己做一个自定义的【my-starter-jetcache】,这样其他项目只要引入我的start包就有jetcache的功能了,不用再配配置文件了,不是您的jetcache-starter包,类似于下边这个项目
微信截图_20240118171321

@areyouok
Copy link
Collaborator

我不能帮你做这个,但是在2楼我已经告诉你要点了,有两种办法。
用类似starter的方式参考jetcache-autoconfigure;或者不用starter的方式自己组装配置,参考下文档里面的“快速入门”。

@teqing6chu
Copy link
Author

我自己封装了【my-starter-jetcache】
问题是【my-starter-jetcache】配置的yml文件 jetcacheAutoconfigure获取不到,导致jetcache没有正确初始化无法使用

快速入门是每个spring boot项目配置到application.yml中,这么配是没有问题的

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

No branches or pull requests

2 participants