Quantcast
Channel: Active questions tagged redis+java - Stack Overflow
Viewing all articles
Browse latest Browse all 2204

use session-data-redis @Autowired FindByIndexNameSessionRepository run error

$
0
0

this is my pom,xml

<dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-security</artifactId><version>2.2.7.RELEASE</version></dependency><dependency><groupId>org.springframework.session</groupId><artifactId>spring-session-data-redis</artifactId><version>2.2.2.RELEASE</version></dependency>

this is my SecurityConfig

@Configurationpublic class WebSecurityConfig<S extends Session> extends WebSecurityConfigurerAdapter {private final String successForwardUrl = "/auth/session";    private final String failureForwardUrl = "/auth/loginFail";    @Autowired    private MobileCodeSecurityConfigurer mobileCodeSecurityConfigurer;    @Override    public AuthenticationManager authenticationManagerBean() throws Exception {        return super.authenticationManagerBean();    }    @Override    protected void configure(AuthenticationManagerBuilder auth) throws Exception {        auth.authenticationProvider(mobileCodeAuthenticationProvider())            .authenticationProvider(usernamePasswordAuthenticationProvider());    }    @Override    protected void configure(HttpSecurity http) throws Exception {        http.cors();        http.headers().frameOptions().disable();        http.csrf().disable().exceptionHandling()            .authenticationEntryPoint(new HttpStatusEntryPoint(HttpStatus.UNAUTHORIZED));        List<String> authAntPatterns = new ArrayList<>();        authAntPatterns.add("/auth/**");        String[] authAntPatternsValue = authAntPatterns.toArray(new String[authAntPatterns.size()]);        http.authorizeRequests().antMatchers(authAntPatternsValue).permitAll();        http.authorizeRequests().anyRequest().authenticated();        http.formLogin().loginProcessingUrl("/auth/login").successHandler(authenticationSuccessHandler())            .failureHandler(authenticationFailureHandler());        http.logout().invalidateHttpSession(true).logoutUrl("/auth/logout")            .logoutSuccessHandler(new HttpStatusReturningLogoutSuccessHandler());        http.sessionManagement().maximumSessions(1).maxSessionsPreventsLogin(false).sessionRegistry(sessionRegistry());        http.apply(mobileCodeSecurityConfigurer);    }    @Bean    public HttpSessionEventPublisher httpSessionEventPublisher() {        return new HttpSessionEventPublisher();    }    @Autowired    private FindByIndexNameSessionRepository<S> sessionRepository;    @Bean    public SessionRegistry sessionRegistry() {        return new SpringSessionBackedSessionRegistry<S>(sessionRepository);    }}

this is my RedisSessionConfig

@EnableRedisHttpSessionpublic class RedisHttpSessionConfig {    @Bean    public LettuceConnectionFactory connectionFactory() {        RedisStandaloneConfiguration standaloneConfig = new RedisStandaloneConfiguration("182.43.172.163", 6379);        return new LettuceConnectionFactory(standaloneConfig);    }}

this is error msg。What should I do with it !!!

Error creating bean with name 'sessionRepositoryFilterRegistration' defined in class path resource [org/springframework/boot/autoconfigure/session/SessionRepositoryFilterConfiguration.class]: Unsatisfied dependency expressed through method 'sessionRepositoryFilterRegistration' parameter 1; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'org.springframework.session.data.redis.config.annotation.web.http.RedisHttpSessionConfiguration': Unsatisfied dependency expressed through method 'setHttpSessionListeners' parameter 0; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'webSecurityConfig': Unsatisfied dependency expressed through field 'sessionRepository'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionRepository' defined in class path resource [org/springframework/session/data/redis/config/annotation/web/http/RedisHttpSessionConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.session.data.redis.RedisIndexedSessionRepository]: Circular reference involving containing bean 'org.springframework.session.data.redis.config.annotation.web.http.RedisHttpSessionConfiguration' - consider declaring the factory method as static for independence from its containing instance. Factory method 'sessionRepository' threw exception; nested exception is java.lang.IllegalStateException: RedisConnectionFactory is required

Viewing all articles
Browse latest Browse all 2204

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>