Spring Boot - 无法确定数据库类型为NONE的嵌入式数据库驱动程序类

时间:2014-06-06 05:24:44

标签: java google-app-engine jpa spring-data spring-boot

这是尝试运行我的网络应用时引发的错误:

[INFO] WARNING: Nested in org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.boot.autoconfigure.orm.jpa.HibernateJpaAutoConfiguration': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private javax.sql.DataSource org.springframework.boot.autoconfigure.orm.jpa.JpaBaseConfiguration.dataSource; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dataSource' defined in class path resource [org/springframework/boot/autoconfigure/jdbc/DataSourceAutoConfiguration$NonEmbeddedConfiguration.class]: Instantiation of bean failed; nested exception is org.springframework.beans.factory.BeanDefinitionStoreException: Factory method [public javax.sql.DataSource org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration$NonEmbeddedConfiguration.dataSource()] threw exception; nested exception is org.springframework.beans.factory.BeanCreationException: Cannot determine embedded database driver class for database type NONE. If you want an embedded database please put a supported one on the classpath.:
    [INFO] org.springframework.beans.factory.BeanCreationException: Cannot determine embedded database driver class for database type NONE. If you want an embedded database please put a supported one on the classpath.
    [INFO]  at org.springframework.boot.autoconfigure.jdbc.DataSourceProperties.getDriverClassName(DataSourceProperties.java:91)
    [INFO]  at org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration$NonEmbeddedConfiguration.dataSource(DataSourceAutoConfiguration.java:100)
    [INFO]  at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    [INFO]  at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    [INFO]  at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    [INFO]  at java.lang.reflect.Method.invoke(Method.java:606)
    [INFO]  at com.google.appengine.tools.development.agent.runtime.Runtime.invoke(Runtime.java:115)
    [INFO]  at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:166)
    [INFO]  at org.springframework.beans.factory.support.ConstructorResolver$3.run(ConstructorResolver.java:580)
    [INFO]  at java.security.AccessController.doPrivileged(Native Method)
    [INFO]  at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:577)
    [INFO]  at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateUsingFactoryMethod(AbstractAutowireCapableBeanFactory.java:1094)
    [INFO]  at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:989)
    [INFO]  at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:504)
    [INFO]  at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:475)
    [INFO]  at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:304)
    [INFO]  at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:228)
    [INFO]  at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:300)
    [INFO]  at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:195)
    [INFO]  at org.springframework.beans.factory.support.DefaultListableBeanFactory.findAutowireCandidates(DefaultListableBeanFactory.java:1017)
    [INFO]  at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:960)
    [INFO]  at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:858)
    [INFO]  at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:480)
    [INFO]  at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:87)
    [INFO]  at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:289)
    [INFO]  at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1185)
    [INFO]  at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:537)
    [INFO]  at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:475)
    [INFO]  at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:304)
    [INFO]  at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:228)
    [INFO]  at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:300)
    [INFO]  at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:195)
    [INFO]  at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:370)
    [INFO]  at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateUsingFactoryMethod(AbstractAutowireCapableBeanFactory.java:1094)
    [INFO]  at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:989)
    [INFO]  at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:504)
    [INFO]  at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:475)
    [INFO]  at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:304)
    [INFO]  at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:228)
    [INFO]  at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:300)
    [INFO]  at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:195)
    [INFO]  at org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:973)
    [INFO]  at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:750)
    [INFO]  at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:482)
    [INFO]  at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:683)
    [INFO]  at org.springframework.boot.SpringApplication.run(SpringApplication.java:313)
    [INFO]  at org.springframework.boot.builder.SpringApplicationBuilder.run(SpringApplicationBuilder.java:142)
    [INFO]  at org.springframework.boot.legacy.context.web.SpringBootContextLoaderListener.initWebApplicationContext(SpringBootContextLoaderListener.java:60)
    [INFO]  at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:106)
    [INFO]  at org.mortbay.jetty.handler.ContextHandler.startContext(ContextHandler.java:548)
    [INFO]  at org.mortbay.jetty.servlet.Context.startContext(Context.java:136)
    [INFO]  at org.mortbay.jetty.webapp.WebAppContext.startContext(WebAppContext.java:1250)
    [INFO]  at org.mortbay.jetty.handler.ContextHandler.doStart(ContextHandler.java:517)
    [INFO]  at org.mortbay.jetty.webapp.WebAppContext.doStart(WebAppContext.java:467)
    [INFO]  at org.mortbay.component.AbstractLifeCycle.start(AbstractLifeCycle.java:50)
    [INFO]  at org.mortbay.jetty.handler.HandlerWrapper.doStart(HandlerWrapper.java:130)
    [INFO]  at org.mortbay.component.AbstractLifeCycle.start(AbstractLifeCycle.java:50)
    [INFO]  at org.mortbay.jetty.handler.HandlerWrapper.doStart(HandlerWrapper.java:130)
    [INFO]  at org.mortbay.jetty.Server.doStart(Server.java:224)
    [INFO]  at org.mortbay.component.AbstractLifeCycle.start(AbstractLifeCycle.java:50)
    [INFO]  at com.google.appengine.tools.development.JettyContainerService.startContainer(JettyContainerService.java:249)
    [INFO]  at com.google.appengine.tools.development.AbstractContainerService.startup(AbstractContainerService.java:306)
    [INFO]  at com.google.appengine.tools.development.AutomaticInstanceHolder.startUp(AutomaticInstanceHolder.java:26)
    [INFO]  at com.google.appengine.tools.development.AbstractModule.startup(AbstractModule.java:79)
    [INFO]  at com.google.appengine.tools.development.Modules.startup(Modules.java:88)
    [INFO]  at com.google.appengine.tools.development.DevAppServerImpl.doStart(DevAppServerImpl.java:254)
    [INFO]  at com.google.appengine.tools.development.DevAppServerImpl.access$000(DevAppServerImpl.java:47)
    [INFO]  at com.google.appengine.tools.development.DevAppServerImpl$1.run(DevAppServerImpl.java:212)
    [INFO]  at com.google.appengine.tools.development.DevAppServerImpl$1.run(DevAppServerImpl.java:210)
    [INFO]  at java.security.AccessController.doPrivileged(Native Method)
    [INFO]  at com.google.appengine.tools.development.DevAppServerImpl.start(DevAppServerImpl.java:210)
    [INFO]  at com.google.appengine.tools.development.DevAppServerMain$StartAction.apply(DevAppServerMain.java:277)
    [INFO]  at com.google.appengine.tools.util.Parser$ParseResult.applyArgs(Parser.java:48)
    [INFO]  at com.google.appengine.tools.development.DevAppServerMain.run(DevAppServerMain.java:219)
    [INFO]  at com.google.appengine.tools.development.DevAppServerMain.main(DevAppServerMain.java:210)

我相信我拥有datanucleus-appenginedatanucleus罐子的正确组合:

  

2.1:需要DataNucleus 3.1.x(core,api-jdo,api-jpa,enhancer)。需要SDK 1.6.4+请注意,此版本的Datanucleus不再存在   由DataNucleus项目支持

JPA App配置:

@Configuration
@EnableJpaRepositories("demo.core.entity")
@EnableTransactionManagement
class JpaApplicationConfig {
    private static final Logger logger = Logger
            .getLogger(JpaApplicationConfig.class.getName());
    @Bean
    public AbstractEntityManagerFactoryBean entityManagerFactory() {
        logger.info("Loading Entity Manager...");
        LocalContainerEntityManagerFactoryBean factory = new LocalContainerEntityManagerFactoryBean();
        factory.setPersistenceUnitName("transactions-optional");
        return factory;
    }
    @Bean
    public PlatformTransactionManager transactionManager() {
        logger.info("Loading Transaction Manager...");
        JpaTransactionManager txManager = new JpaTransactionManager();
        txManager.setEntityManagerFactory(entityManagerFactory().getObject());
        return txManager;
    }
    @Bean
    public PersistenceExceptionTranslator persistenceExceptionTranslator() {
        return new OpenJpaDialect();
    }
}

Application.java

@Configuration
@ComponentScan
@EnableAutoConfiguration
@RestController
public class Application {

    private static final EntityManagerFactory INSTANCE =
            Persistence.createEntityManagerFactory("transactions-optional");

    public static void main(String[] args) {
        SpringApplication.run(Application.class, args);
    }

    @RequestMapping("/")
    public String home() {
        return "Hello World";
    }

}

POM:

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="...">
    <modelVersion>4.0.0</modelVersion>

    <groupId>org.demohq</groupId>
    <artifactId>demo-boot</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <packaging>war</packaging>

    <name>demo-boot</name>
    <description>Demo project</description>

    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>1.1.0.BUILD-SNAPSHOT</version>
    </parent>

    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-actuator</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-tomcat</artifactId>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-legacy</artifactId>
            <version>1.1.0.BUILD-SNAPSHOT</version>
        </dependency>
        <!--<dependency>-->
            <!--<groupId>net.kindleit</groupId>-->
            <!--<artifactId>gae-runtime</artifactId>-->
            <!--<version>${gae.version}</version>-->
            <!--<type>pom</type>-->
            <!--<scope>provided</scope>-->
        <!--</dependency>-->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-data-jpa</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-aspects</artifactId>
        </dependency>
        <!--<dependency>-->
            <!--<groupId>org.hsqldb</groupId>-->
            <!--<artifactId>hsqldb</artifactId>-->
            <!--<scope>runtime</scope>-->
        <!--</dependency>-->
        <dependency>
            <groupId>com.google.appengine</groupId>
            <artifactId>appengine-api-labs</artifactId>
            <version>${gae.version}</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>com.google.appengine</groupId>
            <artifactId>appengine-api-stubs</artifactId>
            <version>${gae.version}</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>com.google.appengine</groupId>
            <artifactId>appengine-testing</artifactId>
            <version>${gae.version}</version>
            <scope>test</scope>
        </dependency>
        <!-- DataNucleus -->
        <dependency>
            <groupId>org.datanucleus</groupId>
            <artifactId>datanucleus-api-jpa</artifactId>
            <version>${datanucleus.jpa.version}</version>
        </dependency>
        <dependency>
            <groupId>org.datanucleus</groupId>
            <artifactId>datanucleus-core</artifactId>
            <version>${datanucleus.jpa.version}</version>
        </dependency>
        <dependency>
            <groupId>org.datanucleus</groupId>
            <artifactId>datanucleus-enhancer</artifactId>
            <version>${datanucleus.jpa.version}</version>
        </dependency>
        <dependency>
            <groupId>com.google.appengine.orm</groupId>
            <artifactId>datanucleus-appengine</artifactId>
            <version>${datanucleus.version}</version>
            <!-- Need to exclude the enhancer since it interfere with the enhancer plugin. -->
            <exclusions>
                <exclusion>
                    <groupId>org.datanucleus</groupId>
                    <artifactId>datanucleus-enhancer</artifactId>
                </exclusion>
            </exclusions>
        </dependency>
        <dependency>
            <groupId>javax.jdo</groupId>
            <artifactId>jdo-api</artifactId>
            <version>3.0.1</version>
        </dependency>
        <dependency>
            <groupId>org.apache.geronimo.specs</groupId>
            <artifactId>geronimo-jpa_2.0_spec</artifactId>
            <version>1.1</version>
        </dependency>

        <!-- OpenJPA -->
        <dependency>
            <groupId>org.apache.openjpa</groupId>
            <artifactId>openjpa-persistence</artifactId>
            <version>2.3.0</version>
        </dependency>


    </dependencies>

    <properties>
        <start-class>demo.Application</start-class>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
        <java.version>1.7</java.version>
        <m2eclipse.wtp.contextRoot>/</m2eclipse.wtp.contextRoot>
        <datanucleus.jpa.version>3.1.1</datanucleus.jpa.version>
        <datanucleus.version>2.1.2</datanucleus.version>
        <gae.version>1.8.8</gae.version>
        <gae.home>${settings.localRepository}/com/google/appengine/appengine-java-sdk/${gae.version}/appengine-java-sdk/appengine-java-sdk-${gae.version}</gae.home>
        <gae.application.version>test</gae.application.version>
        <!--<org.springframework-version>4.0.5.RELEASE</org.springframework-version>-->
    </properties>

    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
            <!--
            <plugin>
                <groupId>net.kindleit</groupId>
                <artifactId>maven-gae-plugin</artifactId>
                <version>0.9.6</version>
                <dependencies>
                    <dependency>
                        <groupId>net.kindleit</groupId>
                        <artifactId>gae-runtime</artifactId>
                        <version>${gae.version}</version>
                        <type>pom</type>
                    </dependency>
                </dependencies>
            </plugin>
            -->
            <plugin>
                <groupId>com.google.appengine</groupId>
                <artifactId>appengine-maven-plugin</artifactId>
                <version>${gae.version}</version>
                <configuration>
                    <enableJarClasses>false</enableJarClasses>
                </configuration>
            </plugin>
            <plugin>
                <artifactId>maven-release-plugin</artifactId>
                <configuration>
                    <goals>gae:deploy</goals>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.tomcat.maven</groupId>
                <artifactId>tomcat6-maven-plugin</artifactId>
                <version>2.0</version>
                <configuration>
                    <path>/</path>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.datanucleus</groupId>
                <artifactId>maven-datanucleus-plugin</artifactId>
                <version>${datanucleus.jpa.version}</version>
                <configuration>
                    <api>JPA</api>
                    <!--<mappingIncludes>**/entity/*.class</mappingIncludes>-->
                    <verbose>true</verbose>
                </configuration>
                <dependencies>
                    <dependency>
                        <groupId>org.datanucleus</groupId>
                        <artifactId>datanucleus-core</artifactId>
                        <version>${datanucleus.jpa.version}</version>
                    </dependency>
                </dependencies>
                <executions>
                    <execution>
                        <phase>compile</phase>
                        <goals>
                            <goal>enhance</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>

    <profiles>
        <!-- We can configure our integration server to activate this profile and 
            perform gae:deploy, thus uploading latest snapshot to the http://1.latest.<applicationName>.appspot.com 
            automatically -->
        <profile>
            <id>integration-build</id>
            <properties>
                <gae.application.version>stage</gae.application.version>
            </properties>
        </profile>

        <!-- This profile will activate automatically during release and upload 
            application to the http://2.latest.<applicationName>.appspot.com (We might 
            want to set the 2nd version as our applications Default version to be accessible 
            at http://<applicationName>.appspot.com) -->
        <profile>
            <id>release-build</id>
            <activation>
                <property>
                    <name>performRelease</name>
                    <value>true</value>
                </property>
            </activation>

            <properties>
                <!-- During release, set application version in appengine-web.xml to 
                    2 -->
                <gae.application.version>release</gae.application.version>
            </properties>
        </profile>
    </profiles>

    <repositories>
        <repository>
            <id>spring-snapshots</id>
            <name>Spring Snapshots</name>
            <url>http://repo.spring.io/snapshot</url>
            <snapshots>
                <enabled>true</enabled>
            </snapshots>
        </repository>
        <repository>
            <id>spring-milestones</id>
            <name>Spring Milestones</name>
            <url>http://repo.spring.io/milestone</url>
            <snapshots>
                <enabled>false</enabled>
            </snapshots>
        </repository>
    </repositories>
    <pluginRepositories>
        <pluginRepository>
            <id>spring-snapshots</id>
            <name>Spring Snapshots</name>
            <url>http://repo.spring.io/snapshot</url>
            <snapshots>
                <enabled>true</enabled>
            </snapshots>
        </pluginRepository>
        <pluginRepository>
            <id>spring-milestones</id>
            <name>Spring Milestones</name>
            <url>http://repo.spring.io/milestone</url>
            <snapshots>
                <enabled>false</enabled>
            </snapshots>
        </pluginRepository>
    </pluginRepositories>

</project>

我想知道我的应用程序中可能缺少什么?我按照Using Spring Data JPA on Google Appengine

的说明进行操作

33 个答案:

答案 0 :(得分:154)

您还没有为Spring Boot提供足够的信息来自动配置DataSource。为此,您需要使用application.properties前缀向spring.datasource添加一些属性。查看DataSourceProperties以查看您可以设置的所有属性。

您需要提供相应的网址和驱动程序类名称:

spring.datasource.url = …
spring.datasource.driver-class-name = …

答案 1 :(得分:107)

如果要使用Spring Boot的嵌入式H2数据库,请将以下依赖项添加到您的pom文件中。

    <dependency>
        <groupId>com.h2database</groupId>
        <artifactId>h2</artifactId>
        <version>1.3.156</version>
    </dependency>

但正如评论中所提到的,嵌入式H2数据库将数据保存在内存中,并且不会永久存储它。

答案 2 :(得分:79)

我遇到了同样的问题并且排除了DataSourceAutoConfiguration解决了这个问题。

@SpringBootApplication
@EnableAutoConfiguration(exclude={DataSourceAutoConfiguration.class})
public class RecommendationEngineWithCassandraApplication {

    public static void main(String[] args) {
        SpringApplication.run(RecommendationEngineWithCassandraApplication.class, args);
    }
}

答案 3 :(得分:58)

这对我有用(1.3.0.M5):

<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    xmlns:fresco="http://schemas.android.com/apk/res-auto"
    android:fitsSystemWindows="true"
    android:background="@color/app_bg_color"
    tools:context=".ProfileActivity">

    <android.support.design.widget.AppBarLayout
        android:id="@+id/app_bar"
        android:fitsSystemWindows="true"
        android:layout_height="wrap_content"
        android:layout_width="match_parent"
        android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">

        <android.support.design.widget.CollapsingToolbarLayout
            android:id="@+id/toolbar_layout"
            android:fitsSystemWindows="true"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            app:layout_scrollFlags="scroll|exitUntilCollapsed"
            app:contentScrim="?attr/colorPrimary">

            <com.facebook.drawee.view.SimpleDraweeView
                android:id="@+id/profile_photo"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
           app:layout_scrollFlags="scroll|enterAlways|enterAlwaysCollapsed"
                app:layout_collapseMode="parallax"
                fresco:overlayImage="@drawable/grid_item_bg"
                android:fitsSystemWindows="true" />
        <android.support.v7.widget.Toolbar
            android:id="@+id/toolbar"
            android:layout_height="?attr/actionBarSize"
            android:layout_width="match_parent"
            app:layout_collapseMode="pin"
            app:popupTheme="@style/ThemeOverlay.AppCompat.Light">

            <ImageView
                android:id="@+id/profile_photo_small"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:src="@drawable/noimage"/>

        </android.support.v7.widget.Toolbar>
    </android.support.design.widget.CollapsingToolbarLayout>
</android.support.design.widget.AppBarLayout>

<android.support.v4.widget.NestedScrollView
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    app:layout_behavior="@string/appbar_scrolling_view_behavior"
    tools:showIn="@layout/activity_scrolling"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_margin="16dp"
        android:text="@string/large_text"
        android:textColor="@color/menu_text_color"/>

</android.support.v4.widget.NestedScrollView>

排除这两个类。

它不适用于

import org.springframework.boot.autoconfigure.jdbc.*;
import org.springframework.boot.autoconfigure.orm.jpa.*;

@Configuration
@EnableAutoConfiguration(exclude = {DataSourceAutoConfiguration.class, HibernateJpaAutoConfiguration.class})
public class Application {

答案 4 :(得分:22)

您可以添加

spring.autoconfigure.exclude=org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration   

到您的application.properties文件。

答案 5 :(得分:19)

现在我仔细观察,我认为DataSource问题是一个红鲱鱼。正在触发Boot的Hibernate自动配置,这就是导致需要DataSource的原因。 Hibernate位于类路径上,因为你依赖spring-boot-starter-data-jpa引入hibernate-entitymanager

更新您的spring-boot-starter-data-jpa依赖项以排除Hibernate:

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-data-jpa</artifactId>
    <exclusions>
        <exclusion>
            <groupId>org.hibernate</groupId>
            <artifactId>hibernate-entitymanager</artifactId>
        </exclusion>
    </exclusions>
</dependency>

答案 6 :(得分:14)

来自Spring manual

  

Spring Boot可以自动配置嵌入式H2,HSQL和Derby数据库。您不需要提供任何连接URL,只需包含对要使用的嵌入式数据库的构建依赖关系。

     

例如,典型的POM依赖关系是:

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
    <groupId>org.hsqldb</groupId>
    <artifactId>hsqldb</artifactId>
    <scope>runtime</scope>
</dependency>

让我省略spring-boot-starter-data-jpa依赖,只使用spring-boot-starter-jdbc依赖就像魅力一样,只要我把h2(或hsqldb)包含为依赖。< / p>

答案 7 :(得分:9)

Spring boot将在application.properties文件中查找datasoure属性。

请在application.properties或yml文件中定义

<强> application.properties

spring.datasource.url=xxx
spring.datasource.username=xxx
spring.datasource.password=xxx
spring.datasource.driver-class-name=xxx

如果您需要自己的配置,可以在创建bean时设置自己的配置文件并使用数据源值。

答案 8 :(得分:7)

如果为时已晚,无法回答。 我可以通过从spring boot中排除DataSourceAutoConfiguration来解决这个问题。

答案 9 :(得分:3)

我和org.springframework.data的groupId有两个依赖关系,然后我删除了jpa并且只保留了mongodb,它运行了!

<dependency>
    <groupId>org.springframework.data</groupId>
    <artifactId>spring-data-mongodb</artifactId>
</dependency>
<dependency>
    <groupId>org.springframework.data</groupId>
    <artifactId>spring-data-jpa</artifactId>
</dependency>

答案 10 :(得分:3)

我在使用Spring Data为ElasticSearch做API时遇到了这个异常。我做了以下工作并且有效。

@SpringDataApplication(exclude = {DataSourceAutoConfiguration.class, HibernateJpaAutoConfiguration.class})

答案 11 :(得分:2)

我解决了我的问题,只需添加 @AutoConfigureTestDatabase(replace = Replace.NONE)

SHOW ENGINE INNODB STATUS

答案 12 :(得分:2)

我在o.s.b.d.LoggingFailureAnalysisReporter的标题中收到了错误消息以及消息&#34; APPLICATION FAILED TO START&#34;。事实证明我没有将-Dspring.profiles.active=dev添加到我的Eclipse调试配置中,所以我没有活动的配置文件。

答案 13 :(得分:2)

我也遇到了同样的问题。

Cannot determine embedded database driver class for database type NONE.

在我的情况下,从对应于数据库的存储库中删除jar文件可以解决问题。存储库中存在损坏的jar,导致问题。

答案 14 :(得分:1)

由于这是谷歌针对此错误返回的第一个主题之一,我会发布我所做的事情以防有人面临同样的问题。 我不想排除DataSourceAutoConfiguration也不使用内存数据库..

在我的情况下,我设置参数,因为其他回复者说,但application.properties文件在错误的文件夹中.. lol

因此,如果没有这样的工作,请检查文件是否在src/main/resources内!就我而言,它位于src/main/resources/static

答案 15 :(得分:1)

使用以下依赖项。

<dependency>
   <groupId>com.h2database</groupId>
   <artifactId>h2</artifactId>
   <scope>runtime</scope>
</dependency>

答案 16 :(得分:1)

在我的情况下,使用IDEA,移除 out 后,一切都会恢复正常。我只是不知道为什么,但是效果很好。

答案 17 :(得分:1)

如果您的应用程序中没有任何数据库,只需在下面添加注释即可禁用数据源的自动配置。

@SpringBootApplication(exclude={DataSourceAutoConfiguration.class})

答案 18 :(得分:1)

我尝试了上面提到的所有内容,但无法解决问题。我正在使用SQLite,我的SQLite文件位于资源目​​录中。

a)为IDE设置完成

我需要在项目的.classpath文件中手动添加以下行。

<classpathentry kind="src" path="resources"/>
<classpathentry kind="output" path="target/classes"/>

之后,我从顶部的MenuBar刷新并清理了该项目。例如Project-&gt; Clean-&gt; My Project Name。

之后,我运行项目并解决了问题。

我项目的

application.properties

spring.datasource.url=jdbc:sqlite:resources/apiusers.sqlite
spring.datasource.driver-class-name=org.sqlite.JDBC
spring.jpa.properties.hibernate.dialect=com.enigmabridge.hibernate.dialect.SQLiteDialect
spring.datasource.username=
spring.datasource.password=
spring.jpa.hibernate.ddl-auto=update

b)如果Jar部署抛出相同的错误,则设置完成

您需要在pom.xml中添加以下行

  <build>
        <resources>
        <resource>
            <directory>resources</directory>
            <targetPath>${project.build.outputDirectory}</targetPath>
            <includes>
                <include>application.properties</include>
            </includes>
        </resource>
    </resources>
</build>

可能对某人有所帮助。

答案 19 :(得分:1)

如果您确实需要“spring-boot-starter-data-jpa”作为项目依赖项,同时您不希望允许您的应用访问任何数据库,则可以简单地排除自动配置类< / p>

@SpringBootApplication(exclude = DataSourceAutoConfiguration.class)

答案 20 :(得分:1)

在我的情况下,我在我的pom中为org.jasig.cas设置了一个maven依赖项,它触发了一个hibernate依赖项,并导致Spring Boot寻找一个数据源来自动配置hibernate持久性。 我通过添加user672009建议的com.h2database maven依赖项来解决它。谢谢你们!

答案 21 :(得分:1)

答案非常简单,SpringBoot将寻找嵌入式数据库驱动程序,如果您没有以XML或Annotations的形式配置任何配置,它将抛出此异常。 像这样在注释中进行更改

@EnableAutoConfiguration(exclude=DataSourceAutoConfiguration.class)
这将排除DataSourceAutoConfiguration。 如果您正确配置了课程,那么完美简单编码完成将会起作用。

    @Controller
    @EnableAutoConfiguration(exclude=DataSourceAutoConfiguration.class)
     public class SimpleController {
      @RequestMapping("/")
      @ResponseBody
       String home() {
        return "Hello World!";
       }public static void main(String[] args) throws Exception {
        SpringApplication.run(SimpleController.class, args);
       }
    }

答案 22 :(得分:1)

以下工作原理。

@EnableAutoConfiguration(exclude={DataSourceAutoConfiguration.class})

但如果我想拥有dataSource,我不应该进行上述配置。 下面的链接说我们需要application.properties文件中的所有属性。所有的属性应该从一开始 spring.datasource.*

http://docs.spring.io/spring-boot/docs/current/reference/html/common-application-properties.html

答案 23 :(得分:0)

任何人在几个小时的头撞墙后来到这个线程。我通过更改

解决了这个错误
create table `group`(
    id char(19) primary key
);

create table if not exists `group`(
    id char(19) primary key
);

在资源目录的schema.sql文件中。

答案 24 :(得分:0)

如果您使用的是Gradle,请输入正确的jar驱动程序,如下所示:

compile("org.mongodb:mongo-java-driver:3.3.0")

或者如果使用Maven然后以Maven风格进行,它应该可以解决您的问题。

答案 25 :(得分:0)

您可以从Maven Repository下载derby-10.10.1.1.jar并将其放在WEB-INF / lib文件夹中,例如Application / WEB-INF / lib / derby-10.10.1.1.jar 。 您的嵌入式AnnotationConfigEmbeddedWebApplicationContext将拾取数据库驱动程序,您的网络服务器将开始运行而不会出现任何问题: - )

答案 26 :(得分:0)

与@Anas相同。我可以在Eclipse中运行它,但是当我使用“java -jar ...”运行它时,它会给我这个错误。然后我发现我的java构建路径错误,它缺少文件夹“src / main / resources”,因此,应用程序找不到application.properties。当我在java构建路径中添加“src / main / resources”文件夹时,它可以工作。

并且,您需要在Application类中添加“@PropertySource({”application.properties“})”。

Screenshot-1

Screenshot-2

答案 27 :(得分:0)

右键单击该项目,然后选择以下选项Maven - &gt;更新项目。这解决了我的问题。

答案 28 :(得分:0)

通常,当您使用JPA并忘记添加数据库连接时会发生此类错误。因此,您必须在应用程序中添加与数据库相关的依赖项。

但是,您希望在不连接任何外部数据库的情况下使用JPA,然后在依赖项中添加hsqldb。

我希望这有帮助!

答案 29 :(得分:0)

这就是我解决这个问题的方法。

在我的情况下:我必须为MySQL服务器配置数据源,这是一个外部服务器。

众所周知,Spring引导能够为嵌入式数据库自动配置DataSource。

因此,我意识到我必须禁用数据源自动配置才能使用我的自定义配置。

如上所述,我在application.properties

中禁用了Spring Boot的自动数据源配置
  

spring.autoconfigure.exclude = org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration

我在一个单独的文件中定义了所有hibernate配置属性: hibernate-mysql.properties

然后,我按照以下方式编写了自己的自定义Hibernate配置,并解决了这个问题。

我根据自定义属性文件中的属性配置所需的DataSource,并使用您的数据源和其他hibernate配置填充LocalSessionFactoryBean。

Hibernate自定义配置类: -
----------------------------------------------- ----------

Hibernate Custom Configuration

答案 30 :(得分:0)

删除C:\Users\admin\.IntelliJIdea2018.1\system\compile-server

答案 31 :(得分:0)

我遇到了类似的问题,但排除了DataSourceAutoConfiguration和HibernateJpaAutoConfiguration解决了该问题。

我已经在application.properties文件中添加了这两行,并且可以正常工作。

> spring.autoconfigure.exclude[0]=org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration
> spring.autoconfigure.exclude[1]=org.springframework.boot.autoconfigure.orm.jpa.HibernateJpaAutoConfiguration

答案 32 :(得分:0)

已经发布了足够的答案。但是,我要发布我犯了什么错误以及如何纠正它。

就我而言,我将项目打包为pom而不是jar

pom.xml:

...
 <packaging>pom</packaging>
...

更改为:

...
 <packaging>jar</packaging>
...

这可能会对犯同样错误的人有所帮助。