一个组件需要一个名为 'dataSource_dbCreate' 的 bean,但找不到

A component required a bean named 'dataSource_dbCreate' that could not be found

我在 grails 上构建 Web 应用程序,groovy 与 3 个数据库 MySql,Oracle(暂时指向 H2),Mongo 进行交互。为了创建数据源,我配置了以下属性

environments:

development:

    dataSources:

        dbCreate: create-drop

        dataSource:
            # local dev mysql db
             url: "jdbc:mysql://localhost:3307/my_db?useUnicode=true&useJDBCCompliantTimezoneShift=true&useLegacyDatetimeCode=false&serverTimezone=UTC"
             username: root
             password: root

        oraclerpt:
           url: jdbc:h2:mem:devDb;MVCC=TRUE;LOCK_TIMEOUT=10000;DB_CLOSE_ON_EXIT=FALSE

    # mongodb settings
    grails:
        mongodb:
           url: "mongodb://localhost/my_db"
            # port: 27017
           #  databaseName: "my_db"
test:
    dataSources:
        oraclerpt:
            url: "jdbc:oracle:thin:@remoteIP:1521/my_db"
            username: XXX
            password: XXXX
            formatSql: true
            use_sql_comments: true
        dataSource:
            url: "jdbc:dataSource://RemoteAlias:3306/de_test"
            username: XXX
            password: XXXX
    # mongodb settings
    grails:
        mongodb:
            url: "mongodb://localhost/de_mfs_test"
# put settings here for deployment environments
production:

application.yml

数据源:

dataSource:

    dbCreate: none

    pooled: true

    jmxExport: true
    driverClassName: "com.mysql.cj.jdbc.Driver"
    dialect: org.hibernate.dialect.MySQL5InnoDBDialect
    properties:
          jmxEnabled: true
          initialSize: 5
          maxActive: 50
          minIdle: 5
          maxIdle: 25
          maxWait: 10000
          maxAge: 600000
          timeBetweenEvictionRunsMillis: 5000
          minEvictableIdleTimeMillis: 60000
          validationQuery: SELECT 1 FROM DUAL
          validationQueryTimeout: 3
          validationInterval: 15000
          testOnBorrow: true
          testWhileIdle: true
          testOnReturn: false
          jdbcInterceptors: ConnectionState
          defaultTransactionIsolation: 2 #

当我构建这个时出现以下错误

2016-12-26 12:15:58,276 ERROR localhost-startStop-1  org.springframework.boot.context.embedded.tomcat.TomcatStarter - Error starting Tomcat context. Exception: org.springframework.beans.factory.BeanCreationException. Message: Error creating bean with name 'filterInvocationInterceptorFilterDeregistrationBean': Cannot resolve reference to bean 'filterInvocationInterceptor' while setting bean property 'filter'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'filterInvocationInterceptor': Cannot resolve reference to bean 'authenticationManager' while setting bean property 'authenticationManager'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'authenticationManager': Cannot resolve reference to bean 'daoAuthenticationProvider' while setting constructor argument with key [0]; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'daoAuthenticationProvider': Cannot resolve reference to bean 'userDetailsService' while setting bean property 'userDetailsService'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'userDetailsService': Initialization of bean failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'transactionManager': Cannot resolve reference to bean 'transactionManager_dbCreate' while setting constructor argument with key [3]; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'transactionManager_dbCreate': Cannot resolve reference to bean 'dataSource_dbCreate' while setting bean property 'dataSource'; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'dataSource_dbCreate' is defined
2016-12-26 12:15:58,479 ERROR main  org.springframework.boot.diagnostics.LoggingFailureAnalysisReporter - 

***************************
APPLICATION FAILED TO START
***************************

Description:

A component required a bean named 'dataSource_dbCreate' that could not be found.


Action:

Consider defining a bean named 'dataSource_dbCreate' in your configuration.


FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':bootRun'.
> Process 'command 'C:\Program Files\Java\jdk1.8.0_111\bin\java.exe'' finished with non-zero exit value 1

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.
Error |
Failed to start server (Use --stacktrace to see the full trace)

Process finished with exit code 1

您在错误的块中使用了 dbCreate,这就是它试图创建 dataSource_dbCreate:

的原因
environments:

    development:

        dataSources:

            dbCreate: create-drop

            dataSource:

将其移动到指定的数据源下:

environments:

    development:

        dataSources:

            dataSource:

                dbCreate: create-drop

另请查看 official docs with example