2016-08-30 21 views
7

我想用Spring Boot 1.4.RELEASE在內存DB中創建測試。當我加入anotation @DataJpaTest到測試和執行測試我發現了以下錯誤:帶有註解的測試@DataJpaTest - EmbeddedDatabaseType是必需的

org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'org.springframework.boot.autoconfigure.orm.jpa.HibernateJpaAutoConfiguration': Unsatisfied dependency expressed through constructor parameter 0: Error creating bean with name 'dataSource': Invocation of init method failed; nested exception is java.lang.IllegalArgumentException: EmbeddedDatabaseType is required; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dataSource': Invocation of init method failed; nested exception is java.lang.IllegalArgumentException: EmbeddedDatabaseType is required 

我的春天引導屬性:

spring.jpa.database=ORACLE 
spring.jpa.show-sql=false 
spring.jpa.hibernate.ddl-auto=validate 

spring.datasource.driverClassName=oracle.jdbc.OracleDriver 
spring.datasource.url=.. 
spring.datasource.username=.. 
spring.datasource.password=.. 

spring.datasource.max-active=20 
spring.datasource.max-idle=5 
spring.datasource.min-idle=1 
spring.datasource.initial-size=5 


spring.datasource.testWhileIdle = true 
spring.datasource.timeBetweenEvictionRunsMillis = 20000 
#spring.datasource.test-on-borrow=true 
spring.datasource.validation-query=select 1 from dual; 

spring.jpa.properties.hibernate.order_inserts=true 
spring.jpa.properties.hibernate.order_updates=true 
spring.jpa.properties.hibernate.jdbc.batch_size=100 
spring.jpa.properties.hibernate.cache.use_second_level_cache=false 

依賴關係:

<dependency> 
    <groupId>org.springframework.boot</groupId> 
    <artifactId>spring-boot-starter-thymeleaf</artifactId> 
</dependency> 
<dependency> 
    <groupId>org.springframework.boot</groupId> 
    <artifactId>spring-boot-starter-tomcat</artifactId> 
    <scope>provided</scope> 
</dependency> 
<dependency> 
    <groupId>javax.el</groupId> 
    <artifactId>javax.el-api</artifactId> 
    <version>2.2.4</version> 
</dependency> 
<dependency> 
    <groupId>org.springframework.boot</groupId> 
    <artifactId>spring-boot-devtools</artifactId> 
    <optional>true</optional> 
</dependency> 
<dependency> 
    <groupId>org.springframework.boot</groupId> 
    <artifactId>spring-boot-starter-actuator</artifactId> 
</dependency> 
<dependency> 
    <groupId>org.springframework.boot</groupId> 
    <artifactId>spring-boot-starter-data-jpa</artifactId> 
</dependency> 
<dependency> 
    <groupId>org.springframework.boot</groupId> 
    <artifactId>spring-boot-starter-jdbc</artifactId> 
</dependency> 
<dependency> 
    <groupId>args4j</groupId> 
    <artifactId>args4j</artifactId> 
    <version>2.33</version> 
</dependency> 
<dependency> 
    <groupId>org.springframework.boot</groupId> 
    <artifactId>spring-boot-starter-remote-shell</artifactId> 
</dependency> 

<dependency> 
    <groupId>org.springframework.boot</groupId> 
    <artifactId>spring-boot-starter-test</artifactId> 
    <scope>test</scope> 
</dependency> 

<dependency> 
    <groupId>commons-lang</groupId> 
    <artifactId>commons-lang</artifactId> 
    <version>2.6</version> 
</dependency> 

<dependency> 
    <groupId>oracle</groupId> 
    <artifactId>ojdbc6</artifactId> 
    <version>11.2.0.3.0</version> 
</dependency> 

<dependency> 
    <groupId>com.netflix.hystrix</groupId> 
    <artifactId>hystrix-core</artifactId> 
    <version>1.4.18</version> 
</dependency> 
<dependency> 
    <groupId>org.perf4j</groupId> 
    <artifactId>perf4j</artifactId> 
    <version>0.9.16</version> 
</dependency> 
<dependency> 
    <groupId>io.reactivex</groupId> 
    <artifactId>rxjava</artifactId> 
    <version>1.0.13</version> 
</dependency> 
<dependency> 
    <groupId>org.springframework</groupId> 
    <artifactId>spring-jdbc</artifactId> 
    <version>4.2.3.RELEASE</version> 
</dependency> 

我預計這個註釋將替換我的真實數據庫與內存數據庫。

回答

6

解決在內存DB添加依賴關係:

徵求意見
<dependency> 
    <groupId>org.hsqldb</groupId> 
    <artifactId>hsqldb</artifactId> 
    <scope>test</scope> 
</dependency> 

編輯:

在additiona這個我不得不在測試中開啓休眠驗證。 新增

spring.jpa.hibernate.ddl-AUTO =創造降

測試/資源/ application.properties

+0

你不必做任何事情來得到它工作?我和你有同樣的問題,但是當我添加hsqldb依賴時,我得到關於'org.hsqldb.HsqlException:用戶缺少特權或對象未找到的錯誤:PG_CLASS' – snowe

+2

我有同樣的問題。我必須在測試中關閉hibernate驗證:在test/resources/application.properties中添加spring.jpa.hibernate.ddl-auto = create-drop – mrh