带有弹簧安全性的圣杯 3.2.6.在内存中保存用户时不会创建 h2 数据库



我没有从其他帖子中找到解决方案,尽管这似乎是其他人遇到的问题。

这是我的应用程序.yml

---
grails:
    profile: web-plugin
    codegen:
        defaultPackage: bioprofile
    spring:
        transactionManagement:
            proxies: false
info:
    app:
        name: '@info.app.name@'
        version: '@info.app.version@'
        grailsVersion: '@info.app.grailsVersion@'
spring:
    main:
        banner-mode: "off"
    groovy:
        template:
            check-template-location: false
# Spring Actuator Endpoints are Disabled by Default
endpoints:
    enabled: false
    jmx:
        enabled: true
---
grails:
    mime:
        disable:
            accept:
                header:
                    userAgents:
                        - Gecko
                        - WebKit
                        - Presto
                        - Trident
        types:
            all: '*/*'
            atom: application/atom+xml
            css: text/css
            csv: text/csv
            form: application/x-www-form-urlencoded
            html:
              - text/html
              - application/xhtml+xml
            js: text/javascript
            json:
              - application/json
              - text/json
            multipartForm: multipart/form-data
            pdf: application/pdf
            rss: application/rss+xml
            text: text/plain
            hal:
              - application/hal+json
              - application/hal+xml
            xml:
              - text/xml
              - application/xml
    urlmapping:
        cache:
            maxsize: 1000
    controllers:
        defaultScope: singleton
    converters:
        encoding: UTF-8
    views:
        default:
            codec: html
        gsp:
            encoding: UTF-8
            htmlcodec: xml
            codecs:
                expression: html
                scriptlets: html
                taglib: none
                staticparts: none
endpoints:
    jmx:
        unique-names: true
---
hibernate:
    cache:
        queries: false
        use_second_level_cache: true
        use_query_cache: false
        region.factory_class: org.hibernate.cache.ehcache.SingletonEhCacheRegionFactory
dataSources:
    dataSource:
        pooled: true
        jmxExport: true
        driverClassName: org.h2.Driver
        username: sa
        password:
        dbCreate: create-drop
        dialect : com.hp.opr.hibernate.dialect.H2Dialect
        url: jdbc:h2:mem:blogDB;MVCC=TRUE;LOCK_TIMEOUT=10000;DB_CLOSE_ON_EXIT=FALSE
    master:
        pooled: true
        jmxExport: true
        driverClassName: org.h2.Driver
        username: sa
        password:
        dbCreate: create-drop
        url: jdbc:h2:mem:masterDb;MVCC=TRUE;LOCK_TIMEOUT=10000;DB_CLOSE_ON_EXIT=FALSE

但是当应用程序启动并在引导程序中,我尝试添加一些用户:

    User admin = new User(username: 'admin', password: 'password')
    admin.save(flush: true)
    User user = new User(username: 'user', password: 'user')
    user.save(flsuh:true)
    Role adminRole = new Role(authority: Role.ROLE_ADMIN)
    adminRole.save(flush:true)
    Role userRole = new Role(authority: Role.ROLE_USER)
    userRole.save(flush:true)
    UserRole.create(admin, adminRole)
    UserRole.create(admin, userRole)
    UserRole.create(user, userRole)

不创建任何数据库。但是,如果我从 url 打开控制台:http://localhost:8080/dbconsole 创建数据库。知道为什么吗?

您在 grails 配置中使用 H2 的内存配置,因此不会创建数据库文件。但是,当您打开 dbconsole 时,可能存在一个带有文件而不是内存配置的连接字符串,因此会创建一个 db 文件。更改数据库控制台配置中的配置。

最新更新