Add RedisAutoConfiguration
This commit is contained in:
parent
71fd474ed2
commit
640b9d2680
|
|
@ -111,6 +111,16 @@
|
||||||
<artifactId>spring-data-mongodb</artifactId>
|
<artifactId>spring-data-mongodb</artifactId>
|
||||||
<optional>true</optional>
|
<optional>true</optional>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework.data</groupId>
|
||||||
|
<artifactId>spring-data-redis</artifactId>
|
||||||
|
<optional>true</optional>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.lambdaworks</groupId>
|
||||||
|
<artifactId>lettuce</artifactId>
|
||||||
|
<optional>true</optional>
|
||||||
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.springframework.security</groupId>
|
<groupId>org.springframework.security</groupId>
|
||||||
<artifactId>spring-security-acl</artifactId>
|
<artifactId>spring-security-acl</artifactId>
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,120 @@
|
||||||
|
/*
|
||||||
|
* Copyright 2012-2013 the original author or authors.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.springframework.boot.autoconfigure.redis;
|
||||||
|
|
||||||
|
import java.net.UnknownHostException;
|
||||||
|
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
|
||||||
|
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
|
||||||
|
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
|
||||||
|
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||||
|
import org.springframework.boot.context.properties.EnableConfigurationProperties;
|
||||||
|
import org.springframework.context.annotation.Bean;
|
||||||
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
import org.springframework.data.redis.connection.RedisConnectionFactory;
|
||||||
|
import org.springframework.data.redis.connection.lettuce.LettuceConnection;
|
||||||
|
import org.springframework.data.redis.connection.lettuce.LettuceConnectionFactory;
|
||||||
|
import org.springframework.data.redis.core.RedisOperations;
|
||||||
|
import org.springframework.data.redis.core.RedisTemplate;
|
||||||
|
import org.springframework.data.redis.core.StringRedisTemplate;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@link EnableAutoConfiguration Auto-configuration} for Spring Data's redis support.
|
||||||
|
*
|
||||||
|
* @author Dave Syer
|
||||||
|
*/
|
||||||
|
@Configuration
|
||||||
|
@ConditionalOnClass({ LettuceConnection.class, RedisOperations.class })
|
||||||
|
public class RedisAutoConfiguration {
|
||||||
|
|
||||||
|
@Configuration
|
||||||
|
@EnableConfigurationProperties(RedisProperties.class)
|
||||||
|
protected static class RedisConfiguration {
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private RedisProperties config;
|
||||||
|
|
||||||
|
@Bean
|
||||||
|
@ConditionalOnMissingBean(RedisConnectionFactory.class)
|
||||||
|
RedisConnectionFactory redisConnectionFactory() throws UnknownHostException {
|
||||||
|
LettuceConnectionFactory factory = new LettuceConnectionFactory(
|
||||||
|
this.config.getHost(), this.config.getPort());
|
||||||
|
if (this.config.getPassword() != null) {
|
||||||
|
factory.setPassword(this.config.getPassword());
|
||||||
|
}
|
||||||
|
return factory;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Bean
|
||||||
|
@ConditionalOnMissingBean(RedisOperations.class)
|
||||||
|
RedisOperations<Object, Object> redisTemplate(
|
||||||
|
RedisConnectionFactory redisConnectionFactory)
|
||||||
|
throws UnknownHostException {
|
||||||
|
RedisTemplate<Object, Object> template = new RedisTemplate<Object, Object>();
|
||||||
|
template.setConnectionFactory(redisConnectionFactory);
|
||||||
|
return template;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Bean
|
||||||
|
@ConditionalOnMissingBean(StringRedisTemplate.class)
|
||||||
|
StringRedisTemplate stringRedisTemplate(
|
||||||
|
RedisConnectionFactory redisConnectionFactory)
|
||||||
|
throws UnknownHostException {
|
||||||
|
StringRedisTemplate template = new StringRedisTemplate();
|
||||||
|
template.setConnectionFactory(redisConnectionFactory);
|
||||||
|
return template;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@ConfigurationProperties(name = "spring.data.redis")
|
||||||
|
public static class RedisProperties {
|
||||||
|
|
||||||
|
private String host = "localhost";
|
||||||
|
|
||||||
|
private String password;
|
||||||
|
|
||||||
|
private int port = 6379;
|
||||||
|
|
||||||
|
public String getHost() {
|
||||||
|
return this.host;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setHost(String host) {
|
||||||
|
this.host = host;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getPort() {
|
||||||
|
return this.port;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setPort(int port) {
|
||||||
|
this.port = port;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getPassword() {
|
||||||
|
return this.password;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setPassword(String password) {
|
||||||
|
this.password = password;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -7,6 +7,7 @@ org.springframework.boot.autoconfigure.PropertyPlaceholderAutoConfiguration,\
|
||||||
org.springframework.boot.autoconfigure.batch.BatchAutoConfiguration,\
|
org.springframework.boot.autoconfigure.batch.BatchAutoConfiguration,\
|
||||||
org.springframework.boot.autoconfigure.data.JpaRepositoriesAutoConfiguration,\
|
org.springframework.boot.autoconfigure.data.JpaRepositoriesAutoConfiguration,\
|
||||||
org.springframework.boot.autoconfigure.data.MongoRepositoriesAutoConfiguration,\
|
org.springframework.boot.autoconfigure.data.MongoRepositoriesAutoConfiguration,\
|
||||||
|
org.springframework.boot.autoconfigure.redis.RedisAutoConfiguration,\
|
||||||
org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration,\
|
org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration,\
|
||||||
org.springframework.boot.autoconfigure.jdbc.DataSourceTransactionManagerAutoConfiguration,\
|
org.springframework.boot.autoconfigure.jdbc.DataSourceTransactionManagerAutoConfiguration,\
|
||||||
org.springframework.boot.autoconfigure.jms.JmsTemplateAutoConfiguration,\
|
org.springframework.boot.autoconfigure.jms.JmsTemplateAutoConfiguration,\
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,44 @@
|
||||||
|
/*
|
||||||
|
* Copyright 2012-2013 the original author or authors.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.springframework.boot.autoconfigure.redis;
|
||||||
|
|
||||||
|
import org.junit.Test;
|
||||||
|
import org.springframework.boot.autoconfigure.PropertyPlaceholderAutoConfiguration;
|
||||||
|
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
|
||||||
|
import org.springframework.data.redis.core.RedisOperations;
|
||||||
|
import org.springframework.data.redis.core.StringRedisTemplate;
|
||||||
|
|
||||||
|
import static org.junit.Assert.assertNotNull;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Dave Syer
|
||||||
|
*/
|
||||||
|
public class RedisAutoConfigurationTests {
|
||||||
|
|
||||||
|
private AnnotationConfigApplicationContext context;
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testDefaultRedisConfiguration() throws Exception {
|
||||||
|
this.context = new AnnotationConfigApplicationContext();
|
||||||
|
this.context.register(RedisAutoConfiguration.class,
|
||||||
|
PropertyPlaceholderAutoConfiguration.class);
|
||||||
|
this.context.refresh();
|
||||||
|
assertNotNull(this.context.getBean("redisTemplate", RedisOperations.class));
|
||||||
|
assertNotNull(this.context.getBean(StringRedisTemplate.class));
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -24,6 +24,7 @@
|
||||||
<joda-time.version>2.3</joda-time.version>
|
<joda-time.version>2.3</joda-time.version>
|
||||||
<jstl.version>1.2</jstl.version>
|
<jstl.version>1.2</jstl.version>
|
||||||
<junit.version>4.11</junit.version>
|
<junit.version>4.11</junit.version>
|
||||||
|
<lettuce.version>2.3.3</lettuce.version>
|
||||||
<liquibase.version>3.0.2</liquibase.version>
|
<liquibase.version>3.0.2</liquibase.version>
|
||||||
<log4j.version>1.2.17</log4j.version>
|
<log4j.version>1.2.17</log4j.version>
|
||||||
<logback.version>1.0.13</logback.version>
|
<logback.version>1.0.13</logback.version>
|
||||||
|
|
@ -40,6 +41,7 @@
|
||||||
<spring-batch.version>2.2.2.RELEASE</spring-batch.version>
|
<spring-batch.version>2.2.2.RELEASE</spring-batch.version>
|
||||||
<spring-data-jpa.version>1.4.2.RELEASE</spring-data-jpa.version>
|
<spring-data-jpa.version>1.4.2.RELEASE</spring-data-jpa.version>
|
||||||
<spring-data-mongo.version>1.3.2.RELEASE</spring-data-mongo.version>
|
<spring-data-mongo.version>1.3.2.RELEASE</spring-data-mongo.version>
|
||||||
|
<spring-data-redis.version>1.1.0.RELEASE</spring-data-redis.version>
|
||||||
<spring-rabbit.version>1.2.0.RELEASE</spring-rabbit.version>
|
<spring-rabbit.version>1.2.0.RELEASE</spring-rabbit.version>
|
||||||
<spring-mobile.version>1.1.0.RELEASE</spring-mobile.version>
|
<spring-mobile.version>1.1.0.RELEASE</spring-mobile.version>
|
||||||
<spring-security.version>3.2.0.RC2</spring-security.version>
|
<spring-security.version>3.2.0.RC2</spring-security.version>
|
||||||
|
|
@ -81,6 +83,11 @@
|
||||||
<artifactId>commons-httpclient</artifactId>
|
<artifactId>commons-httpclient</artifactId>
|
||||||
<version>${commons-httpclient.version}</version>
|
<version>${commons-httpclient.version}</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.lambdaworks</groupId>
|
||||||
|
<artifactId>lettuce</artifactId>
|
||||||
|
<version>${lettuce.version}</version>
|
||||||
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>javax.servlet</groupId>
|
<groupId>javax.servlet</groupId>
|
||||||
<artifactId>javax.servlet-api</artifactId>
|
<artifactId>javax.servlet-api</artifactId>
|
||||||
|
|
@ -397,6 +404,11 @@
|
||||||
<artifactId>spring-data-mongodb</artifactId>
|
<artifactId>spring-data-mongodb</artifactId>
|
||||||
<version>${spring-data-mongo.version}</version>
|
<version>${spring-data-mongo.version}</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework.data</groupId>
|
||||||
|
<artifactId>spring-data-redis</artifactId>
|
||||||
|
<version>${spring-data-redis.version}</version>
|
||||||
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.springframework.integration</groupId>
|
<groupId>org.springframework.integration</groupId>
|
||||||
<artifactId>spring-integration-core</artifactId>
|
<artifactId>spring-integration-core</artifactId>
|
||||||
|
|
|
||||||
|
|
@ -26,6 +26,7 @@
|
||||||
<module>spring-boot-starter-mobile</module>
|
<module>spring-boot-starter-mobile</module>
|
||||||
<module>spring-boot-starter-actuator</module>
|
<module>spring-boot-starter-actuator</module>
|
||||||
<module>spring-boot-starter-parent</module>
|
<module>spring-boot-starter-parent</module>
|
||||||
|
<module>spring-boot-starter-redis</module>
|
||||||
<module>spring-boot-starter-security</module>
|
<module>spring-boot-starter-security</module>
|
||||||
<module>spring-boot-starter-shell-remote</module>
|
<module>spring-boot-starter-shell-remote</module>
|
||||||
<module>spring-boot-starter-test</module>
|
<module>spring-boot-starter-test</module>
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1 @@
|
||||||
|
/target
|
||||||
|
|
@ -0,0 +1,30 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
|
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||||
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
<parent>
|
||||||
|
<groupId>org.springframework.boot</groupId>
|
||||||
|
<artifactId>spring-boot-starters</artifactId>
|
||||||
|
<version>0.5.0.BUILD-SNAPSHOT</version>
|
||||||
|
</parent>
|
||||||
|
<artifactId>spring-boot-starter-redis</artifactId>
|
||||||
|
<packaging>jar</packaging>
|
||||||
|
<properties>
|
||||||
|
<main.basedir>${basedir}/../..</main.basedir>
|
||||||
|
</properties>
|
||||||
|
<dependencies>
|
||||||
|
<dependency>
|
||||||
|
<groupId>${project.groupId}</groupId>
|
||||||
|
<artifactId>spring-boot-starter</artifactId>
|
||||||
|
<version>${project.version}</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework.data</groupId>
|
||||||
|
<artifactId>spring-data-redis</artifactId>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.lambdaworks</groupId>
|
||||||
|
<artifactId>lettuce</artifactId>
|
||||||
|
</dependency>
|
||||||
|
</dependencies>
|
||||||
|
</project>
|
||||||
Loading…
Reference in New Issue