Spring引导——无法确定数据库类型的嵌入式数据库驱动程序类。

时间:2022-09-11 16:27:43

This is the error that is thrown when trying to run my web app:

这是运行我的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)

I believe I have the right combination of datanucleus-appengine and datanucleus jars:

我相信我有正确的数据核应用程序引擎和数据核罐子的组合:

2.1: Requires DataNucleus 3.1.x (core, api-jdo, api-jpa, enhancer). Requires SDK 1.6.4+ Note that this release of Datanucleus is no longer supported by the DataNucleus project

2.1:需要DataNucleus 3.1。x (core, api-jdo, api-jpa,增强器)。需要SDK 1.6.4+注意,这个数据核版本不再支持数据核项目

JPA App Config:

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

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:

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>

I wonder what could be missing in my app? I followed the instruction from here Using Spring Data JPA on Google Appengine

我想知道我的应用程序中可能缺少什么?我使用谷歌Appengine上的Spring Data JPA遵循了这里的指令

28 个解决方案

#1


131  

You haven't provided Spring Boot with enough information to auto-configure a DataSource. To do so, you'll need to add some properties to application.properties with the spring.datasource prefix. Take a look at DataSourceProperties to see all of the properties that you can set.

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

You'll need to provide the appropriate url and driver class name:

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

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

#2


95  

I solved this by adding the following to my pom file.

我通过在pom文件中添加以下内容来解决这个问题。

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

#3


69  

I'd the same problem and excluding the DataSourceAutoConfiguration solved the problem.

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

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

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

#4


54  

This worked for me (1.3.0.M5) :

这对我有效(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 {

Exclude both classes.

排除两类。

It did not work with

它不起作用

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

#5


16  

Now that I look closer, I think that the DataSource problem is a red-herring. Boot's Hibernate auto-configuration is being triggered and that's what causing a DataSource to be required. Hibernate's on the classpath because you've got a dependency on spring-boot-starter-data-jpa which pulls in hibernate-entitymanager.

现在我仔细看了一下,我认为数据源问题是一个转移注意力的问题。启动的Hibernate自动配置正在被触发,这就是导致需要数据源的原因。Hibernate之所以出现在类路径中,是因为您依赖于spring-boot-starter-data-jpa,它引入Hibernate -entitymanager。

Update your spring-boot-starter-data-jpa dependency to exclude Hibernate:

更新您的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  

From the Spring manual.

春天的手册。

Spring Boot can auto-configure embedded H2, HSQL, and Derby databases. You don’t need to provide any connection URLs, simply include a build dependency to the embedded database that you want to use.

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

For example, typical POM dependencies would be:

例如,典型的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>

For me leaving out the spring-boot-starter-data-jpa dependency and just using the spring-boot-starter-jdbc dependency worked like a charm, as long as I had h2 (or hsqldb) included as dependencies.

对于我来说,省去了spring-boot-starter-data-jpa依赖项,而只使用spring-boot-starter-jdbc依赖项,只要我将h2(或hsqldb)包含为依赖项,它就会像一种魅力。

#7


12  

You can add

您可以添加

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

to your application.properties file.

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

#8


6  

I don't if it is too late to answer. I could solve this issue by excluding DataSourceAutoConfiguration from spring boot.

如果太晚的话,我不会回答。我可以通过从spring boot中排除DataSourceAutoConfiguration来解决这个问题。

#9


6  

Spring boot will look for datasoure properties in application.properties file.

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

Please define it in application.properties or yml file

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

application.properties

application.properties

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

If you need your own configuration you could set your own profile and use the datasource values while bean creation.

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

#10


3  

I faced this exception while I was doing APIs for ElasticSearch using Spring Data. I did the following and it worked.

当我在使用Spring数据做弹性搜索api时,遇到了这个异常。我做了下面的事情,它成功了。

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

#11


2  

I solve my problem just adding @AutoConfigureTestDatabase(replace=Replace.NONE)

我只需添加@AutoConfigureTestDatabase(replace=Replace.NONE)就能解决问题。

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

}

#12


2  

I had two dependencies with groupId of org.springframework.data, then I removed jpa and kept mongodb only , and it worked!

我对org.springframework有两个依赖项。数据,然后我删除了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>

#13


2  

I got the error message in the title from o.s.b.d.LoggingFailureAnalysisReporter along with the message "APPLICATION FAILED TO START". It turned out that I hadn't added -Dspring.profiles.active=dev to my Eclipse debug configuration so I had no active profile.

我从o.s.b.d那里得到了标题中的错误信息。LoggingFailureAnalysisReporter,还有“应用程序启动失败”的消息。原来我没有添加-Dspring.profiles。活动=dev到我的Eclipse调试配置,因此我没有活动概要文件。

#14


2  

I too faced the same issue.

我也面临同样的问题。

Cannot determine embedded database driver class for database type NONE.

In my case deleting the jar file from repository corresponding to the database fixes the issue. There was corrupted jar present in the repository which was causing the issue.

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

#15


1  

In my case , I put it a maven dependency for org.jasig.cas in my pom that triggered a hibernate dependency and that caused Spring Boot to look for a datasource to auto-configure hibernate persistence. I solved it by adding the com.h2database maven dependency as suggested by user672009. Thanks guys!

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

#16


1  

As this is one of the first topics returned in google for this error, I'll post what I did in case someone face the same issue.. I didn't want to exclude DataSourceAutoConfiguration neither use a memory database..

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

In my case I was setting the parameters as the other repliers said but the application.properties file was inside the wrong folder.. lol

在我的例子中,我是按照其他repliers所说的设置参数的,但是应用程序是这样的。属性文件在错误的文件夹中。哈哈

So in case nothing like this works, check if the file is inside src/main/resources! In my case it was inside src/main/resources/static

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

#17


1  

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

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

@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);
       }
    }

#18


1  

Doing below works.

做下面的工作。

@EnableAutoConfiguration(exclude={DataSourceAutoConfiguration.class})

But If I wanted to have dataSource, I should not do the above configuration. The below link says that we need to all the properties in application.properties file. All the properties should start with spring.datasource.*

但是如果我想要数据源,我不应该做上面的配置。下面的链接表示我们需要应用程序中的所有属性。属性文件。所有属性都应该从spring.datasource.*开始

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

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

#19


1  

If you really need "spring-boot-starter-data-jpa" as your project dependency and at the same time you don't want to allow your app to access any database, you can simply exclude auto-configuration classes

如果您确实需要“spring-boot-starter-data-jpa”作为项目依赖项,同时又不想让应用程序访问任何数据库,那么您只需排除自动配置类

@SpringBootApplication(exclude = DataSourceAutoConfiguration.class)

#20


1  

I tried all the mentioned things above but could not resolve the issue. I am using SQLite and my SQLite file was in the resources directory.

我尝试了上面提到的所有事情,但是没有解决问题。我使用的是SQLite,我的SQLite文件在参考资料目录中。

a) Set Up done for IDE

a)为IDE设置。

I need to manually add below lines in the .classpath file of my project.

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

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

After that, I refreshed and Cleaned the project from MenuBar at the top. like Project->Clean->My Project Name.

之后,我从顶部的MenuBar刷新并清理了项目。像项目- >清洁- >我的项目名称。

After that, I run the project and problem resolved.

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

application.properties for my project is

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

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) Set Up done if Jar deployment throw same error

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

You need to add following lines to your pom.xml

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

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

May be it may help someone.

也许它可以帮助某人。

#21


0  

You can download the derby-10.10.1.1.jar from the Maven Repository and place it in your WEB-INF/lib folder, like this Application/WEB-INF/lib/derby-10.10.1.1.jar. Your embedded AnnotationConfigEmbeddedWebApplicationContext will pickup the database driver and your webserver will start running without any issues :-)

您可以下载derby 10.10.1.1。从Maven存储库中提取jar并将其放入WEB-INF/lib文件夹,就像这个应用程序/WEB-INF/lib/derby- 10.1.1.1 .jar。您的嵌入式AnnotationConfigEmbeddedWebApplicationContext将接收数据库驱动程序,您的webserver将开始运行,没有任何问题:

#22


0  

If you are using Gradle, include right jar of driver as below:

如果您使用的是等级,请包括右车档如下:

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

Or if using Maven then do it in Maven style, it should solve your problem.

或者如果使用Maven,那么使用Maven样式,它应该可以解决您的问题。

#23


0  

To anybody coming to this thread after hours of banging your head against a wall. I solved this error by changing

对于任何一个连续几个小时把头靠在墙上的人来说。我通过改变来解决这个错误。

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

to

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

in my schema.sql file in the resources directory.

在我的模式。资源目录中的sql文件。

#24


0  

if you do not have any database in your application simply disable the auto-config of datasource by adding below annotation.

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

@SpringBootApplication(exclude={DataSourceAutoConfiguration.class})

#25


0  

The same to @Anas. I can run it in Eclipse, but when i use "java -jar ..." run it, it giving me this error. Then i find my java build path is wrong, it missing the folder “src/main/resources”, so, the application can't find application.properties. When i add the “src/main/resources” folder in java build path, it worked.

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

And, you need add "@PropertySource({"application.properties"})" in your Application class.

并且,您需要在您的应用程序类中添加“@PropertySource({”Application .properties”})。

Screenshot-1

Screenshot-1

Screenshot-2

Screenshot-2

#26


0  

Right click the project and select the following option Maven -> Update Project. This has solved my issue.

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

#27


0  

Generally, such error occurs when you've used JPA and forget to add database connection. So, you must add database related dependencies in your application.

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

Though, you want to use JPA without connecting any external database then add hsqldb in your dependency.

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

I hope this helps!

我希望这可以帮助!

#28


0  

This is how I resolved this problem.

我就是这样解决这个问题的。

In my case: I had to configure the datasource for MySQL Server, which was an external Server.

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

As we all know, Spring boot has capability to auto-configure DataSource for embedded databases.

众所周知,Spring boot可以为嵌入式数据库自动配置数据源。

Thus, I realized that I had to disable datasource auto-configuration in order use my custom configuration.

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

As mentioned above by many, I disabled Automatic DataSource configuration of Spring Boot at application.properties

正如前面提到的,我在application.properties上禁用了Spring Boot的自动数据源配置

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

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

I defined all hibernate configuration properties in a separate file: hibernate-mysql.properties

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

Then, I coded my own Custom Hibernate Configuration in following manner and it resolved the issue.

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

My way to configure the desired DataSource based on properties in a custom property file and populate your LocalSessionFactoryBean with your data source and other hibernate configuration.

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

Hibernate Custom Configuration Class:-
---------------------------------------------------------

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

Hibernate Custom Configuration

Hibernate自定义配置

#1


131  

You haven't provided Spring Boot with enough information to auto-configure a DataSource. To do so, you'll need to add some properties to application.properties with the spring.datasource prefix. Take a look at DataSourceProperties to see all of the properties that you can set.

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

You'll need to provide the appropriate url and driver class name:

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

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

#2


95  

I solved this by adding the following to my pom file.

我通过在pom文件中添加以下内容来解决这个问题。

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

#3


69  

I'd the same problem and excluding the DataSourceAutoConfiguration solved the problem.

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

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

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

#4


54  

This worked for me (1.3.0.M5) :

这对我有效(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 {

Exclude both classes.

排除两类。

It did not work with

它不起作用

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

#5


16  

Now that I look closer, I think that the DataSource problem is a red-herring. Boot's Hibernate auto-configuration is being triggered and that's what causing a DataSource to be required. Hibernate's on the classpath because you've got a dependency on spring-boot-starter-data-jpa which pulls in hibernate-entitymanager.

现在我仔细看了一下,我认为数据源问题是一个转移注意力的问题。启动的Hibernate自动配置正在被触发,这就是导致需要数据源的原因。Hibernate之所以出现在类路径中,是因为您依赖于spring-boot-starter-data-jpa,它引入Hibernate -entitymanager。

Update your spring-boot-starter-data-jpa dependency to exclude Hibernate:

更新您的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  

From the Spring manual.

春天的手册。

Spring Boot can auto-configure embedded H2, HSQL, and Derby databases. You don’t need to provide any connection URLs, simply include a build dependency to the embedded database that you want to use.

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

For example, typical POM dependencies would be:

例如,典型的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>

For me leaving out the spring-boot-starter-data-jpa dependency and just using the spring-boot-starter-jdbc dependency worked like a charm, as long as I had h2 (or hsqldb) included as dependencies.

对于我来说,省去了spring-boot-starter-data-jpa依赖项,而只使用spring-boot-starter-jdbc依赖项,只要我将h2(或hsqldb)包含为依赖项,它就会像一种魅力。

#7


12  

You can add

您可以添加

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

to your application.properties file.

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

#8


6  

I don't if it is too late to answer. I could solve this issue by excluding DataSourceAutoConfiguration from spring boot.

如果太晚的话,我不会回答。我可以通过从spring boot中排除DataSourceAutoConfiguration来解决这个问题。

#9


6  

Spring boot will look for datasoure properties in application.properties file.

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

Please define it in application.properties or yml file

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

application.properties

application.properties

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

If you need your own configuration you could set your own profile and use the datasource values while bean creation.

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

#10


3  

I faced this exception while I was doing APIs for ElasticSearch using Spring Data. I did the following and it worked.

当我在使用Spring数据做弹性搜索api时,遇到了这个异常。我做了下面的事情,它成功了。

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

#11


2  

I solve my problem just adding @AutoConfigureTestDatabase(replace=Replace.NONE)

我只需添加@AutoConfigureTestDatabase(replace=Replace.NONE)就能解决问题。

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

}

#12


2  

I had two dependencies with groupId of org.springframework.data, then I removed jpa and kept mongodb only , and it worked!

我对org.springframework有两个依赖项。数据,然后我删除了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>

#13


2  

I got the error message in the title from o.s.b.d.LoggingFailureAnalysisReporter along with the message "APPLICATION FAILED TO START". It turned out that I hadn't added -Dspring.profiles.active=dev to my Eclipse debug configuration so I had no active profile.

我从o.s.b.d那里得到了标题中的错误信息。LoggingFailureAnalysisReporter,还有“应用程序启动失败”的消息。原来我没有添加-Dspring.profiles。活动=dev到我的Eclipse调试配置,因此我没有活动概要文件。

#14


2  

I too faced the same issue.

我也面临同样的问题。

Cannot determine embedded database driver class for database type NONE.

In my case deleting the jar file from repository corresponding to the database fixes the issue. There was corrupted jar present in the repository which was causing the issue.

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

#15


1  

In my case , I put it a maven dependency for org.jasig.cas in my pom that triggered a hibernate dependency and that caused Spring Boot to look for a datasource to auto-configure hibernate persistence. I solved it by adding the com.h2database maven dependency as suggested by user672009. Thanks guys!

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

#16


1  

As this is one of the first topics returned in google for this error, I'll post what I did in case someone face the same issue.. I didn't want to exclude DataSourceAutoConfiguration neither use a memory database..

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

In my case I was setting the parameters as the other repliers said but the application.properties file was inside the wrong folder.. lol

在我的例子中,我是按照其他repliers所说的设置参数的,但是应用程序是这样的。属性文件在错误的文件夹中。哈哈

So in case nothing like this works, check if the file is inside src/main/resources! In my case it was inside src/main/resources/static

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

#17


1  

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

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

@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);
       }
    }

#18


1  

Doing below works.

做下面的工作。

@EnableAutoConfiguration(exclude={DataSourceAutoConfiguration.class})

But If I wanted to have dataSource, I should not do the above configuration. The below link says that we need to all the properties in application.properties file. All the properties should start with spring.datasource.*

但是如果我想要数据源,我不应该做上面的配置。下面的链接表示我们需要应用程序中的所有属性。属性文件。所有属性都应该从spring.datasource.*开始

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

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

#19


1  

If you really need "spring-boot-starter-data-jpa" as your project dependency and at the same time you don't want to allow your app to access any database, you can simply exclude auto-configuration classes

如果您确实需要“spring-boot-starter-data-jpa”作为项目依赖项,同时又不想让应用程序访问任何数据库,那么您只需排除自动配置类

@SpringBootApplication(exclude = DataSourceAutoConfiguration.class)

#20


1  

I tried all the mentioned things above but could not resolve the issue. I am using SQLite and my SQLite file was in the resources directory.

我尝试了上面提到的所有事情,但是没有解决问题。我使用的是SQLite,我的SQLite文件在参考资料目录中。

a) Set Up done for IDE

a)为IDE设置。

I need to manually add below lines in the .classpath file of my project.

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

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

After that, I refreshed and Cleaned the project from MenuBar at the top. like Project->Clean->My Project Name.

之后,我从顶部的MenuBar刷新并清理了项目。像项目- >清洁- >我的项目名称。

After that, I run the project and problem resolved.

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

application.properties for my project is

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

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) Set Up done if Jar deployment throw same error

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

You need to add following lines to your pom.xml

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

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

May be it may help someone.

也许它可以帮助某人。

#21


0  

You can download the derby-10.10.1.1.jar from the Maven Repository and place it in your WEB-INF/lib folder, like this Application/WEB-INF/lib/derby-10.10.1.1.jar. Your embedded AnnotationConfigEmbeddedWebApplicationContext will pickup the database driver and your webserver will start running without any issues :-)

您可以下载derby 10.10.1.1。从Maven存储库中提取jar并将其放入WEB-INF/lib文件夹,就像这个应用程序/WEB-INF/lib/derby- 10.1.1.1 .jar。您的嵌入式AnnotationConfigEmbeddedWebApplicationContext将接收数据库驱动程序,您的webserver将开始运行,没有任何问题:

#22


0  

If you are using Gradle, include right jar of driver as below:

如果您使用的是等级,请包括右车档如下:

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

Or if using Maven then do it in Maven style, it should solve your problem.

或者如果使用Maven,那么使用Maven样式,它应该可以解决您的问题。

#23


0  

To anybody coming to this thread after hours of banging your head against a wall. I solved this error by changing

对于任何一个连续几个小时把头靠在墙上的人来说。我通过改变来解决这个错误。

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

to

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

in my schema.sql file in the resources directory.

在我的模式。资源目录中的sql文件。

#24


0  

if you do not have any database in your application simply disable the auto-config of datasource by adding below annotation.

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

@SpringBootApplication(exclude={DataSourceAutoConfiguration.class})

#25


0  

The same to @Anas. I can run it in Eclipse, but when i use "java -jar ..." run it, it giving me this error. Then i find my java build path is wrong, it missing the folder “src/main/resources”, so, the application can't find application.properties. When i add the “src/main/resources” folder in java build path, it worked.

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

And, you need add "@PropertySource({"application.properties"})" in your Application class.

并且,您需要在您的应用程序类中添加“@PropertySource({”Application .properties”})。

Screenshot-1

Screenshot-1

Screenshot-2

Screenshot-2

#26


0  

Right click the project and select the following option Maven -> Update Project. This has solved my issue.

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

#27


0  

Generally, such error occurs when you've used JPA and forget to add database connection. So, you must add database related dependencies in your application.

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

Though, you want to use JPA without connecting any external database then add hsqldb in your dependency.

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

I hope this helps!

我希望这可以帮助!

#28


0  

This is how I resolved this problem.

我就是这样解决这个问题的。

In my case: I had to configure the datasource for MySQL Server, which was an external Server.

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

As we all know, Spring boot has capability to auto-configure DataSource for embedded databases.

众所周知,Spring boot可以为嵌入式数据库自动配置数据源。

Thus, I realized that I had to disable datasource auto-configuration in order use my custom configuration.

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

As mentioned above by many, I disabled Automatic DataSource configuration of Spring Boot at application.properties

正如前面提到的,我在application.properties上禁用了Spring Boot的自动数据源配置

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

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

I defined all hibernate configuration properties in a separate file: hibernate-mysql.properties

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

Then, I coded my own Custom Hibernate Configuration in following manner and it resolved the issue.

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

My way to configure the desired DataSource based on properties in a custom property file and populate your LocalSessionFactoryBean with your data source and other hibernate configuration.

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

Hibernate Custom Configuration Class:-
---------------------------------------------------------

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

Hibernate Custom Configuration

Hibernate自定义配置