将JdbcOperationsSessionRepository注入到构造函数中。

huangapple go评论74阅读模式
英文:

Injecting JdbcOperationsSessionRepository into a constructor

问题

我正在将一个 SpringBoot 应用从 2.1.17 升级到 2.3.4,在这个过程中涉及到以下的类:

@Configuration
public class SessionRepositoryConfig {
    public SessionRepositoryConfig(JdbcOperationsSessionRepository sessionRepo) {
        // 配置会话过期 + 表名 + 转换器
        // ...
        // ...
    }
}

这是整个代码库中唯一涉及到 JdbcOperationsSessionRepository 的部分,所以可以推测在 2.1.17 版本中,SpringBoot 可能自动创建了这种类型的 bean。然而,当我切换到 2.3.4 版本时,注入失败了:

  .   ____          _            __ _ _
 /\\ / ___'_ __ _ _(_)_ __  __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
 \\/  ___)| |_)| | | | | || (_| |  ) ) ) )
  '  |____| .__|_| |_|_| |_\__, | / / / /
 =========|_|==============|___/=/_/_/_/
 :: Spring Boot ::        (v2.3.4.RELEASE)

2020-10-13 12:32:43.970  INFO --- [kground-preinit] o.h.v.i.u.Version                        : HV000001: Hibernate Validator 6.1.2.Final
...
... (日志内容)
...
2020-10-13 12:32:50.410  INFO --- [           main] ConditionEvaluationReportLoggingListener :

我怎样能够最简单地使这个工作正常?

英文:

I'm upgrading a SpringBoot app from 2.1.17 to 2.3.4, which includes this class:

@Configuration
public class SessionRepositoryConfig {
    public SessionRepositoryConfig(JdbcOperationsSessionRepository sessionRepo) {
		// configure session expiry + table name + converter
		...
		...
	}
}

This is the only mention of JdbcOperationsSessionRepository in the entire code-base, so presumably in 2.1.17 a bean of this type was automatically made available by SpringBoot. However, when I switch to 2.3.4 the injection fails:

  .   ____          _            __ _ _
 /\\ / ___'_ __ _ _(_)_ __  __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
 \\/  ___)| |_)| | | | | || (_| |  ) ) ) )
  '  |____| .__|_| |_|_| |_\__, | / / / /
 =========|_|==============|___/=/_/_/_/
 :: Spring Boot ::        (v2.3.4.RELEASE)

2020-10-13 12:32:43.970  INFO --- [kground-preinit] o.h.v.i.u.Version                        : HV000001: Hibernate Validator 6.1.2.Final
2020-10-13 12:32:44.082  INFO --- [           main] c.s.o.a.s.UIAuthorizationEndpointTest    : Starting UIAuthorizationEndpointTest on UK-WMorgan1 with PID 17444 (started by WMorgan in C:\git_repos\oauth2-auth-server\sc-oauth2-authorization-server-application)
2020-10-13 12:32:44.086  INFO --- [           main] c.s.o.a.s.UIAuthorizationEndpointTest    : The following profiles are active: local,dbAutoUpdate,localLDAP
WARNING: An illegal reflective access operation has occurred
WARNING: Illegal reflective access by org.codehaus.groovy.reflection.CachedClass (file:/C:/Users/wmorgan/.m2/repository/org/codehaus/groovy/groovy/2.5.13/groovy-2.5.13.jar) to method java.lang.Object.finalize()
WARNING: Please consider reporting this to the maintainers of org.codehaus.groovy.reflection.CachedClass
WARNING: Use --illegal-access=warn to enable warnings of further illegal reflective access operations
WARNING: All illegal access operations will be denied in a future release
2020-10-13 12:32:47.823  INFO --- [           main] o.s.b.w.e.t.TomcatWebServer              : Tomcat initialized with port(s): 0 (http)
2020-10-13 12:32:47.848  INFO --- [           main] o.a.c.h.Http11NioProtocol                : Initializing ProtocolHandler ["http-nio-auto-1"]
2020-10-13 12:32:47.849  INFO --- [           main] o.a.c.c.StandardService                  : Starting service [Tomcat]
2020-10-13 12:32:47.849  INFO --- [           main] o.a.c.c.StandardEngine                   : Starting Servlet engine: [Apache Tomcat/9.0.38]
2020-10-13 12:32:48.046  INFO --- [           main] o.a.c.c.C.[.[.[/oauth2Server]            : Initializing Spring embedded WebApplicationContext
2020-10-13 12:32:48.046  INFO --- [           main] w.s.c.ServletWebServerApplicationContext : Root WebApplicationContext: initialization completed in 3561 ms
2020-10-13 12:32:48.444  INFO --- [           main] c.t.c.c.f.KeyStoreFactoryBean            : Loading key store from URL [file:./src/test/resources/thunderhead.jks]
2020-10-13 12:32:48.809  INFO --- [           main] c.z.h.HikariDataSource                   : HikariPool-1 - Starting...
2020-10-13 12:32:49.120  INFO --- [           main] c.z.h.HikariDataSource                   : HikariPool-1 - Start completed.
2020-10-13 12:32:50.376  WARN --- [           main] ConfigServletWebServerApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'sessionRepositoryConfiguration' defined in file [C:\git_repos\oauth2-auth-server\sc-oauth2-authorization-server-application\target\classes\com\SessionRepositoryConfig.class]: Unsatisfied dependency expressed through constructor parameter 0; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: 
No qualifying bean of type 'org.springframework.session.jdbc.JdbcOperationsSessionRepository' available: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: {}
2020-10-13 12:32:50.377  INFO --- [           main] c.z.h.HikariDataSource                   : HikariPool-1 - Shutdown initiated...
2020-10-13 12:32:50.385  INFO --- [           main] c.z.h.HikariDataSource                   : HikariPool-1 - Shutdown completed.
2020-10-13 12:32:50.393  INFO --- [           main] o.a.c.c.StandardService                  : Stopping service [Tomcat]
2020-10-13 12:32:50.410  INFO --- [           main] ConditionEvaluationReportLoggingListener : 

What's the simplest way I can get this working again?

答案1

得分: 0

已通过将JdbcOperationsSessionRepository替换为JdbcIndexedSessionRepository进行修复。

英文:

Fixed by replacing JdbcOperationsSessionRepository with JdbcIndexedSessionRepository

huangapple
  • 本文由 发表于 2020年10月13日 19:04:12
  • 转载请务必保留本文链接:https://go.coder-hub.com/64334012.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定