2016-05-23 22 views
3

は私がthis exampleを実行しようとするが、代わりに私のローカルのMySQLサーバと、Redisのを使用せずに存在していません。春のセッションJDBC構成を持つ:テーブル「test.spring_sessionは」

私はこのように、この春ブーツアプリを編集した:

のGradle:

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

を私は春がそれを処理すると仮定

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 

私は手動でこのテーブルを作成する方法について何かを読んで覚えていません:アプリケーションはTomcat上で起動しますが、私は私のブラウザではlocalhostを打ったとき、私は取得

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

私のために...

編集: 私は実際にmanually create tablesにしようとし、アプリケーションが正常に実行されます。しかし、私は手動でこれを行うべきではないと思います。

+1

私はあなたがそれらを手動で作成することがあると思います。ここでは例えばドキュメントはそれが使っている組み込みデータベース内のテーブルを設定するためのスクリプトを持っている: http://docs.spring.io/spring-session/docs/current/reference/html5/guides/httpsession-jdbc .html – PaulNUK

答えて

7

Springセッションには、ほとんどの主要なRDBMS(org.springframework.session.jdbcパッケージに含まれています)のデータベーススキーマスクリプトが同梱されていますが、Spring Session JDBCサポート用のデータベーステーブルを作成する必要があります。

用意されているスクリプトは、しかし、一部のユーザーが参照として提供されるスクリプトを使用して、特定のニーズに合うようにそれらを変更することもできます、そのまま使用することができます。

オプションは、データベーステーブルの作成を処理するために、Flywayなどのデータベース移行ツールを使用することです。

あなたは春のブートを使用しているので、それは春のセッションJDBCスキーマの自動初期化のためのサポートを追加するための保留中のPRがあることが、あなたの興味があるかもしれない:https://github.com/spring-projects/spring-boot/pull/5879

ドキュメントは、テーブルを考えることにあなたを誤解した場合春のセッション自体によって自動的に作成する必要があり、必要に応じて、我々はドキュメントを更新できるように問題を報告して考えてみます。https://github.com/spring-projects/spring-session/issues

+0

私は定期的にここに戻ってくるのを忘れて、「ハ!私のテーブルを作成して行く。 –

関連する問題