NoSuchBeanDefinitionException:没有'javax.sql.DataSource'类型的限定bean

时间:2017-11-09 15:08:23

标签: spring-boot spring-data-jpa datasource

我尝试用jpa和没有jdbc构建我的spring-boot项目。 但是会发生以下错误:

- >现在我使用spring数据源编辑了我的代码和配置,但我也得到了异常T T

- >我已经配置了mysql数据源但是发生了错误。

我的应用程序代码如下:

    :::


    @SpringBootApplication
    public class OAuth2Application extends SpringBootServletInitializer   {

        public static void main(String[] args) {

            new SpringApplicationBuilder(OAuth2Application.class)
            .initializers(new OAuth2ApplicationContextInitializer())
            .run(args);
       }
   :::
   }


   [application.yml]

    :::
    #spring.h2.console:
    #  enabled: true
    #  path: /h2-console
    #
    # 외부 DB 설정시 아래의 주석을 활성화 시킨 후 관련 DB 설정 정보를 입력한다.
    #spring:
    #  datasource:
    #    url:               jdbc:h2:tcp://localhost/~/api;DB_CLOSE_DELAY=-1;DB_CLOSE_ON_EXIT=FALSE
    #    driverClassName: org.h2.Driver
    #    username: sa
    #    password:
    # DataSource
    spring.datasource:
      driver-class-name: com.mysql.jdbc.Driver
      url: 'jdbc:mysql://localhost:3306/db'
      username: user
      password: pass

    #
    # MongoDB data
    spring.data:
      mongodb: 
        #uri: mongodb://localhost/
        host: localhost
        port: 27017 
        database: db
        username: user
        password: pass
        repositories.enabled: true
    #
    mybatis:
      config-location: 'classpath:mybatis-config.xml'

    [my exception log]
    java.lang.IllegalStateException: Failed to load ApplicationContext
        at org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContext(DefaultCacheAwareContextLoaderDelegate.java:124)
        at org.springframework.test.context.support.DefaultTestContext.getApplicationContext(DefaultTestContext.java:83)
    :::
    Caused by: org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.apache.tomcat.jdbc.pool.DataSource]
   :::
   DataSourceBeanCreationException: Cannot determine embedded database driver class for database type NONE. If you want an embedded database please put a supported one on the classpath

1 个答案:

答案 0 :(得分:0)

mvn install - >安装&试运行得到了错误! 但是mvn spring-boot:run do work good !!!

我不知道测试运行问题......

相关问题