Spring Boot应用程序部署问题 [英] Spring Boot Application Deployment Issue

查看:143
本文介绍了Spring Boot应用程序部署问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

朋友,

我是Spring Boot框架的新手.我已经完成了简单的spring boot应用程序,因此我将在服务器中部署spring应用程序(Windows 10 64位)

I'm new to the spring boot framework. i have completed simple spring boot application so i'm going to deploy spring application in my server (Windows 10 64 Bits)

我正在使用 Gradle 作为我的项目构建工具

我正在尝试使用以下命令获取战争/战争文件

I'm Trying to get Jar / War File Using the following Commands

./gradlew war

./gradlew bootWar

./gradlew bootJar

我成功获取了Jar/War文件,但是我尝试使用以下命令运行文件

I'm Successfully Getting Jar/War Files But I'm Try to Run the file using following Command

java -jar application.jar

但是我遇到以下错误:

Exception in thread "main" java.lang.reflect.InvocationTargetException
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.lang.reflect.Method.invoke(Method.java:498)
        at org.springframework.boot.loader.MainMethodRunner.run(MainMethodRunner.java:49)
        at org.springframework.boot.loader.Launcher.launch(Launcher.java:109)
        at org.springframework.boot.loader.Launcher.launch(Launcher.java:58)
        at org.springframework.boot.loader.JarLauncher.main(JarLauncher.java:88)
Caused by: java.lang.NoClassDefFoundError: org/springframework/boot/SpringApplication
        at com.darefriends.daregames.DaregamesApplicationKt.main(DaregamesApplication.kt:17)
        ... 8 more
Caused by: java.lang.ClassNotFoundException: org.springframework.boot.SpringApplication
        at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
        at org.springframework.boot.loader.LaunchedURLClassLoader.loadClass(LaunchedURLClassLoader.java:129)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
        ... 9 more

成绩文件:

import org.jetbrains.kotlin.gradle.tasks.KotlinCompile



plugins {
    `java`
    `idea`
    id("org.springframework.boot") version "2.3.0.RC1"
    id("io.spring.dependency-management") version "1.0.9.RELEASE"
    war
    kotlin("jvm") version "1.3.72"
    kotlin("plugin.spring") version "1.3.72"
    kotlin("plugin.jpa") version "1.3.72"
}



group = "com.darefriends"
version = "0.0.1-SNAPSHOT"
java.sourceCompatibility = JavaVersion.VERSION_1_8

repositories {
    mavenCentral()
    maven { url = uri("https://repo.spring.io/milestone") }
}

idea{
    module{
        inheritOutputDirs = false
        outputDir = file("$buildDir/classes/kotlin/main")
    }
}

dependencies {
    implementation("org.springframework.boot:spring-boot-starter-data-jdbc")
    implementation("org.springframework.boot:spring-boot-starter-data-jpa")
    implementation("org.springframework.boot:spring-boot-starter-jooq")
    implementation("org.springframework.boot:spring-boot-starter-web")
    implementation("com.fasterxml.jackson.module:jackson-module-kotlin")
    implementation("org.jetbrains.kotlin:kotlin-reflect")
    implementation("org.jetbrains.kotlin:kotlin-stdlib-jdk8")
    implementation("org.liquibase:liquibase-core")
    implementation("mysql:mysql-connector-java")
    implementation("io.springfox:springfox-swagger2:2.9.2")
    implementation("io.springfox:springfox-swagger-ui:2.9.2")
    developmentOnly("org.springframework.boot:spring-boot-devtools")
    providedRuntime("org.springframework.boot:spring-boot-starter-tomcat")
    testImplementation("org.springframework.boot:spring-boot-starter-test") {
        exclude(group = "org.junit.vintage", module = "junit-vintage-engine")
    }
}


tasks.withType<Test> {
    useJUnitPlatform()
}

tasks.withType<KotlinCompile> {
    kotlinOptions {
        freeCompilerArgs = listOf("-Xjsr305=strict")
        jvmTarget = "1.8"
    }
}

我不知道这是什么问题.我使用Kotlin作为我的开发语言

I d'not Know the What is issue. I'm Using Kotlin as My Development Language

任何人请帮助我解决此问题.在此先感谢.

Any One Please Help me to Fix this issue. Thanks in Advance..

推荐答案

我使用您的确切配置创建了一个快速准系统项目,并且我注意到,每当使用以下依赖项行时,始终存在构建问题.

I created a quick barebones project using your exact configs and I noted that there always exists a build issue whenever the following dependency line is used;

developmentOnly("org.springframework.boot:spring-boot-devtools")

一些背景:

Spring Boot 2.3.0.RC1 之前-或至少据我所知在 2.2.7.RELEASE 版本中-使用developmentOnly依赖项标签引起的问题.解决方法是在包含依赖项之前,按以下步骤在build.gradle文件中定义developmentOnly

A little Background:

Before Spring Boot 2.3.0.RC1 - or at least to my knowledge as at version 2.2.7.RELEASE - there were issues that arose from the use of the developmentOnly dependency tag. The work around was to define developmentOnly in your build.gradle file as follows before including the dependency;

val developmentOnly = configurations.create("developmentOnly")
configurations.runtimeClasspath.get().extendsFrom(developmentOnly)

但是,对于 Spring Boot 2.3.0.RC1 (您正在使用的版本),引入了一个修复程序来自动处理定义developmentOnly配置的问题.请参阅: https://github.com/spring-projects/spring-boot/wiki/Spring-Boot-2.3.0-RC1-Release-Notes#automatic-creation-of-developmentonly-configuration

However with Spring Boot 2.3.0.RC1 (which is the version you are using) a fix was introduced to automatically take care of defining developmentOnly configuration. See: https://github.com/spring-projects/spring-boot/wiki/Spring-Boot-2.3.0-RC1-Release-Notes#automatic-creation-of-developmentonly-configuration

现在此修复程序带来了另一个复杂性-用于排除devtoolsdevelopmentOnly配置从生成的胖jar(可执行的jar也是)中排除了一些jar文件.参见: https://github.com/spring-projects/spring-boot/Issues/21288 .

Now with this fix came another complication - Used to exclude devtools, the developmentOnly configuration excludes some jar files from generated fat jars (which is what your executable jar also is). See: https://github.com/spring-projects/spring-boot/issues/21288.

要解决此问题并继续前进,我有两个主要建议

To resolve this issue and move ahead, I have two major suggestions

选项1-(使用Spring Boot 2.3.0.RC1)-完全摆脱了这一行;

Option-1 - (With Spring Boot 2.3.0.RC1) - Just entirely get rid of this line;

    developmentOnly("org.springframework.boot:spring-boot-devtools")

如果您确实想控制项目中何时以及如何使用devtools,我的建议是遵循Spring Boot官方文档中的说明,网址为

And if you really do want to have some control over when and how devtools is used within your project, my suggestion would be to follow the instruction in Spring boot's official documentation here https://docs.spring.io/spring-boot/docs/current/gradle-plugin/reference/html/#packaging-executable-configuring-excluding-devtools which states as follows;

默认情况下,Spring Boot的Devtools模块 org.springframework.boot:spring-boot-devtools,将被排除在 可执行的jar或war.如果要在您的设备中包含Devtools 存档将excludeDevtools属性设置为false:

By default, Spring Boot’s Devtools module, org.springframework.boot:spring-boot-devtools, will be excluded from an executable jar or war. If you want to include Devtools in your archive set the excludeDevtools property to false:

在科特林:

// if generating a jar file
tasks.getByName<BootJar>("bootJar") {
    isExcludeDevtools = false
}

// if generating a war file
tasks.getByName<BootWar>("bootWar") {
    isExcludeDevtools = false
}

很显然,您可以根据需要切换此属性.

Obviously, you can toggle this property as you wish.

选项2 -仅保留以下行

    developmentOnly("org.springframework.boot:spring-boot-devtools")

但是将您的Spring Boot版本降级为最新发行版-现在,我认为这可能是 Spring Boot 2.2.7.RELEASE ,然后使用流行的解决方法通过在dependencies{...}块之前的任意位置包含以下developmentOnly定义.

But downgrade your spring boot version to the latest release version - at this moment, I think that's perhaps Spring Boot 2.2.7.RELEASE then use the popular work around by including the following definition of developmentOnly anywhere before your dependencies{...} block.

val developmentOnly = configurations.create("developmentOnly")
configurations.runtimeClasspath.get().extendsFrom(developmentOnly)

这篇关于Spring Boot应用程序部署问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆