1
|
package eu.dnetlib.repo.manager.server.config;
|
2
|
|
3
|
import org.apache.log4j.Logger;
|
4
|
import org.springframework.beans.factory.annotation.Value;
|
5
|
import org.springframework.context.annotation.Bean;
|
6
|
import org.springframework.context.annotation.Configuration;
|
7
|
import org.springframework.context.annotation.PropertySource;
|
8
|
import org.springframework.data.redis.connection.jedis.JedisConnectionFactory;
|
9
|
import org.springframework.session.data.redis.config.annotation.web.http.EnableRedisHttpSession;
|
10
|
import org.springframework.session.web.http.CookieSerializer;
|
11
|
import org.springframework.session.web.http.DefaultCookieSerializer;
|
12
|
|
13
|
import javax.annotation.PostConstruct;
|
14
|
|
15
|
@Configuration
|
16
|
@EnableRedisHttpSession
|
17
|
@PropertySource(value = { "classpath:eu/dnetlib/repo/manager/server/springContext-repo-manager.properties"} )
|
18
|
public class Config {
|
19
|
|
20
|
private static Logger LOGGER = Logger.getLogger(Config.class);
|
21
|
|
22
|
@Value("${rediss.host:localhost}")
|
23
|
private String host;
|
24
|
|
25
|
@Value("${rediss.port:6379}")
|
26
|
private String port;
|
27
|
|
28
|
@Value("${rediss.password:#{null}}")
|
29
|
private String password;
|
30
|
|
31
|
@PostConstruct
|
32
|
private void init(){
|
33
|
LOGGER.info(host);
|
34
|
}
|
35
|
|
36
|
@Bean
|
37
|
JedisConnectionFactory connectionFactory() {
|
38
|
LOGGER.info(String.format("Redis : %s Port : %s Password : %s",host,port,password));
|
39
|
JedisConnectionFactory jedisConnectionFactory = new JedisConnectionFactory();
|
40
|
jedisConnectionFactory.setHostName(host);
|
41
|
jedisConnectionFactory.setPort(Integer.parseInt(port));
|
42
|
if(password != null) jedisConnectionFactory.setPassword(password);
|
43
|
return jedisConnectionFactory;
|
44
|
}
|
45
|
|
46
|
@Bean
|
47
|
public CookieSerializer cookieSerializer() {
|
48
|
DefaultCookieSerializer serializer = new DefaultCookieSerializer();
|
49
|
serializer.setCookieName("SESSION"); // <1>
|
50
|
serializer.setCookiePath("/"); // <2>
|
51
|
return serializer;
|
52
|
}
|
53
|
|
54
|
}
|