PSQLException-Travis失败:任务:test失败-由于Postgres?

时间:2019-05-09 21:44:44

标签: java angular postgresql gradle travis-ci

我已经使用Java,Spring,Hibernate,Postgres和Angular创建了简单的应用程序。该应用程序正常工作,gradle构建正确(这意味着:“渐变清洁,gradle构建,gradle测试,gradle检查等”)-我没有问题。 然后,我在travis-ci.com上运行我的仓库-仍然存在相同的错误:

Task :test
com.bookTicket.BookTicketApplicationTests > contextLoads FAILED
    java.lang.IllegalStateException
        Caused by: org.springframework.beans.factory.BeanCreationException
            Caused by: javax.persistence.PersistenceException
                Caused by: org.hibernate.exception.GenericJDBCException
                    Caused by: org.postgresql.util.PSQLException
1 test completed, 1 failed
 Task :test FAILED
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':test'.

我尝试了什么?:

  1. 删除:
psql -c "ALTER USER postgres WITH PASSWORD 'postgres';" -U postgres

来自 .travis.yml 并在 application.properties

中未设置密码
  1. .travis.yml 中的自定义postgres:
addons:
  postgresql: "10"
  apt:
    packages:
      - postgresql-10
      - postgresql-client-10
env:
  global:
    - PGPORT=5432
  1. 更改
hibernate.hbm2ddl.auto=create

hibernate.hbm2ddl.auto=none

application.properties

  1. 删除lombok项目并手动创建getter / setter。我删除了:
compileOnly 'org.projectlombok:lombok:1.18.8'
annotationProcessor 'org.projectlombok:lombok:1.18.8'

我没主意了。我将在下面向您展示一些代码:

build.gradle

plugins {
    id 'org.springframework.boot' version '2.1.4.RELEASE'
    id 'java'
}

apply plugin: 'io.spring.dependency-management'

group = 'com'
version = '0.0.1'
sourceCompatibility = '11'

repositories {
    mavenCentral()
}

dependencies {
    implementation 'org.springframework.boot:spring-boot-starter-web'
    implementation 'org.springframework.boot:spring-boot-starter-test'
    compile group: 'org.springframework.data', name: 'spring-data-jpa', version: '2.1.6.RELEASE'
    compile group: 'org.hibernate', name: 'hibernate-core', version: '5.4.2.Final'
    compile group: 'org.postgresql', name: 'postgresql', version: '42.2.5'
    compileOnly 'org.projectlombok:lombok:1.18.8'
    annotationProcessor 'org.projectlombok:lombok:1.18.8'

}

bootJar {
    archiveName = "BootTicket.jar"
    mainClassName = 'com.bookTicket.BookTicketApplication'

    from('src/client/dist/client') {
        into 'static'
    }
}

processResources.dependsOn(':src:client:build')

settings.gradle

pluginManagement {
    repositories {
        gradlePluginPortal()
    }
}
rootProject.name = 'bookTicket'

include ':src:client'

.travis.yml

language: java
jdk:
- oraclejdk11
services:
- postgresql
before_script:
- psql -c 'create database bookTicket;' -U postgres
- psql -c "ALTER USER postgres WITH PASSWORD 'postgres';" -U postgres
before_install:
- chmod +x gradlew

src / main / recources / application.properties

jdbc.driverClassName=org.postgresql.Driver
jdbc.url=jdbc:postgresql://localhost:5432/bookTicket
jdbc.username=postgres
jdbc.password=postgres
hibernate.dialect=org.hibernate.dialect.PostgreSQLDialect
hibernate.show_sql=true
hibernate.format_sql=true
hibernate.hbm2ddl.auto=create

src / main / java / com / bookTicket / config / RootConfig.java

@Configuration
@EnableJpaRepositories(basePackages = {"com.bookTicket.repository"})
@PropertySource(value = {"classpath:application.properties"})
@EnableTransactionManagement
@ComponentScan(basePackages = {"com.bookTicket.service", "com.bookTicket.repository", "com.bookTicket.controller",
        "com.bookTicket.domain", "com.bookTicket"})
public class RootConfig {

    @Autowired
    private Environment environment;

    @Bean
    public DataSource dataSource() {
        DriverManagerDataSource dataSource = new DriverManagerDataSource();
        dataSource.setDriverClassName(environment.getRequiredProperty("jdbc.driverClassName"));
        dataSource.setUrl(environment.getRequiredProperty("jdbc.url"));
        dataSource.setUsername(environment.getRequiredProperty("jdbc.username"));
        dataSource.setPassword(environment.getRequiredProperty("jdbc.password"));

        return dataSource;
    }

    @Bean
    public LocalContainerEntityManagerFactoryBean entityManagerFactory() {

        HibernateJpaVendorAdapter vendorAdapter = new HibernateJpaVendorAdapter();
        vendorAdapter.setDatabase(Database.POSTGRESQL);
        vendorAdapter.setGenerateDdl(true);
        vendorAdapter.setShowSql(true);

        LocalContainerEntityManagerFactoryBean factory = new LocalContainerEntityManagerFactoryBean();
        factory.setJpaVendorAdapter(vendorAdapter);
        factory.setPackagesToScan("com.bookTicket.domain");
        factory.setDataSource(dataSource());
        factory.setJpaProperties(jpaProperties());

        return factory;
    }

    private Properties jpaProperties() {
        Properties properties = new Properties();
        properties.put("hibernate.dialect", environment.getRequiredProperty("hibernate.dialect"));
        properties.put("hibernate.show_sql", environment.getRequiredProperty("hibernate.show_sql"));
        properties.put("hibernate.format_sql", environment.getRequiredProperty("hibernate.format_sql"));
        properties.put("hibernate.hbm2ddl.auto", environment.getRequiredProperty("hibernate.hbm2ddl.auto"));
        return properties;
    }

    @Bean
    public PlatformTransactionManager transactionManager() {

        JpaTransactionManager txManager = new JpaTransactionManager();
        txManager.setEntityManagerFactory(entityManagerFactory().getObject());
        return txManager;
    }


    @Bean
    public static PropertySourcesPlaceholderConfigurer propertySourcesPlaceholderConfigurer() {
        PropertySourcesPlaceholderConfigurer o = new PropertySourcesPlaceholderConfigurer();
        o.setLocation(new ClassPathResource("application.properties"));
        return o;
    }
}

src / client / build.gradle

plugins {
  id "com.moowork.node" version "1.3.1"
}

version '0.0.1'

node {
  version = '10.15.3'
  npmVersion = '6.4.1'
  download = true
  workDir = file("${project.buildDir}/node")
  nodeModulesDir = file("${project.projectDir}")
}

task build(type: NpmTask) {
  args = ['run', 'build']
}

build.dependsOn(npm_install)

src / client / settings.gradle

pluginManagement {
  repositories {
    gradlePluginPortal()
  }
}
rootProject.name = 'client'

src / client / package.json

{
  "name": "client",
  "version": "0.0.0",
  "scripts": {
    "ng": "ng",
    "start": "ng serve",
    "start-proxy": "ng serve --proxy-config proxy.conf.json",
    "build": "ng build",
    "test": "ng test",
    "lint": "ng lint",
    "e2e": "ng e2e"
  },
  "private": true,
  "dependencies": {
    "@angular/animations": "^7.2.14",
    "@angular/cdk": "^7.3.7",
    "@angular/common": "~7.2.0",
    "@angular/compiler": "~7.2.0",
    "@angular/core": "~7.2.0",
    "@angular/forms": "~7.2.0",
    "@angular/material": "^7.3.7",
    "@angular/platform-browser": "~7.2.0",
    "@angular/platform-browser-dynamic": "~7.2.0",
    "@angular/router": "~7.2.0",
    "core-js": "^2.5.4",
    "hammerjs": "^2.0.8",
    "rxjs": "~6.3.3",
    "tslib": "^1.9.0",
    "zone.js": "~0.8.26"
  },
  "devDependencies": {
    "@angular-devkit/build-angular": "~0.13.0",
    "@angular/cli": "~7.3.8",
    "@angular/compiler-cli": "~7.2.0",
    "@angular/language-service": "~7.2.0",
    "@types/node": "~8.9.4",
    "@types/jasmine": "~2.8.8",
    "@types/jasminewd2": "~2.0.3",
    "codelyzer": "~4.5.0",
    "jasmine-core": "~2.99.1",
    "jasmine-spec-reporter": "~4.2.1",
    "karma": "~4.0.0",
    "karma-chrome-launcher": "~2.2.0",
    "karma-coverage-istanbul-reporter": "~2.0.1",
    "karma-jasmine": "~1.1.2",
    "karma-jasmine-html-reporter": "^0.2.2",
    "protractor": "~5.4.0",
    "ts-node": "~7.0.0",
    "tslint": "~5.11.0",
    "typescript": "~3.2.2"
  }
}

src / test / java / com / BookTicket / BookTicketApplicationTests.java

@RunWith(SpringRunner.class)
@SpringBootTest
public class BookTicketApplicationTests {

    @Test
    public void contextLoads() {

    }
}

也许我使用另一个数据库也可以,但是我想知道应该怎么解决这个问题。

0 个答案:

没有答案