【发布时间】:2017-11-30 21:30:50
【问题描述】:
我目前正在开发一个 Spring Boot Starter,它将托管一个带有一些关于正在运行的应用程序的元数据的 Restful Web 服务。
我在从我的 mainfest 文件中提取我的 artifactId 和 versionId 时遇到了困难。我相信我的问题是自动配置类是在主测试应用程序之前加载的,所以清单还不能被发现。如果我从错误的角度解决问题,我不确定我的逻辑是否正确。
我最初是按照以下tutorial 进行设置的。
这给了我 3 个独立的项目
Generic Spring Services with no context
AutoConfiguration project for these services
Spring Boot starter
作为最终结果,我将启动器与测试项目配对。
目前正在使用 maven 与 Spring Boot 一起生成清单文件。
Implementation-Title: MyExampleProjectWithCustomStarter
Implementation-Version: 0.0.1-SNAPSHOT
Archiver-Version: Plexus Archiver
Built-By: mcf
Implementation-Vendor-Id: com.coolCompany
Spring-Boot-Version: 1.5.4.RELEASE
Implementation-Vendor: Pivotal Software, Inc.
Main-Class: org.springframework.boot.loader.JarLauncher
Start-Class: com.coolcompany.SpringBootExampleApplication
Spring-Boot-Classes: BOOT-INF/classes/
Spring-Boot-Lib: BOOT-INF/lib/
Created-By: Apache Maven 3.5.0
Build-Jdk: 1.8.0_131
Implementation-URL: http://someurl
但是,当我尝试从我的通用服务包中找到示例项目的清单文件时,我找不到该文件。
private String getApplicationVersion(String applicationName, List<Attributes> manifests) {
String unknownVersion = "0.0.0-UNKNOWN";
for (Attributes attr : manifests) {
String title = attr.getValue(IMPL_TITLE);
String version = attr.getValue(IMPL_VERSION);
if (version != null) {
if (applicationName.equalsIgnoreCase(title)) {
return title + ' ' + version;
}
}
}
log.warn(
"Could not find MANIFEST file with '" + applicationName + "' as Implementation-Title."
+ " Meta-API will return buildVersion '" + unknownVersion + "'.");
return applicationName + ' ' + unknownVersion;
}
private List<Attributes> loadManifestFiles() {
List<Attributes> manifests = new ArrayList<>();
try {
Enumeration<URL> resources =
Thread.currentThread().getContextClassLoader().getResources("/META-INF/MANIFEST.MF");
while (resources.hasMoreElements()) {
URL url = resources.nextElement();
try (InputStream is = url.openStream()) {
manifests.add(new Manifest(is).getMainAttributes());
System.out.println("Manifest size:" + manifests.size());
} catch (IOException e) {
log.error("Failed to read manifest from " + url, e);
}
}
} catch (IOException e) {
log.error("Failed to get manifest resources", e);
}
return manifests;
}
当前清单实施-标题:
Spring Boot Web Starter
Spring Boot Starter
Spring Boot
Spring Boot AutoConfigure
Spring Boot Logging Starter
null
null
jcl-over-slf4j
null
log4j-over-slf4j
null
Spring Boot Tomcat Starter
Apache Tomcat
Apache Tomcat
Apache Tomcat
hibernate-validator
null
JBoss Logging 3
ClassMate
jackson-databind
Jackson-annotations
Jackson-core
spring-web
spring-aop
spring-beans
spring-context
spring-webmvc
spring-expression
Spring Boot Actuator Starter
Spring Boot Actuator
null
** MyCustom-spring-boot-starter
** MyGenericSpringService
null
null
null
Metrics Core
JVM Integration for Metrics
null
null
Jackson datatype: JSR310
** MyService-spring-boot-autoconfigure
slf4j-api
spring-core
** 缺少 MyExampleProjectWithCustomStarter
清单记录数:44
【问题讨论】:
-
可以分享一下错误日志吗?另外,项目的运行情况如何?在编辑器或 cmd 行中?
-
我现在从图片中删除了编辑器我只是 maven 安装和使用 java -jar。目前,当我检索所有清单时,除了缺少清单之外没有其他错误
标签: java spring maven spring-boot manifest