我有2个xml配置文件,如下所示
app-context.xml:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:gfe="http://www.springframework.org/schema/gemfire" xmlns:util="http://www.springframework.org/schema/util"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/gemfire http://www.springframework.org/schema/gemfire/spring-gemfire.xsd
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd">
<context:component-scan
base-package="com.mycompany.data.testcache" />
<context:annotation-config />
<import resource="test-cache.xml" />
<bean id="testCache" class="org.springframework.data.gemfire.GemfireTemplate">
<property name="region" ref="region1" />
</bean>
</beans>
test-cache.xml
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:gfe="http://www.springframework.org/schema/gemfire"
xmlns:util="http://www.springframework.org/schema/util" xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/gemfire http://www.springframework.org/schema/gemfire/spring-gemfire.xsd
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd">
<context:component-scan
base-package="com.mycompany.data.testcache" />
<context:annotation-config />
<util:properties id="props" location="classpath:test-cache.properties">
<prop key="log-level">info</prop>
</util:properties>
<gfe:cache id="gemfire-cache" properties-ref="props" />
<gfe:local-region id="region1" cache-ref="gemfire-cache">
<gfe:cache-listener ref="listener" />
</gfe:local-region>
<bean id="listener"
class="com.mycompany.data.TestLoggingCacheListener" />
</beans>
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = { "classpath:app-context.xml" })
public class TestCache {
@Autowired
GemfireTemplate testCache;
@Test
public void testgetSomeValues() {
HashMap<String, String> map1 = retrieveSomeValues();
HashMap<String, String> map2 = retrieveSomeValues();
assertEquals(Map1, Map2);
}
@Cacheable(value = "testCache")
public HashMap<String, String> retrieveSomeValues() {
HashMap<String, String> obj = new HashMap<String, String>();
obj.put("600", "Auto");
obj.put("601", "Life");
return obj;
}
}
您需要Spring Framework的缓存支持才能使用@Cacheable。有一个Spring GemFire quickstart示例,展示了如何在以下位置使用带有@Cacheable注释的GemFire:
https://github.com/springsource/spring-gemfire-examples/tree/master/quickstart/spring-cache
您将在那里找到所需的一切:应用程序的xml配置、缓存、gemfire和使用注释的代码。
我有一个非常简单的spring boot应用程序,我正在尝试使用一些外部配置。我试着按照spring boot文件上的信息去做,但是我遇到了一个障碍。 当我运行下面的应用程序时,application.properties文件中的外部配置不会填充到bean中的变量中。我肯定我在做傻事,谢谢你的建议。 mybean.Java(位于/src/main//foo/bar/中) application.J
我计划在我的应用程序组件中使用SelfPopulatingCache,因为它支持通读和看似用于刷新的支持缓存。 然而,我对timeToLiveSeconds配置有点困惑。这是我的测试配置: 在我的单元测试中,我执行以下操作: < li >验证我的缓存中有2个条目 < li >睡眠3秒钟 < li >但是,Hibernate后,我的缓存中仍有2个条目。 根据其他在线帖子(而不是文档),当我下次执行读
但是,当我运行使用maven从命令行生成的jar时,它不会读取application.properties,默认情况下,tomcat是在8080上启动的,我无法识别上下文。其他的一切都很好。 在eclipse中,我将:VM参数提供为: 我文章和问题看起来很相似,我已经引用了这篇文章,只有我引用了Application.Properteis来配置spring boot应用程序的自定义上下文和端口。我
我有一个非常简单的Java/Spring应用程序来演示KStream的功能,但不幸的是,我无法使KStream加载数据。想法是创建一个KStream对象,并使用controller GET方法简单地检索其内容。示例代码: 问题-主题中有消息,但foreach(...)中的KStream枚举没有从中检索任何结果。KStream对象状态为“RUNning”,日志中没有错误。 生成随机应用程序ID并将A
为了提高响应能力,Gradle 默认缓存了所有编译后的脚本. 包括所有的构建脚本,初始化脚本,还有其他脚本. Gradle 创建了一个 .gradle 目录来存放编译后的脚本,下次您运行构建脚本时,如果这个脚本自从它被编译后就再也没有被改动过,Gradle 会先使用编译后的脚本. 否则 Gradle 会重新编译脚本,然后将新编译后的文件缓存起来. 如果您使用 Gradle —recompile—s
我们正在从gefire 8.2.7迁移到9.2.1 作为Gemfire启动的一部分,我们利用SpringContextBootstrappingInitializer来初始化SpringBean,它@自动连接缓存。 迁移到Gemfire 9.2.1(以及其他堆栈)的同一代码在服务器启动时失败,出现以下错误。 原因:org.springframework.beans.factory.NoSuchBe