grails3配置过滤器_Grails 3数据源配置

grails3配置过滤器

Grails 3具有新的配置文件和格式。 新格式基于YAML,用于数据库配置的文件名为grails-app / conf / application.yml。 在Grails 1、1和2上开发应用程序后,我才刚刚开始使用Grails3。我期待着构建新的Grails 3应用程序。

在开始之前,我阅读了Grails 2到Grails 3的升级说明,并且感到非常自信。 但是,我昨天遇到一个问题,我想在这里描述一下,以防它对您有所帮助。

首先,这是application.yml的有效代码段,该代码段是为mySQL配置的数据源

dataSource:
    pooled: true
    jmxExport: true
    # driverClassName: org.h2.Driver
    driverClassName: com.mysql.jdbc.Driver
    # dialect: org.hibernate.dialect.MySQL5InnoDBDialect
    username: root
    password: root
 
environments:
    development:
        dataSource:
            # dbCreate = "create-drop" // one of 'create', 'create-drop', 'update', 'validate', ''
            dbCreate: create
            url: jdbc:mysql://localhost/demo?autoReconnect=true

但是,这是您应该小心的地方。

确保您未在​​YAML文件中使用<variable_name> =“ <setting>”的格式。 我什么意思 好吧,这是一个例子:

dataSource:
    pooled: true
    jmxExport: true
    # driverClassName: org.h2.Driver
    driverClassName: com.mysql.jdbc.Driver
    # dialect: org.hibernate.dialect.MySQL5InnoDBDialect
    username: root
    password: root
 
environments:
    development:
        dataSource:
            # dbCreate = "create-drop" // one of 'create', 'create-drop', 'update', 'validate', ''
            dbCreate = "create"
            url = "jdbc:mysql://localhost/demo?autoReconnect=true"

我以这种方式配置了Grails 3数据源,并且在grails运行应用程序启动时收到错误:

ERROR org.springframework.boot.SpringApplication - Application startup failed
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'persistenceInterceptor': Cannot resolve reference to bean 'hibernateDatastore' while setting bean property 'hibernateDatastore'; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'hibernateDatastore' is defined

是的,回想起来,这令人尴尬。 我花了更多的时间进行调试,这超出了我的意愿。 因此,以防万一它可以帮助任何人,我正在为您写下来。

翻译自: https://www.javacodegeeks.com/2016/02/grails-3-datasource-configuration.html

grails3配置过滤器

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值