【问题标题】:Run as spring boot app is not working where as run as java app working以 Spring Boot 应用程序运行无法正常运行,而以 Java 应用程序运行则无法运行
【发布时间】:2018-11-07 03:17:22
【问题描述】:

我正在使用 STS。

这是我的主要课程:

    @EnableZuulProxy
@SpringBootApplication


    public static void main(String[] args)  {
        try {
            SpringApplication.run(DevProxyApp.class, args);

        }catch(Exception e) {

        }

    }
}

下面是我的 build.gradle :

    buildscript {
    ext {
        springBootVersion = '2.0.2.RELEASE'
    }
    repositories {
        mavenCentral()
    }
    dependencies {
        classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
    }
}

plugins {
    id 'pmd'
    id 'org.sonarqube' version '2.6.2'
}

apply plugin: 'java'
apply plugin: 'application'
apply plugin: 'eclipse'
apply plugin: 'org.springframework.boot'
apply plugin: 'io.spring.dependency-management'
apply plugin: 'jacoco'

mainClassName = 'com.siemens.mindsphere.devproxy.DevProxyApp'
group = 'mindsphere'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = 1.8

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


ext {
    springCloudVersion = 'Finchley.BUILD-SNAPSHOT'
}

jar {
    baseName = 'sdk-devproxy'
    doLast {

    }
    destinationDir = file("$buildDir/libs/mindsphere/sdk-devproxy/$project.version/")
}

dependencies {
    compile group: 'org.springframework.cloud', name: 'spring-cloud-starter-parent', version: 'Edgware.SR3', ext: 'pom'
    compile('org.springframework.cloud:spring-cloud-starter-oauth2')
    compile('org.springframework.cloud:spring-cloud-starter-netflix-zuul')
    compile('org.springframework.boot:spring-boot-starter-web')
    compile group: 'com.auth0', name: 'java-jwt', version: '3.3.0'
    compile('com.auth0:java-jwt')
    testCompile('org.springframework.boot:spring-boot-starter-test')
    testCompile('org.springframework.security:spring-security-test')
}

dependencyManagement {
    imports {
        mavenBom "org.springframework.cloud:spring-cloud-dependencies:${springCloudVersion}"
    }
}

我也尝试过以下依赖项:

    dependencies {
    compile group: 'org.springframework.boot', name: 'spring-boot-starter-parent', version: '1.2.1.RELEASE', ext: 'pom'
    compile group: 'org.springframework.cloud', name: 'spring-cloud-starter-parent', version: 'Edgware.SR3', ext: 'pom'
    compile group: 'org.springframework.cloud', name: 'spring-cloud-starter-oauth2', version: '1.0.0.RELEASE'
    compile group: 'org.springframework.cloud', name: 'spring-cloud-starter-zuul', version: '1.4.4.RELEASE'
    compile group: 'org.springframework.boot', name: 'spring-boot-starter-web', version: '1.5.9.RELEASE'
    implementation 'org.slf4j:slf4j-api:1.7.25'
    compile group: 'com.auth0', name: 'java-jwt', version: '3.3.0'
    testCompile('org.springframework.boot:spring-boot-starter-test')
    testCompile('org.springframework.security:spring-security-test')
}

每当我将应用程序作为 Spring Boot 应用程序运行时,都会出现以下错误:

    Error: Could not find or load main class com.siemens.mindsphere.devproxy.DevProxyApp

当作为 java 应用程序运行时,它正在启动,但是这种启动功能(oauth2、zuul 路由功能)不起作用。

我尝试了以下方法,但问题仍然存在:

  • 刷新、重建、更新 gradle
  • 手动移除所有依赖,手动移除 gradle repo
  • 安装了新的 STS。

如果您需要任何其他信息来解决此问题,请告诉我。

仅供参考,以前它是一个 maven 项目并且工作正常,现在我通过添加 build.gradle、gradle 项目等将其作为 gradle 项目并删除了 pom.xml。 Gradle 构建正常进行。

是否有任何 jar 兼容性的问题????

【问题讨论】:

标签: java spring spring-boot gradle build


【解决方案1】:

尝试添加清单属性:

jar {
  manifest {
    attributes(
      'Class-Path': configurations.compile.collect { it.getName() }.join(' '),
      'Main-Class': 'com.siemens.mindsphere.devproxy.DevProxyApp'
    )
  }
}

【讨论】:

  • 我仍然遇到同样的问题
  • 主类放在哪里?如果不是,您应该将其放在 src/main/java/base.package 中。另外,只有 mainClassName: com.siemens.mindsphere.devproxy.DevProxyApp 应该可以正常工作
  • 它是正确的......你看到 jar 兼容性的问题了吗?
  • 嘿,问题是组 ID 和包结构不同步。它现在工作正常,...谢谢
【解决方案2】:

尝试降级 springBootVersion。 我遇到了这个问题,这解决了它。

【讨论】:

    猜你喜欢
    • 2020-10-03
    • 2018-05-08
    • 1970-01-01
    • 2019-05-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-04-20
    • 2020-02-22
    相关资源
    最近更新 更多