AlekseyPleshkov
@AlekseyPleshkov
Java/Swift developer, transhumanist, dreamer.

Как исправить ошибку при запуске Spring на боевой машине?

Доброго времени суток.

Я запускаю через Jar файл из терминала (в автозагрузку скриптов добавил на Ubuntu Server). Но через некоторое время сайт перестает работать и выдает ошибку
Could not open JPA EntityManager for transaction; nested exception is javax.persistence.PersistenceException: org.hibernate.TransactionException: JDBC begin transaction failed:


Мой build.gradle
group 'ru.test'
version '1.0-SNAPSHOT'

buildscript {
    ext.kotlin_version = '1.0.3'

    repositories {
        mavenCentral()
    }
    dependencies {
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
        classpath("org.springframework.boot:spring-boot-gradle-plugin:1.3.6.RELEASE")
        classpath 'mysql:mysql-connector-java:5.1.34'
    }
}

apply plugin: 'kotlin'
apply plugin: 'eclipse'
apply plugin: 'idea'
apply plugin: 'spring-boot'

jar {
    baseName = 'test'
    version =  '0.1.0'
}

springBoot {
    mainClass = 'ru.test.Application'
}

repositories {
    mavenCentral()
}

sourceCompatibility = 1.8
targetCompatibility = 1.8

dependencies {
    // Kotlin
    compile "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"

    // Spring
    compile("org.springframework.boot:spring-boot-starter-web")
    compile("org.springframework.boot:spring-boot-starter-data-jpa")
    compile("org.springframework.boot:spring-boot-starter-security")
    compile("org.springframework.boot:spring-boot-starter-thymeleaf")

    // Others
    compile("org.hibernate:hibernate-validator")
    compile 'org.codehaus.jackson:jackson-mapper-asl:1.9.13'
    compile 'mysql:mysql-connector-java:5.1.31'
    compile 'commons-dbcp:commons-dbcp:1.4'

    // Tests
    testCompile("org.springframework:spring-test")
    testCompile("junit:junit")
    testCompile 'org.springframework.security:spring-security-test'
}

task wrapper(type: Wrapper) {
    gradleVersion = '2.3'
}

jar {
    manifest {
        attributes 'Main-Class': 'ru.test.Application'
        attributes 'Class-Path': configurations.compile.collect { "lib/" + it.getName() }.join(' ')
    }

    into('lib') {
        from configurations.compile
    }
}

task copyDependencies(type: Copy) {
    into "$libsDir/lib"
    from configurations.compile
}

build.doLast {
    tasks.copyDependencies.execute()
}


И application.properties

# Settings site
server.port=80

# Settings for database
spring.datasource.url=jdbc:mysql://localhost:3306/test?useUnicode=yes&characterEncoding=UTF-8
spring.datasource.username=root
spring.datasource.password=password

spring.datasource.driver-class-name=com.mysql.jdbc.Driver
spring.jpa.properties.hibernate.enable_lazy_load_no_trans = true


И Application.kt

@SpringBootApplication
@ComponentScan
@EnableAutoConfiguration
@Configuration
@EnableJpaRepositories(basePackages = arrayOf("ru.test.repositories"))
open class Application {

    companion object {
        @JvmStatic fun main(args: Array<String>) {
            SpringApplication.run(Application::class.java, *args)
        }
    }

}


В чем может заключаться ошибка? Mysql имеет стандартную настройку.
Спасибо. Если потребуется показать другие участки кода, могу предоставить.
  • Вопрос задан
  • 541 просмотр
Пригласить эксперта
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Войти через центр авторизации
Похожие вопросы