组件需要无法找到名为“dataSource_dbCreate”的bean

时间:2016-12-26 13:24:45

标签: grails spring-boot spring-data gorm-mongodb

我在grails上构建web应用程序,groovy与3 DB的MySql,Oracle(暂时向H2)进行交互,Mongo。为了创建我在以下属性

配置的dataSource
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

1 个答案:

答案 0 :(得分:2)

您在错误的区域中使用@Before public static WebDriver setUp() throws Exception { DesiredCapabilities capabilities; capabilities = new DesiredCapabilities(); capabilities.setJavascriptEnabled(true); capabilities.setCapability(PhantomJSDriverService.PHANTOMJS_EXECUTABLE_PATH_PROPERTY, "phantomjs.exe"); capabilities.setCapability("phantomjs.binary.path", "phantomjs.exe"); PhantomJSDriver driver = new PhantomJSDriver(capabilities); String baseURL = "url"; driver.get(baseURL); System.out.println("Loading page"); return driver; } @Test public static void test(WebDriver driver, String login, String password) throws InterruptedException, IOException { CookieHandler.addCookie(driver); //function that add a cookie to my driver CookieHandler.printAllCookies(driver); //just to verify cookie is added WebDriverWait wait = new WebDriverWait(driver, 10); WebElement LoginButton = wait.until(ExpectedConditions.presenceOfElementLocated(By.xpath("somexpath"))); LoginButton.click(); // ... some other treatement but code blocked here } ,这就是为什么它尝试创建dataSource_dbCreate:

dbCreate

将其移动到指定的dataSource:

environments:

    development:

        dataSources:

            dbCreate: create-drop

            dataSource:

还可以查看official docs with example