如何将application.yml
文件中的Integer参数传递给@EnableJdbcHttpSession
注释属性?它的工作原理如下:
@EnableJdbcHttpSession(tableName = "${some.string.property}")
但如果这样写的话会显示意外类型:
@EnableJdbcHttpSession(maxInactiveIntervalInSeconds = "${some.Integer.property}")
只有tableName
的@EnableJdbcHttpSession
属性支持占位符分辨率(请参阅related JdbcHttpSessionConfiguration
code)。
但是既然你提到application.yml
,如果你正在使用Spring Boot,你可以简单地省略@EnableJdbcHttpSession
并让Spring Boot自动配置Spring Session。此时,您可以使用以下属性轻松自定义Spring Session JDBC:
spring.session.jdbc.cleanup-cron=0 * * * * * # Cron expression for expired session cleanup job.
spring.session.jdbc.initialize-schema=embedded # Database schema initialization mode.
spring.session.jdbc.schema=classpath:org/springframework/session/jdbc/schema-@@platform@@.sql # Path to the SQL file to use to initialize the database schema.
spring.session.jdbc.table-name=SPRING_SESSION # Name of the database table used to store sessions.
有关详细信息,请参阅Spring Boot的reference manual。