【问题标题】:Dependency error in Spring boot for Spring session and Redis. What is the correct dependency i have to use?Spring 会话和 Redis 的 Spring 启动中的依赖关系错误。我必须使用的正确依赖项是什么?
【发布时间】:2021-01-25 13:49:10
【问题描述】:

我有 Angular 2 前端和 Spring Boot 后端。我想使用用户名和密码登录,然后使用 x-auth-token 检查从 angular 发送的每个请求的会话。我想使用 Redis 存储会话.但是在连接到Redis时我不断收到以下错误。我的假设是我的spring session的依赖版本导致了这个问题,但我不明白为什么会这样? -

An attempt was made to call a method that does not exist. The attempt was made from the following location: org.springframework.session.data.redis.config.ConfigureNotifyKeyspaceEventsAction.getNotifyOptions(ConfigureNotifyKeyspaceEventsAction.java:74) The following method did not exist: org.springframework.data.redis.connection.RedisConnection.getConfig(Ljava/lang/String;)Ljava/util/List; The method's class, org.springframework.data.redis.connection.RedisConnection, is available from the following locations: jar:file:/C:/Users/Ajay/.m2/repository/org/springframework/data/spring-data-redis/2.3.3.RELEASE/spring-data-redis-2.3.3.RELEASE.jar!/org/springframework/data/redis/connection/RedisConnection.class The class hierarchy was loaded from the following locations: org.springframework.data.redis.connection.RedisConnection: file:/C:/Users/Ajay/.m2/repository/org/springframework/data/spring-data-redis/2.3.3.RELEASE/spring-data-redis-2.3.3.RELEASE.jar Action: Correct the classpath of your application so that it contains a single, compatible version of org.springframework.data.redis.connection.RedisConnection

春天-

  import org.springframework.context.annotation.Bean; 
  import org.springframework.data.redis.connection.lettuce.LettuceConnectionFactory;
  import org.springframework.session.data.redis.config.annotation.web.http.EnableRedisHttpSession;
  
  @EnableRedisHttpSession public class HttpSessionConfig {
  @Bean public LettuceConnectionFactory connectionFactory() { return new
  LettuceConnectionFactory(); }
  
  }




@Configuration
@EnableWebSecurity
public class SecurityConfig extends WebSecurityConfigurerAdapter{
    
    @Autowired
    Environment env; 

    @Autowired
    UserSecurityService useSecurityService;
    
    private BCryptPasswordEncoder passwordEncoder() {
        return SecurityUtility.passwordEncoder();
    }
    
    private static final String[] PUBLIC_MATHCES= {
            "/css/**",
            "/js/**",
            "/image/**",
            "/book/**",
            "/user/**"
    };

    @Override
    protected void configure(AuthenticationManagerBuilder auth) throws Exception {
        auth.userDetailsService(useSecurityService).passwordEncoder(passwordEncoder());
        
        
    }

    @Override
    protected void configure(HttpSecurity http) throws Exception {
        http.authorizeRequests()
            .antMatchers(PUBLIC_MATHCES).permitAll()
            .anyRequest().authenticated();
        http.csrf().disable()
            .cors()
            .and()
            .httpBasic();
        
    }
    
    
      @Bean public HttpSessionStrategy httpSessionStrategy() { 
          return new HeaderHttpSessionStrategy(); 
      }
        
}

pom.xml-

<?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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.3.3.RELEASE</version>
        <relativePath /> <!-- lookup parent from repository -->
    </parent>
    <groupId>com.bookstore</groupId>
    <artifactId>bookstore</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <name>BookStore</name>
    <description>BookStore backend</description>

    <properties>
        <java.version>1.8</java.version>
    </properties>

    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>

        <!-- https://mvnrepository.com/artifact/org.springframework.boot/spring-boot-starter-data-jpa -->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-data-jpa</artifactId>
        </dependency>

        <!-- https://mvnrepository.com/artifact/org.springframework.boot/spring-boot-starter-jdbc -->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-jdbc</artifactId>
        </dependency>

        <!-- https://mvnrepository.com/artifact/org.springframework.boot/spring-boot-starter-security -->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-security</artifactId>
        </dependency>

        <!-- https://mvnrepository.com/artifact/MySQL/mysql-connector-java -->
        <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
        </dependency>


<!-- https://mvnrepository.com/artifact/org.springframework.session/spring-session -->
<dependency>
    <groupId>org.springframework.session</groupId>
    <artifactId>spring-session</artifactId>
    <version>1.3.5.RELEASE</version>
</dependency>



 <dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-data-redis</artifactId>
</dependency>

<dependency>
    <groupId>org.springframework.session</groupId>
    <artifactId>spring-session-data-redis</artifactId>
</dependency>  



        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
            <exclusions>
                <exclusion>
                    <groupId>org.junit.vintage</groupId>
                    <artifactId>junit-vintage-engine</artifactId>
                </exclusion>
            </exclusions>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
        </plugins>
    </build>

</project>

【问题讨论】:

    标签: java spring spring-boot maven redis


    【解决方案1】:

    我认为 pom.xml 有点混乱。你有冲突的依赖关系。

    使用下面的命令查看加载了哪些依赖项的详细信息 n 哪些被省略了。

    mvn dependency:tree -Dverbose -Dincludes=commons-collections

    这会给你一些见解。

    https://maven.apache.org/plugins/maven-dependency-plugin/examples/resolving-conflicts-using-the-dependency-tree.html

    在我看来,您也可以尝试删除以下依赖项并运行应用程序。

    <dependency>
    <groupId>org.springframework.session</groupId>
    <artifactId>spring-session</artifactId>
        <version>1.3.5.RELEASE</version>
    </dependency>
    

    【讨论】:

      猜你喜欢
      • 2012-09-15
      • 2019-09-02
      • 1970-01-01
      • 2021-06-08
      • 1970-01-01
      • 1970-01-01
      • 2022-10-04
      • 2016-09-17
      • 1970-01-01
      相关资源
      最近更新 更多