Spring 在多maven项目中启动ehcache
Spring Boot ehcache in multi maven project
我正在尝试使用多个 ehcahe.xml 配置文件来代替将使用已定义缓存的模块。
何时将 ehcache.xml 配置放置在启动 spring 启动应用程序的 app-web 模块的资源下,它与 @EnableCaching
一起工作正常。
@SpringBootApplication
@Import({ CommonApp.class, CoreConfig.class})
@EnableSwagger2
@EnableCaching
public class WebApplication extends WeblogicMvcConfigurerAdapter {
}
但是什么时候将配置放在 app-core 模块下,@EnableCaching
移动到 CoreConfig
下,由 WebApplication
导入它在运行时失败。
@Configuration
@ComponentScan
@EnableCaching
public class CoreConfig {
}
当调用 @Cacheable
方法时,我得到
java.lang.IllegalArgumentException: Cannot find cache named 'systemParameterCache'
我的想法是每个模块都可以有自己的 ehcache.xml 配置以及属于该模块的缓存。
可以这么用吗?我做错了什么?
谢谢!
有可能。但我不建议这样做。应用程序中有一个缓存管理器就足够了。有很多是无用的资源消耗。如果您无法为缓存指定不同的名称,我建议您使用模块前缀。
那么,我不确定你所说的模块是什么意思。 @EnableCaching
预计在一个应用程序中指定一次。
但如果它仅在 CoreConfig
上指定,它应该可以工作。但是,您仍然需要在缓存配置中创建 systemParameterCache
。这似乎是你的问题。
我正在尝试使用多个 ehcahe.xml 配置文件来代替将使用已定义缓存的模块。
何时将 ehcache.xml 配置放置在启动 spring 启动应用程序的 app-web 模块的资源下,它与 @EnableCaching
一起工作正常。
@SpringBootApplication
@Import({ CommonApp.class, CoreConfig.class})
@EnableSwagger2
@EnableCaching
public class WebApplication extends WeblogicMvcConfigurerAdapter {
}
但是什么时候将配置放在 app-core 模块下,@EnableCaching
移动到 CoreConfig
下,由 WebApplication
导入它在运行时失败。
@Configuration
@ComponentScan
@EnableCaching
public class CoreConfig {
}
当调用 @Cacheable
方法时,我得到
java.lang.IllegalArgumentException: Cannot find cache named 'systemParameterCache'
我的想法是每个模块都可以有自己的 ehcache.xml 配置以及属于该模块的缓存。
可以这么用吗?我做错了什么?
谢谢!
有可能。但我不建议这样做。应用程序中有一个缓存管理器就足够了。有很多是无用的资源消耗。如果您无法为缓存指定不同的名称,我建议您使用模块前缀。
那么,我不确定你所说的模块是什么意思。 @EnableCaching
预计在一个应用程序中指定一次。
但如果它仅在 CoreConfig
上指定,它应该可以工作。但是,您仍然需要在缓存配置中创建 systemParameterCache
。这似乎是你的问题。