英文:
Generated Jar file throwing org.springframework.beans.factory.UnsatisfiedDependencyException
问题
完整的应用程序在Eclipse中完美运行。我通过在项目目录中使用mvn clean package
命令生成了一个jar文件。jar文件生成在目标文件夹中。
现在我通过java -jar ScoreExtractionApp.jar
来执行这个jar文件,它会产生以下异常:
ConfigServletWebServerApplicationContext:在上下文初始化期间遇到异常 - 取消刷新尝试:org.springframework.beans.factory.UnsatisfiedDependencyException:通过字段
scoreParserService
表达的不满足的依赖关系创建bean时出错;嵌套异常是org.springframework.beans.factory.UnsatisfiedDependencyException:通过字段decisionAgentService
表达的不满足的依赖关系创建bean时出错;嵌套异常是org.springframework.beans.factory.BeanCreationException:在URL [jar:file:/D:/ScoreExtractionGitHub/ScoreExtraction/target/classes/ScoreExtractionApp.jar!/BOOT-INF/classes!/com/alrajhi/score/ScoreExtraction/service/impl/DecisionAgentServiceImpl.class] 中定义了bean的创建时出错:合并的bean定义的后处理失败;嵌套异常是java.lang.IllegalStateException:无法从ClassLoader [org.springframework.boot.loader.LaunchedURLClassLoader@179d3b25] 内部检查类[com.alrajhi.score.ScoreExtraction.service.impl.DecisionAgentServiceImpl]。
以下是AppStartupRunner
类:
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] 在构建com.alrajhi.score:ScoreExtraction:jar:0.0.1的有效模型时遇到了一些问题
[WARNING] 依赖项com.experian.appscore:appscore:jar的`dependencies.dependency.systemPath`不应该指向项目目录内的文件,${project.basedir}/src/main/resources/lib/APPSCORE.jar将无法被依赖项目解析 @ 第133行,第25列
[WARNING] 依赖项com.experian.encoder:encoder:jar的`dependencies.dependency.systemPath`不应该指向项目目录内的文件,${project.basedir}/src/main/resources/lib/com.experian.eda.encoder-1.2.1.EDA2-bundle.jar将无法被依赖项目解析 @ 第142行,第25列
[WARNING] 依赖项com.experian.eda.da:Decision.Agent.Bundle:jar的`dependencies.dependency.systemPath`不应该指向项目目录内的文件,${project.basedir}/src/main/resources/lib/DA.jar将无法被依赖项目解析 @ 第151行,第25列
[WARNING] 依赖项org.grlea.Bridge:Log.Bridge:jar的`dependencies.dependency.systemPath`不应该指向项目目录内的文件,${project.basedir}/src/main/resources/lib/log-bridge-1.0.jar将无法被依赖项目解析 @ 第160行,第25列
英文:
My complete application is working perfectly in Eclipse. I generated a jar file by mvn clean package
command in the project directory. The jar file is generated in the target folder.
Now I am executing this jar file by java -jar ScoreExtractionApp.jar
, it is giving the below exceptions:
> ConfigServletWebServerApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'appStartupRunner': Unsatisfied dependency expressed through field 'scoreParserService'; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'scoreParserServiceImpl': Unsatisfied dependency expressed through field 'decisionAgentService'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'decisionAgentServiceImpl' defined in URL [jar:file:/D:/ScoreExtractionGitHub/ScoreExtraction/target/classes/ScoreExtractionApp.jar!/BOOT-INF/classes!/com/alrajhi/score/ScoreExtraction/service/impl/DecisionAgentServiceImpl.class]: Post-processing of merged bean definition failed; nested exception is 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();
}
}
Below is the ScoreParserService Interface
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);
}
Warning Messages during building Jar file
[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
答案1
得分: 0
如我在上面的评论中提到的,问题是在构建过程中出现了警告消息。
[WARNING] 在构建 com.alrajhi.score:ScoreExtraction:jar:0.0.1 有效模型时遇到了一些问题
[WARNING] com.experian.appscore:appscore:jar 的 'dependencies.dependency.systemPath' 不应指向项目目录内的文件,${project.basedir}/src/main/resources/lib/APPSCORE.jar 将无法被依赖项目解析,位于第 133 行,第 25 列
[WARNING] com.experian.encoder:encoder:jar 的 'dependencies.dependency.systemPath' 不应指向项目目录内的文件,${project.basedir}/src/main/resources/lib/com.experian.eda.encoder-1.2.1.EDA2-bundle.jar 将无法被依赖项目解析,位于第 142 行,第 25 列
[WARNING] com.experian.eda.da:Decision.Agent.Bundle:jar 的 'dependencies.dependency.systemPath' 不应指向项目目录内的文件,${project.basedir}/src/main/resources/lib/DA.jar 将无法被依赖项目解析,位于第 151 行,第 25 列
[WARNING] org.grlea.Bridge:Log.Bridge:jar 的 'dependencies.dependency.systemPath' 不应指向项目目录内的文件,${project.basedir}/src/main/resources/lib/log-bridge-1.0.jar 将无法被依赖项目解析,位于第 160 行,第 25 列
解决这些警告消息的方法是将这些 JAR 文件包含在我的本地 Maven 仓库中。
我通过这个 线程 得到了这个想法。
英文:
As i mentioned in the comments above the problem was warining messages during build.
[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
And the solution of these warning messages was including these jar files in my local mevan repository.
I got this idea by this thread
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论