加入收藏 | 设为首页 | 会员中心 | 我要投稿 湖南网 (https://www.hunanwang.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程 > 正文

mysql – 行使JDBC设置的Spring-Session:表’test.spring_sess

发布时间:2021-03-06 05:35:11 所属栏目:编程 来源:网络整理
导读:我实行运行this example但不行使Redis,而是行使我的当地MySQL处事器. 我编辑了这个春季启动应用措施,如下所示: 摇篮: buildscript { repositories { mavenCentral() } dependencies { classpath("org.springframework.boot:spring-boot-gradle-plugin:$spr

我实行运行this example但不行使Redis,而是行使我的当地MySQL处事器.

我编辑了这个春季启动应用措施,如下所示:

摇篮:

buildscript {
    repositories {
        mavenCentral()
    }
    dependencies {
        classpath("org.springframework.boot:spring-boot-gradle-plugin:$springBootVersion")
    }
}

apply plugin: 'spring-boot'

apply from: JAVA_GRADLE


//this 'if' statement is because I was getting error: Execution failed for task ':samples:findbyusername:findMainClass'.
//> Could not find property 'main' on task ':samples:findbyusername:run'.
if (!hasProperty('mainClass')) {
    ext.mainClass = 'sample.FindByUsernameApplication'
}

tasks.findByPath("artifactoryPublish")?.enabled = false

group = 'samples'

dependencies {
    compile("org.springframework.boot:spring-boot-starter-jdbc:$springBootVersion") 
    compile group: 'mysql',name: 'mysql-connector-java',version: '6.0.2'
    compile group: 'org.springframework.session',name: 'spring-session',version: '1.2.0.RELEASE'



    compile project(':spring-session'),"org.springframework.boot:spring-boot-starter-web","org.springframework.boot:spring-boot-starter-thymeleaf","nz.net.ultraq.thymeleaf:thymeleaf-layout-dialect","org.springframework.security:spring-security-web:$springSecurityVersion","org.springframework.security:spring-security-config:$springSecurityVersion","com.maxmind.geoip2:geoip2:2.3.1","org.apache.httpcomponents:httpclient"

    testCompile "org.springframework.boot:spring-boot-starter-test","org.assertj:assertj-core:$assertjVersion"

    integrationTestCompile gebDependencies,"org.spockframework:spock-spring:$spockVersion"

}



def reservePort() {
    def socket = new ServerSocket(0)
    def result = socket.localPort
    socket.close()
    result
}

application.properties

spring.datasource.url = jdbc:mysql://localhost:3306/TEST?characterEncoding=UTF-8&useUnicode=true&useJDBCCompliantTimezoneShift=true&useLegacyDatetimeCode=false&serverTimezone=UTC
spring.datasource.driverClassName = com.mysql.jdbc.Driver
spring.datasource.username=root
spring.datasource.password=but

spring.thymeleaf.cache=false
spring.template.cache=false

HttpSessionConfig.java

@EnableJdbcHttpSession // <1>
public class HttpSessionConfig {
}

应用措施从tomcat开始,可是当我在赏识器中点击localhost时,我获得:

Whitelabel Error Page

This application has no explicit mapping for /error,so you are seeing this as a fallback.

Mon May 23 21:14:31 CEST 2016
There was an unexpected error (type=Internal Server Error,status=500).
PreparedStatementCallback; bad SQL grammar [INSERT INTO SPRING_SESSION(SESSION_ID,CREATION_TIME,LAST_ACCESS_TIME,MAX_INACTIVE_INTERVAL,PRINCIPAL_NAME) VALUES (?,?,?)]; nested exception is java.sql.SQLSyntaxErrorException: Table 'test.spring_session' doesn't exist

我不记得读过关于手动建设这个表的任何内容以是我以为spring会为我处理赏罚它…

编辑:
我现实上实行了manually create tables,然后应用措施运行正常.但我想我不该该手动这样做. 最佳谜底 Spring Session附带了大大都首要RDBMS的数据库模式剧本(位于org.springframework.session.jdbc包中),但Spring Session JDBC支持的数据库表的建设必要由用户本身处理赏罚.

提供的剧本可以不受影响地行使,可是一些用户可以选择行使提供的剧本作为参考来修改它们以满意其特定需求.

一种选择是行使数据库迁徙器材(如Flyway)来处理赏罚数据库表的建设.

因为您正在行使Spring Boot,因此您也许会有一个待处理赏罚的PR来添加对Spring Session JDBC模式的自动初始化的支持:https://github.com/spring-projects/spring-boot/pull/5879

假如文档误导您以为表应该由Spring Session自动建设,请思量陈诉题目,以便我们可以在须要时更新文档:https://github.com/spring-projects/spring-session/issues

(编辑:湖南网)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    热点阅读