我在使用 spring boot 2.1.x.RELEASE 时遇到了问题,因为它没有在组件扫描中扫描基本包,但它在 2.0.x 中运行良好。
@ComponentScan(basePackages = { "com.app.base*", "com.app.child.*" })
使用创建构建时
mvn clean package
它的 jar 已经创建,但是在运行 jar 时它没有从基本外部存储库加载 bean。
java -jar child.jar
例外:
ConfigServletWebServerApplicationContext : Exception encountered during context initialization
- cancelling refresh attempt: org.springframework.beans.factory.BeanDefinitionStoreException:
Failed to parse configuration class
[com.app.child.UserApiApplication]; 嵌套异常是 java.io.FileNotFoundException:类路径资源 [com/app/base/service/BaseService.class] 无法打开,因为它不存在
我在子项目的 lib/base.jar 中添加 base.jar。以下是 pom.xml
<dependency>
<groupId>com.app</groupId>
<artifactId>base</artifactId>
<version>0.2</version>
</dependency>
<repository>
<id>myRepo</id>
<url>file://${basedir}/lib</url>
</repository>
将 base.jar 部署到我的本地存储库中
mvn deploy:deploy-file -DgroupId=com.app -DartifactId=base-Dversion=0.2 -Durl=file:./myRepo -DrepositoryId=myRepo -DupdateReleaseInfo=true -Dfile=lib/base-0.2.jar
当我从 STS 运行应用程序时,组件扫描运行良好。但是当我创建构建并尝试运行 jar 时,它会抛出错误。
我还使用爆炸了 child.jar
jar -tf child.jar
base.jar 在列表中。