需要额外引入的依赖
<dependency>
<groupId>net.spy</groupId>
<artifactId>spymemcached</artifactId>
<version>2.12.2</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-configuration-processor</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
1.启动类
package com.memcached.test;
import java.io.IOException;
import java.net.InetSocketAddress;
import javax.annotation.Resource;
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import com.memcached.test.Demo.MemcacheSource;
import net.spy.memcached.MemcachedClient;
2.加载ip端口
package com.memcached.test.Demo;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.stereotype.Component;
3.测试memcached的启动类
package com.memcached.test;
import javax.annotation.Resource;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;
import net.spy.memcached.MemcachedClient;
resources下建一个application.properties
#缓存配置
memcache.ip=127.0.0.1
memcache.port=11211
配置类会自行读取该配置