[SPRING] Embedded Redis가 실제 Redis 서버에 연결하려고 시도하여 예외가 발생합니다.
SPRINGEmbedded Redis가 실제 Redis 서버에 연결하려고 시도하여 예외가 발생합니다.
내 dev 봄 프로필 (나는 또한 진짜 redis 연결하는 구름 프로필이) 포함 된 redis 사용하려고합니다.
그러나 내장 된 redis 구성이 실제 redis에 연결하려고합니다.
dev 프로필을 실행할 때 나는 다음과 같은 오류가 발생합니다.
Caused by: redis.clients.jedis.exceptions.JedisDataException: NOAUTH Authentication required.
at redis.clients.jedis.Protocol.processError(Protocol.java:113)
at redis.clients.jedis.Protocol.process(Protocol.java:131)
at redis.clients.jedis.Protocol.read(Protocol.java:200)
at redis.clients.jedis.Connection.readProtocolWithCheckingBroken(Connection.java:285)
at redis.clients.jedis.Connection.getBinaryMultiBulkReply(Connection.java:221)
at redis.clients.jedis.Connection.getMultiBulkReply(Connection.java:214)
at redis.clients.jedis.Jedis.configGet(Jedis.java:2758)
at org.springframework.data.redis.connection.jedis.JedisConnection.getConfig(JedisConnection.java:554)
... 19 more
JedisDataException NOAUTH는 실제 Redis 서버에서 인증을 활성화하고 실제 서버에 연결을 시도하기 때문에 발생합니다.
다음은 Spring 구성이다.
@Configuration
public class RedisConfiguration {
@Autowired
private RedisConnectionFactory redisConnectionFactory;
@Bean
public RedisTemplate<String, String> redisTemplate() {
RedisTemplate<String, String> redisTemplate = new RedisTemplate<String, String>();
redisTemplate.setConnectionFactory(redisConnectionFactory);
return redisTemplate;
}
}
"dev"및 "test"구성 :
@Configuration
@EnableRedisHttpSession
@Profile({ Profiles.DEV, Profiles.TEST })
public class RedisDevTestSessionConfiguration {
@Bean
public RedisConnectionFactory redisConnectionFactory() {
return new JedisConnectionFactory();
}
@Bean
public RedisServerBean redisServer() {
return new RedisServerBean();
}
class RedisServerBean implements InitializingBean, DisposableBean {
private RedisServer redisServer;
public void afterPropertiesSet() throws Exception {
redisServer = new RedisServer(Protocol.DEFAULT_PORT);
redisServer.start();
}
public void destroy() throws Exception {
if (redisServer != null) {
redisServer.stop();
}
}
}
}
클라우드 구성 :
@Configuration
@EnableRedisHttpSession
@Profile(Profiles.CLOUD)
public class RedisCloudSessionConfiguration extends AbstractCloudConfig {
@Bean
public RedisConnectionFactory redisConnectionFactory() {
PoolConfig poolConfig = new PoolConfig(10, 200);// TODO: configure!
return connectionFactory().redisConnectionFactory("REDISCLOUD", new PooledServiceConnectorConfig(poolConfig));
}
내 의존성은 다음과 같습니다.
compile("redis.embedded:embedded-redis:0.4")
프로필 :
public final class Profiles {
public static final String CLOUD = "cloud";
public static final String TEST = "test";
public static final String DEV = "dev";
public static final String CAPACITY_TEST = "capacity-test";
}
편집하다:
다음은 예외가 무엇인지 나와 있으며 해당 구성이 아래에 나와 있습니다.
Exception in thread "main" org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'redisServer' defined in class path resource [com/bignibou/configuration/session/EmbeddedRedisConfiguration.class]: Invocation of init method failed; nested exception is java.lang.RuntimeException: Can't start redis server. Check logs for details.
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1574)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:539)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:476)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:303)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:299)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:194)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:755)
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:757)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:480)
at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.refresh(EmbeddedWebApplicationContext.java:118)
at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:686)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:320)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:957)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:946)
at com.bignibou.Application.main(Application.java:22)
Caused by: java.lang.RuntimeException: Can't start redis server. Check logs for details.
at redis.embedded.AbstractRedisInstance.awaitRedisServerReady(AbstractRedisInstance.java:66)
at redis.embedded.AbstractRedisInstance.start(AbstractRedisInstance.java:37)
at redis.embedded.RedisServer.start(RedisServer.java:11)
at com.bignibou.configuration.session.EmbeddedRedisConfiguration$RedisServerBean.afterPropertiesSet(EmbeddedRedisConfiguration.java:26)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1633)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1570)
... 15 more
다음은 수정 된 redis 구성입니다.
import org.springframework.beans.factory.DisposableBean;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Profile;
import redis.clients.jedis.Protocol;
import redis.embedded.RedisServer;
@Configuration
@Profile({ "dev" })
public class EmbeddedRedisConfiguration {
@Bean
public RedisServerBean redisServer() {
return new RedisServerBean();
}
class RedisServerBean implements InitializingBean, DisposableBean {
private RedisServer redisServer;
public void afterPropertiesSet() throws Exception {
redisServer = new RedisServer(Protocol.DEFAULT_PORT);
redisServer.start();
}
public void destroy() throws Exception {
if (redisServer != null) {
redisServer.stop();
}
}
}
}
해결법
from https://stackoverflow.com/questions/29059794/embedded-redis-tries-to-connect-to-real-redis-server-resulting-in-an-exception by cc-by-sa and MIT license
'SPRING' 카테고리의 다른 글
[SPRING] 봄 부트 프레임 워크에서 Tomcat이 생성 한 액세스 로그를 필터링하는 방법 (0) | 2019.04.26 |
---|---|
[SPRING] web.xml의 CharacterEncodingFilter를 사용한 Spring 인코딩 (0) | 2019.04.26 |
[SPRING] Spring @Transactional을 사용한 TestNG 다중 스레드 테스트 (0) | 2019.04.26 |
[SPRING] Spring MVC와 다중 응답 유형으로 JSONP를 지원하는 방법 (0) | 2019.04.26 |
[SPRING] Spring Data Neo4J 4.0.0 : BeforeSaveEvent가 실행되지 않습니까? (0) | 2019.04.26 |