当前位置: 首页 > 知识库问答 >
问题:

Spring Boot@DataJpaTest停留在hh000400:使用方言:org。冬眠地方话Oracle12cDialect

司徒志强
2023-03-14

我有一个JUnit 5测试不起作用,它卡住了,如下所示:

2020-04-03 16:53:23.207  INFO 2788 --- [           main] .i.p.d.r.CustomerReferenceRepositoryTest : 
No active profile set, falling back to default profiles: default
2020-04-03 16:53:24.153  INFO 2788 --- [           main] .s.d.r.c.RepositoryConfigurationDelegate : 
Bootstrapping Spring Data JPA repositories in DEFAULT mode.
2020-04-03 16:53:24.590  INFO 2788 --- [           main] .s.d.r.c.RepositoryConfigurationDelegate : 
Finished Spring Data repository scanning in 372ms. Found 8 JPA repository interfaces.
2020-04-03 16:53:26.078  INFO 2788 --- [           main] com.zaxxer.hikari.HikariDataSource       : 
HikariPool-1 - Starting...
2020-04-03 16:53:27.667  INFO 2788 --- [           main] com.zaxxer.hikari.HikariDataSource       : 
HikariPool-1 - Start completed.
2020-04-03 16:53:27.997  INFO 2788 --- [           main] o.hibernate.jpa.internal.util.LogHelper  : 
HHH000204: Processing PersistenceUnitInfo [name: default]
2020-04-03 16:53:28.392  INFO 2788 --- [           main] org.hibernate.Version                    : 
HHH000412: Hibernate ORM core version 5.4.12.Final
2020-04-03 16:53:28.866  INFO 2788 --- [           main] o.hibernate.annotations.common.Version   : 
HCANN000001: Hibernate Commons Annotations {5.1.0.Final}
2020-04-03 16:53:29.180  INFO 2788 --- [           main] org.hibernate.dialect.Dialect            : 
HHH000400: Using dialect: org.hibernate.dialect.Oracle12cDialect

测试注释如下:

@DataJpaTest
@AutoConfigureTestDatabase(replace = Replace.NONE)
@ContextConfiguration(classes = TestDALConfig.class)
class CustomerReferenceRepositoryTest {

测试被卡住了,当我手动停止时,会收到以下错误消息:

在测试运行程序“JUnit 5”中未找到测试

测试本身非常简单:

@Test
public void notNull() {
    assertThat(customerReferenceRepository).isNotNull();
}

完整单元测试

package <removed>.payment.dal.repository;

import static org.assertj.core.api.Assertions.assertThat;

import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.autoconfigure.jdbc.AutoConfigureTestDatabase;
import org.springframework.boot.test.autoconfigure.jdbc.AutoConfigureTestDatabase.Replace;
import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest;
import org.springframework.test.context.ContextConfiguration;

import aero.sita.pts.ir.payment.config.TestDALConfig;

@DataJpaTest
@AutoConfigureTestDatabase(replace = Replace.NONE)
@ContextConfiguration(classes = TestDALConfig.class)
class CustomerReferenceRepositoryTest {

    @Autowired
    private CustomerReferenceRepository customerReferenceRepository;

    public CustomerReferenceRepositoryTest() {
        super();
    }

    @Test
    public void notNull() {
        assertThat(customerReferenceRepository).isNotNull();
    }

}

maven pom

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.2.6.RELEASE</version>
        <relativePath /> <!-- lookup parent from repository -->
    </parent>

    <artifactId>payment-dal-api</artifactId>
    <name>payment-dal-api</name>
    <description>payment-dal-api</description>

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
        <java.version>1.8</java.version>
        <maven-jar-plugin.version>3.1.1</maven-jar-plugin.version>
        <ojdbc7.version>12.1.0.2</ojdbc7.version>
    </properties>

    <dependencies>
        <dependency>
            <groupId>com.oracle</groupId>
            <artifactId>ojdbc7</artifactId>
            <version>${ojdbc7.version}</version>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
            <exclusions>
                <exclusion>
                    <groupId>org.junit.vintage</groupId>
                    <artifactId>junit-vintage-engine</artifactId>
                </exclusion>
            </exclusions>
        </dependency>
    </dependencies>
</project>

测试DALConfig

@Configuration
@EnableJpaRepositories(basePackageClasses=ConfigRepository.class)
public class TestDALConfig {

    public TestDALConfig() {
        super();
    }
}

客户参考库

import org.springframework.data.repository.PagingAndSortingRepository;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import aero.sita.pts.ir.payment.dal.dto.CustomerReferenceDTO;

@Transactional(propagation = Propagation.SUPPORTS, readOnly = true)
@Repository
public interface CustomerReferenceRepository extends PagingAndSortingRepository<CustomerReferenceDTO, Long> {

}

有人能解释一下吗?谢谢

共有1个答案

司马璞
2023-03-14

请验证实体类中的导入。例如,对于日期,正确的导入为:

java.util.Date

不是:

java.sql.Date
 类似资料:
  • 即使设置了hibernate,我也会遇到异常。方言属性。我使用的是hibernate 5.0.11和spring boot 1.4.2,mysql版本为5.7 波姆。xml 这里有什么问题?

  • 另一种方法是使用Crieteria关联,但关联只能与和一起工作! 请在这里帮帮我。

  • 我试图将Spring MVC与Hibernate(即HibernateTemplate)集成,但却被这个ClassCastException ie org所困扰。springframework。orm。hibernate4.LocalSessionFactoryBean无法转换为org。冬眠SessionFactory。我正在使用Hibernate-4(ie-org.springframework

  • 在我的jax rs上使用hibernate时,出现以下错误: HTTP错误500 访问 /services/datesTest.问题原因: java.lang.连接器上的异常。Connector.buildSessionFactory(Connector.java:32)连接器。连接器处的Connector.getSessionFactory(Connector.java:37)。Connecto

  • 配置类的应用程序侦听器时出现错误 这实际上是我的错误 ** 严重:配置类org的应用程序侦听器时出错。springframework。网状物上下文ContextLoaderListener java。lang.NoClassDefFoundError:javax/servlet/ServletContextListener **在爪哇。lang.ClassLoader。java上的findBoot

  • 本文向大家介绍SpringBoot starter 作用在什么地方?相关面试题,主要包含被问及SpringBoot starter 作用在什么地方?时的应答技巧和注意事项,需要的朋友参考一下 依赖管理是所有项目中至关重要的一部分。当一个项目变得相当复杂,管理依赖会成为一个噩梦,因为当中涉及太多 artifacts 了。 这时候 SpringBoot starter 就派上用处了。每一个 state