Grails 3.2.6具有弹簧安全性。在内存中,在保存用户时不会创建数据库

时间:2017-04-07 20:53:14

标签: grails h2

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

这是我的application.yml

CREATE TABLE DimStatAccount (StatAccount varchar(255), Accounts varchar(255), AccountsRange varchar(255))
INSERT INTO DimStatAccount VALUES
  ('Stat1', 'in (1000,1020)', null),
  ('Stat2', 'in (1020,2020)', null),
  ('Stat3', null, 'between 1000 and 1999'),
  ('Stat4', null, 'between 2000 and 2999')

CREATE TABLE FactAmount (Account int, [Month] varchar(255), Amount int)
INSERT INTO FactAmount VALUES
  (1000,'jan',500),
  (1000,'feb',460),
  (1010,'jan',799),
  (1010,'jan',855),
  (1010,'feb',633),
  (1020,'feb',522),
  (2000,'jan',436),
  (2000,'jan',946),
  (2000,'jan',374),
  (2010,'jan',683),
  (2010,'feb',492),
  (2020,'jan',437),
  (2020,'feb',834),
  (2030,'jan',944)

DECLARE @sqlStatement NVARCHAR(MAX) = '';

SELECT @sqlStatement += CONCAT('SELECT ''',StatAccount,''',[Month],SUM(Amount) FROM FactAmount WHERE Account ',ISNULL(Accounts,AccountsRange),' GROUP BY [Month] UNION ALL ')
FROM DimStatAccount
;

SET @sqlStatement = LEFT(@sqlStatement,LEN(@sqlStatement)-10); --remove the final Union All

EXEC sp_executesql @sqlStatement;

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

---
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

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

1 个答案:

答案 0 :(得分:1)

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