java - springboot 如何基于注解方式集成 memcached?
PHP中文网
PHP中文网 2017-04-18 09:56:16
[Java讨论组]

最近想在springboot项目中集成memcached,网上查看的资料都是基于配置文件形式的,所以想看看如何基于注解方式来使用呢?还有一个问题就是

@Override
@ReadThroughSingleCache(namespace = "demo", expiration = 30000)
public Person selectById(Long id) {
    System.out.println("person 缓存未命中");
    return personMapper.selectById(id);
}

如何让 @ReadThroughSingleCache 注解生效呢?

PHP中文网
PHP中文网

认证0级讲师

全部回复(1)
大家讲道理
<beans xmlns="http://www.springframework.org/schema/beans" 
xmlns:aop="http://www.springframework.org/schema/aop"
xsi:schemaLocation="http://www.springframework.org/schema/beans
        http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
        http://www.springframework.org/schema/aop
        http://www.springframework.org/schema/aop/spring-aop-3.0.xsd">

  <import resource="simplesm-context.xml" />
  <aop:aspectj-autoproxy />

  <bean name="defaultMemcachedClient" class="com.google.code.ssm.CacheFactory">
      <property name="cacheClientFactory">
            <bean class="com.google.code.ssm.providers.xmemcached.MemcacheClientFactoryImpl" />
      </property>
      <property name="addressProvider">
            <bean class="com.google.code.ssm.config.DefaultAddressProvider">
                 <property name="address" value="127.0.0.1:11211" />
            </bean>
      </property>
      <property name="configuration">
            <bean class="com.google.code.ssm.providers.CacheConfiguration">
                  <property name="consistentHashing" value="true" />
            </bean>
      </property>
   </bean>
</beans>

以上是官方的使用示例。


导入配置 spring-boot Importing XML configuration

通过@Bean定义对象 官方文档

@Configuration
public class AppConfig {
    @Bean
    public TransferService transferService() {
        return new TransferServiceImpl();
    }
}
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责申明 举报中心 意见反馈 讲师合作 广告合作 最新更新 English
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送
PHP中文网APP
随时随地碎片化学习

Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号