【问题标题】:Generated Jar file throwing org.springframework.beans.factory.UnsatisfiedDependencyException生成的 Jar 文件抛出 org.springframework.beans.factory.UnsatisfiedDependencyException
【发布时间】:2020-12-21 14:32:58
【问题描述】:

我的完整应用程序在 Eclipse 中运行良好。我在项目目录下通过mvn clean package命令生成了一个jar文件。在目标文件夹中生成jar文件。

现在我正在通过java -jar ScoreExtractionApp.jar 执行这个 jar 文件,它给出了以下例外:

ConfigServletWebServerApplicationContext:上下文初始化期间遇到异常-取消刷新尝试:org.springframework.beans.factory.UnsatisfiedDependencyException:创建名称为“appStartupRunner”的bean时出错:通过字段“scoreParserService”表示的依赖关系不满足;嵌套异常是 org.springframework.beans.factory.UnsatisfiedDependencyException:创建名称为“scoreParserServiceImpl”的 bean 时出错:通过字段“decisionAgentService”表示不满足的依赖关系;嵌套异常是 org.springframework.beans.factory.BeanCreationException:在创建 URL [jar:file:/D:/ScoreExtractionGitHub/ScoreExtraction/target/classes/ScoreExtractionApp.jar!/BOOT-INF/ 中定义的名称为“decisionAgentServiceImpl”的 bean 时出错classes!/com/alrajhi/score/ScoreExtraction/service/impl/DecisionAgentServiceImpl.class]:合并 bean 定义的后处理失败;嵌套异常是 java.lang.IllegalStateException: Failed to introspect Class [com.alrajhi.score.ScoreExtraction.service.impl.DecisionAgentServiceImpl] from ClassLoader [org.springframework.boot.loader.LaunchedURLClassLoader@179d3b25]

package com.alrajhi.score.ScoreExtraction;

import lombok.extern.slf4j.Slf4j;


import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Service;

import com.alrajhi.score.ScoreExtraction.service.ScoreParserService;

@Slf4j
@ComponentScan
@Service
public class AppStartupRunner implements ApplicationRunner {
//
    @Autowired
    ScoreParserService scoreParserService;
//
    @Override
    public void run(ApplicationArguments args) throws Exception {
        log.info("Your application started with option names : {}", args.getOptionNames());
       scoreParserService.startExecution();
    }
}

下面是 ScoreParserService 接口

package com.alrajhi.score.ScoreExtraction.service;

import java.io.File;
import java.math.BigDecimal;
import java.util.Date;
import java.util.List;

import org.springframework.stereotype.Service;

@Service
public interface ScoreParserService {

    public void startExecution();

    public List<File> getInputFiles(String workingDirectory);

    public void processInputFiles(List<File> files);
    
    public void saveLogOutputToDB(Date logDate, String logLevel, String logResult, String logType, String logUser, String runStatus,BigDecimal s);

 }

构建 Jar 文件时的警告消息

[WARNING] Some problems were encountered while building the effective model for com.alrajhi.score:ScoreExtraction:jar:0.0.1

[WARNING] 'dependencies.dependency.systemPath' for com.experian.appscore:appscore:jar should not point at files within the project directory, ${project.basedir}/src/main/resources/lib/APPSCORE.jar will be unresolvable by dependent projects @ line 133, column 25

[WARNING] 'dependencies.dependency.systemPath' for com.experian.encoder:encoder:jar should not point at files within the project directory, ${project.basedir}/src/main/resources/lib/com.experian.eda.encoder-1.2.1.EDA2-bundle.jar will be unresolvable by dependent projects @ line 142, column 25

[WARNING] 'dependencies.dependency.systemPath' for com.experian.eda.da:Decision.Agent.Bundle:jar should not point at files within the project directory, ${project.basedir}/src/main/resources/lib/DA.jar will be unresolvable by dependent projects @ line 151, column 25

[WARNING] 'dependencies.dependency.systemPath' for org.grlea.Bridge:Log.Bridge:jar should not point at files within the project directory, ${project.basedir}/src/main/resources/lib/log-bridge-1.0.jar will be unresolvable by dependent projects @ line 160, column 25

【问题讨论】:

  • Bean 创建失败,因为未扫描组件。您需要添加注释@ComponentScan
  • 我必须把它放在哪里
  • 从 Eclipse 运行时,您使用的 Java 版本是否与运行打包的 JAR 时相同?
  • 在 Eclipse 中它由 JAVA“1.8.0_11”运行,而在外部我有 2 个 Java 版本“1.8.0_221”和“1.8.0_11”。我通过 java 版本“1.8.0_11”执行了生成的 jar 文件,它给出了相同的结果
  • 您需要将 @ComponentScan 放入 AppStartupRunner 中,因为您已经需要将基本包引用和包引用放入相同的内容。参考:springframework.guru/spring-component-scan

标签: java spring spring-boot maven spring-data-jpa


【解决方案1】:

正如我在上面的 cmets 中提到的,问题是在构建期间警告消息。

[WARNING] Some problems were encountered while building the effective model for com.alrajhi.score:ScoreExtraction:jar:0.0.1

[WARNING] 'dependencies.dependency.systemPath' for com.experian.appscore:appscore:jar should not point at files within the project directory, ${project.basedir}/src/main/resources/lib/APPSCORE.jar will be unresolvable by dependent projects @ line 133, column 25

[WARNING] 'dependencies.dependency.systemPath' for com.experian.encoder:encoder:jar should not point at files within the project directory, ${project.basedir}/src/main/resources/lib/com.experian.eda.encoder-1.2.1.EDA2-bundle.jar will be unresolvable by dependent projects @ line 142, column 25

[WARNING] 'dependencies.dependency.systemPath' for com.experian.eda.da:Decision.Agent.Bundle:jar should not point at files within the project directory, ${project.basedir}/src/main/resources/lib/DA.jar will be unresolvable by dependent projects @ line 151, column 25

[WARNING] 'dependencies.dependency.systemPath' for org.grlea.Bridge:Log.Bridge:jar should not point at files within the project directory, ${project.basedir}/src/main/resources/lib/log-bridge-1.0.jar will be unresolvable by dependent projects @ line 160, column 25

这些警告消息的解决方案是将这些 jar 文件包含在我的本地 mevan 存储库中。 我通过thread得到了这个想法

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多