集成测试给出了初始化错误

时间:2019-05-01 20:23:45

标签: java sql postgresql spring-boot

我正在使用Java11.0.3和springboot 2.0.5。我正在尝试为与postgresql连接的应用程序编写集成测试。所以我正在使用NamedParameterJdbcTemplate。

当我尝试运行集成测试时。 (MVN清除验证-P集成测试)  它给出了

java.lang.NoClassDefFoundError: java/sql/SQLException
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.<clinit>(SpringJUnit4ClassRunner.java:107)
    at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
    at java.base/jdk.internal.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
    at java.base/java.lang.reflect.Constructor.newInstance(Constructor.java:490)
    at org.junit.internal.builders.AnnotatedBuilder.buildRunner(AnnotatedBuilder.java:104)
    at org.junit.internal.builders.AnnotatedBuilder.runnerForClass(AnnotatedBuilder.java:86)
    at org.junit.runners.model.RunnerBuilder.safeRunnerForClass(RunnerBuilder.java:59)
    at org.junit.internal.builders.AllDefaultPossibilitiesBuilder.runnerForClass(AllDefaultPossibilitiesBuilder.java:26) 

这是我的考试课程

@RunWith(SpringJUnit4ClassRunner.class)
@SpringBootTest(classes = ContentAggregatorApplication.class, webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
@TestPropertySource("/application.properties")
public class ContentAggregatorApplicationIT {

    @LocalServerPort
    private int port;

    TestRestTemplate restTemplate = new TestRestTemplate();

    HttpHeaders headers = new HttpHeaders();

    @Test
    public void getESGValues() throws Exception{

 HttpEntity<String> entity = new HttpEntity<>(String, headers);

        ResponseEntity<String> exchange = restTemplate
            .exchange(createURLWithPort("v1/data/valueRequest"), HttpMethod.POST, entity,
                String.class);

        assertEquals(HttpStatus.OK,exchange.getStatusCode());
}

 private String createURLWithPort(String uri) {
        return "http://localhost:" + port + uri;
    }
}

这是我的配置文件

public class PostgresConfig {

    @Bean
    @Primary
    @ConfigurationProperties("spring.datasource")
    public HikariDataSource dataSource() {
        return DataSourceBuilder.create().type(HikariDataSource.class).build();
    }

    @Bean public NamedParameterJdbcTemplate jdbcTemplate(DataSource dataSource) {
        NamedParameterJdbcTemplate namedParameterJdbcTemplate =
            new NamedParameterJdbcTemplate(dataSource);

        return namedParameterJdbcTemplate;
    }

我有这种依赖性

 <dependency>
            <groupId>org.postgresql</groupId>
            <artifactId>postgresql</artifactId>
        </dependency>

0 个答案:

没有答案