Spring Memcache配置及缺少com.danga的解决
2016-07-05 09:06
453 查看
需要以下jar
![](https://img-blog.csdn.net/20160705085659173)
但是maven配置,会无法下载对应jar,主要是由于maven repository中没有,我们需要从
https://github.com/gwhalin/Memcached-Java-Client/downloads
中下载对应版本,手动导入本地maven仓库
手动导入maven仓库的命令
这样我们仓库中就有这个jar包了,然后再导入其他三个jar就行
spring-memcache.xml的配置文件
memcache.properties
测试类代码SpringMemcache.java
但是maven配置,会无法下载对应jar,主要是由于maven repository中没有,我们需要从
https://github.com/gwhalin/Memcached-Java-Client/downloads
中下载对应版本,手动导入本地maven仓库
<dependency> <groupId>com.danga</groupId> <artifactId>java-memcached</artifactId> <version>2.6.6</version> </dependency>
手动导入maven仓库的命令
mvn install:install-file -Dfile=D:/java_memcached-release_2.6.6.jar -DgroupId=com.danga -DartifactId=java-memcached -Dversion=2.6.6 -Dpackaging=jar
这样我们仓库中就有这个jar包了,然后再导入其他三个jar就行
spring-memcache.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:context="http://www.springframework.org/schema/context" xmlns:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.5.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.5.xsd"> <bean id="propertyConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"> <property name="locations"> <list> <value>classpath:com/ys/memcache/memcache.properties</value> </list> </property> </bean> <bean id="memcachedPool" class="com.danga.MemCached.SockIOPool" factory-method="getInstance" init-method="initialize" destroy-method="shutDown"> <constructor-arg> <value>neeaMemcachedPool</value> </constructor-arg> <!-- 可以配置多服务器负载均衡 --> <property name="servers"> <list> <value>${memcache.server}</value> </list> </property> <!-- 初始连接数 --> <property name="initConn"> <value>${memcache.initConn}</value> </property> <!-- 最小连接数 --> <property name="minConn"> <value>${memcache.minConn}</value> </property> <!-- 最大连接数 --> <property name="maxConn"> <value>${memcache.maxConn}</value> </property> <!-- 连接池守护线程的睡眠时间 --> <property name="maintSleep"> <value>${memcache.maintSleep}</value> </property> <property name="nagle"> <value>${memcache.nagle}</value> </property> <property name="socketTO"> <value>${memcache.socketTO}</value> </property> </bean> <bean id="memcachedClient" class="com.danga.MemCached.MemCachedClient"> <constructor-arg> <value>neeaMemcachedPool</value> </constructor-arg> </bean> </beans>
memcache.properties
memcache.server=127.0.0.1:11211 memcache.initConn=20 memcache.minConn=10 memcache.maxConn=50 memcache.maintSleep=3000 memcache.nagle=false memcache.socketTO=3000
测试类代码SpringMemcache.java
public class SpringMemcache { MemCachedClient memCachedClient; @Before public void beforeTest() { ApplicationContext atx = new ClassPathXmlApplicationContext("com/ys/memcache/spring-memcache.xml"); memCachedClient = (MemCachedClient) atx.getBean("memcachedClient"); } @Test public void TestMem() { memCachedClient.set("name", "han"); System.out.println(memCachedClient.get("name")); } }
相关文章推荐
- maven学习
- 一个jar包里的网站
- 一个jar包里的网站之文件上传
- 一个jar包里的网站之返回对媒体类型
- Spring和ThreadLocal
- Spring Boot 开发微服务
- Spring AOP动态代理-切面
- maven插件maven-war-plugin的使用
- jenkins------部署项目到jboss eap下
- maven使用经验集
- Spring整合Quartz(JobDetailBean方式)
- Spring整合Quartz(JobDetailBean方式)
- 修复mysql数据库
- nodejs中的fiber(纤程)库详解
- 桌面中心(一)创建数据库
- 模拟Spring的简单实现
- Spring整合WebSocket应用示例(上)
- spring+html5实现安全传输随机数字密码键盘
- Spring中属性注入详解