这是在试图运行我的web应用程序时抛出的错误:

[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)

我相信我有datannuclear -appengine和datanucleus jars的正确组合:

2.1:需要DataNucleus 3.1。X(核心,api-jdo, api-jpa,增强器)。需要SDK 1.6.4+注意,这个版本的Datanucleus不再 由DataNucleus项目支持

JPA应用程序配置:

@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>

我想知道在我的应用程序中会缺少什么?我遵循从这里使用Spring Data JPA在谷歌Appengine的说明


您还没有为Spring Boot提供足够的信息来自动配置数据源。为此,需要向应用程序添加一些属性。属性与弹簧。数据源前缀。查看DataSourceProperties以查看您可以设置的所有属性。

你需要提供适当的url和驱动程序类名:

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

现在我仔细看了一下,我认为DataSource问题是一个转移注意力的问题。引导的Hibernate自动配置被触发,这就是需要数据源的原因。Hibernate在类路径上,因为你依赖spring-boot-start -data-jpa,它会拉入Hibernate -entitymanager。

更新spring-boot-start -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>

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

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

但正如评论中提到的,嵌入式H2数据库将数据保存在内存中,而不是永久存储。


在我的例子中,我在pom中为org.jasig.cas放置了一个maven依赖项,该依赖项触发了hibernate依赖项,并导致Spring Boot寻找一个数据源来自动配置hibernate持久性。 我通过加上com来解决这个问题。由user672009建议的H2database maven依赖项。谢谢你们了!


来自Spring手册。

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)作为依赖项。


我不知道现在回答是否太晚。 我可以通过从spring引导中排除DataSourceAutoConfiguration来解决这个问题。


我也有同样的问题,排除DataSourceAutoConfiguration解决了这个问题。

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

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

做以下工作。

@EnableAutoConfiguration(exclude={DataSourceAutoConfiguration.class})

但是如果我想要dataSource,我不应该做上面的配置。 下面的链接说,我们需要在应用程序中的所有属性。属性文件。所有属性都应该以 spring.datasource。*

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


这对我有用(1.3.0.M5):

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

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

排除这两个类。

它没有工作

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

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

在我的情况下,我设置的参数是其他回复者说的,而不是应用程序。属性文件在错误的文件夹中。哈哈

因此,如果没有这样的工作,检查文件是否在src/main/resources!在我的例子中,它在src/main/resources/static中


Answer is very simple, SpringBoot will look for Embeddable database driver, If you didn't configure in any of your configuration in form of XML or Annotations, it will throws this exception. Make the changes in your annotation like this @EnableAutoConfiguration(exclude=DataSourceAutoConfiguration.class) this will exclude the DataSourceAutoConfiguration. And the Perfect Simple Coding completion would be work if you have properly configured your class. @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); } }


您可以从Maven资源库下载derby-10.10.1.1.jar,并将其放在WEB-INF/lib文件夹中,例如Application/WEB-INF/lib/derby-10.10.1.1.jar。 你嵌入的AnnotationConfigEmbeddedWebApplicationContext将拾取数据库驱动程序,你的web服务器将开始运行没有任何问题:-)


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

@RunWith(SpringRunner.class)
@DataJpaTest
@AutoConfigureTestDatabase(replace=Replace.NONE)
public class TestClienteRepository {

}

如果你正在使用Gradle,包括正确的驱动程序,如下所示:

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

或者如果使用Maven,那么按照Maven风格来做,它应该可以解决您的问题。


献给那些在几小时后把头撞到墙上后来到这个帖子的人。我通过改变解决了这个错误

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

to

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

在我的图式中。资源目录下的SQL文件。


我对org.springframework的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>

Spring引导将在应用程序中查找数据源属性。属性文件。

请在应用中定义它。属性或yml文件

application.properties

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

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


我在使用Spring Data为ElasticSearch做api时遇到了这个异常。我做了下面的事情,它奏效了。

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

我从o.s.b.d.LoggingFailureAnalysisReporter的标题中得到了错误消息,并附上了“应用程序未能启动”的消息。原来我没有添加-Dspring.profiles。active=dev到我的Eclipse调试配置,因此我没有活动配置文件。


你可以添加

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

到你的应用程序。属性文件。


我也面临着同样的问题。

Cannot determine embedded database driver class for database type NONE.

在我的例子中,从数据库对应的存储库中删除jar文件可以解决这个问题。储存库中存在损坏的jar,导致了该问题。


如果你真的需要“spring-boot-start -data-jpa”作为你的项目依赖项,同时你又不想让你的应用访问任何数据库,你可以简单地排除自动配置类

@SpringBootApplication(exclude = DataSourceAutoConfiguration.class)

我尝试了上面提到的所有方法,但都不能解决这个问题。我正在使用SQLite,我的SQLite文件在资源目录中。

a) IDE设置完成

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

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

之后,我从菜单栏的顶部刷新和清理项目。比如项目->清洁->我的项目名。

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

应用程序。属性为我的项目是

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>

也许它能帮助到某人。


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

@SpringBootApplication(exclude={DataSourceAutoConfiguration.class})

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

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

Screenshot-1

Screenshot-2


右键单击项目并选择以下选项Maven ->更新项目。这解决了我的问题。


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

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

我希望这能有所帮助!


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

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

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

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

如上所述,我在application.properties中禁用了Spring Boot的自动DataSource配置

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

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

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

我的方法是基于自定义属性文件中的属性配置所需的数据源,并用数据源和其他hibernate配置填充LocalSessionFactoryBean。

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

Hibernate自定义配置


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


在我的例子中,使用IDEA,删除out目录后,一切恢复正常。我也不知道为什么,但还是成功了。


使用下面的依赖项。

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

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

我在我的申请中添加了这两行。属性文件,它工作。

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

已经有足够多的答案被贴出来了。但是,我把我犯的错误和我是如何改正的贴出来。

在我的例子中,我将我的项目打包为pom而不是jar

pom.xml:

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

更改为:

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

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


我的应用程序文件没有被读取,Spring试图连接到一个嵌入式H2数据库(没有添加到pom中)。这将抛出以下错误消息:

如果要从特定配置文件加载数据库设置 您可能需要激活它(当前没有配置文件激活)。

通过下面的问题,确保您的应用程序文件正在被读取。


如果这些都不起作用,尝试创建一个Repository类以及RepositoryInterface, 虽然spring boot应该自动生成一个实现类, 这对我来说很管用。