Spring Boot – 无法确定数据库types为NONE的embedded式数据库驱动程序类
这是尝试运行我的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)
我相信我有正确的datanucleus-appengine
和datanucleus
jar组合:
2.1:需要DataNucleus 3.1.x(core,api-jdo,api-jpa,enhancer)。 需要SDK 1.6.4+请注意DataNucleus项目不再支持Datanucleus的这个版本
JPA应用程序configuration:
@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>
我不知道我的应用程序可能会丢失什么? 我遵循在这里使用Google Appengine上的Spring Data JPA的指令
您没有提供足够的信息来自动configurationDataSource
Spring Boot。 为此,您需要使用spring.datasource
前缀将一些属性添加到application.properties
。 看看DataSourceProperties看看你可以设置的所有属性。
您需要提供适当的url和驱动程序类名称:
spring.datasource.url = … spring.datasource.driver-class-name = …
我通过添加以下内容到我的pom文件来解决这个问题。
<dependency> <groupId>com.h2database</groupId> <artifactId>h2</artifactId> <version>1.3.156</version> </dependency>
我想同样的问题,排除DataSourceAutoConfiguration解决了这个问题。
@SpringBootApplication @EnableAutoConfiguration(exclude={DataSourceAutoConfiguration.class}) public class RecommendationEngineWithCassandraApplication { public static void main(String[] args) { SpringApplication.run(RecommendationEngineWithCassandraApplication.class, args); } }
这对我有用(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})
现在我仔细观察,我认为DataSource问题是一个红鲱鱼。 Boot的Hibernate自动configuration正在被触发,这就是导致需要DataSource的原因。 Hibernate的类path,因为你有依赖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>
从春季手册 。
Spring Boot可以自动configurationembedded式H2,HSQL和Derby数据库。 您不需要提供任何连接URL,只需将构build依赖项包含到要使用的embedded式数据库中即可。
例如,典型的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>
对于我而言,只要将h2(或hsqldb)作为依赖关系包含在spring-boot-starter-data-jpa依赖项中,并使用spring-boot-starter-jdbc依赖项就像一个魅力一样工作。
如果回答太晚,我不会。 我可以通过从弹簧引导中排除DataSourceAutoConfiguration来解决这个问题。
Spring启动将在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
如果你需要自己的configuration,你可以设置你自己的configuration文件,并在创buildbean时使用数据源值。
你可以添加spring.autoconfigure.exclude=org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration
到你的属性文件
我有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>
做下面的工作。
@EnableAutoConfiguration(exclude={DataSourceAutoConfiguration.class})
但是,如果我想有dataSource,我不应该做上面的configuration。 下面的链接说我们需要在application.properties文件中的所有属性。 所有的属性应该从spring.datasource.*
开始spring.datasource.*
http://docs.spring.io/spring-boot/docs/current/reference/html/common-application-properties.html
我在使用Spring Data为ElasticSearch执行API时遇到了这个exception。 我做了以下,它的工作。
@SpringDataApplication(exclude = {DataSourceAutoConfiguration.class, HibernateJpaAutoConfiguration.class})
我从osbdLoggingFailureAnalysisReporter
的标题中收到了错误消息,并显示“应用程序失败开始”消息。 事实certificate,我没有添加-Dspring.profiles.active=dev
到我的Eclipsedebuggingconfiguration,所以我没有活动configuration文件。
我也面临同样的问题。
Cannot determine embedded database driver class for database type NONE.
在我的情况下删除从数据库相应的数据库中的jar文件修复了问题。 存在导致问题的存储库中存在损坏的jar。
在我的情况下,我把它放在我的pom中的org.jasig.cas的maven依赖项,它触发了一个hibernate的依赖,并导致Spring Boot寻找一个数据源来自动configurationhibernate的持久性。 我通过添加user672009build议的com.h2database maven dependency来解决这个问题。 多谢你们!
由于这是在谷歌返回这个错误的第一个主题之一,我会发布我所做的情况下,有人面临同样的问题..我不想排除DataSourceAutoConfiguration
既不使用内存数据库..
在我的情况下,我设置的参数为其他repliers说,但application.properties
文件是在错误的文件夹内..大声笑
所以如果没有这样的工作,检查文件是否在src/main/resources
! 在我的情况是在src/main/resources/static
答案很简单,SpringBoot将查找Embeddable数据库驱动程序,如果您没有以XML或注解formsconfiguration您的任何configuration,则会抛出此exception。 像这样在注释中进行更改
@EnableAutoConfiguration(exclude=DataSourceAutoConfiguration.class)
这将排除DataSourceAutoConfiguration。 完美的简单编码完成将是工作,如果你有适当的configuration你的课堂。
@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);
}
}
我解决我的问题只是添加@AutoConfigureTestDatabase(replace= Replace.NONE)
@RunWith(SpringRunner.class) @DataJpaTest @AutoConfigureTestDatabase(replace=Replace.NONE) public class TestClienteRepository { }
您可以从Maven Repository下载derby-10.10.1.1.jar,并将其放在您的WEB-INF / lib文件夹中,就像这个Application / WEB-INF / lib / derby-10.10.1.1.jar一样。 您的embedded式AnnotationConfigEmbeddedWebApplicationContext将获取数据库驱动程序,您的Web服务器将开始运行,而不会有任何问题:-)
如果您使用的是Gradle,请包含如下的驱动程序jar:
compile("org.mongodb:mongo-java-driver:3.3.0")
或者,如果使用Maven,那么使用Maven风格,它应该可以解决你的问题。
几个小时后,你的头靠在墙上,对任何人来到这个线程。 我通过更改解决了这个错误
create table `group`( id char(19) primary key );
至
create table if not exists `group`( id char(19) primary key );
在资源目录中的我的schema.sql文件中。
如果您确实需要“spring-boot-starter-data-jpa”作为您的项目依赖项,并且同时您不希望允许您的应用程序访问任何数据库,则可以简单地排除自动configuration类
@SpringBootApplication(exclude = DataSourceAutoConfiguration.class)
即使在application.properties中提供了所有必需的数据源属性之后,我仍面临着这个问题。 然后我意识到,属性configuration类没有得到由Spring启动扫描,因为它是在不同的包层次结构相比,我的Spring引导Application.java,因此没有属性被应用到数据源对象。 我改变了我的属性configuration类的包名称,并开始工作。 https://stackoverflow.com/a/42368525/7598936