我们有一个库,为了自动配置该库,我们在(src / main / resources / META-INF)下使用spring.factories文件,该文件提供用于自动配置我的库的类。
参考:https://docs.spring.io/spring-boot/docs/1.4.0.M3/reference/htmlsingle/#boot-features-custom-starter
我在spring.factories文件中具有以下配置:
org.springframework.boot.autoconfigure.EnableAutoConfiguration=com.x.y.PubSubConfig
构建代码时spring.factories应该是生成的工件的一部分,但令我惊讶的是,我在罐子中没有看到任何Meta-Inf。
关于一点点的研究,我相信它可能与build插件有关,下面的问题围绕它进行了描述。 https://github.com/spring-projects/spring-boot/issues/8299
我的问题是我的jar中没有附带spring.factories文件,因此不会进行自动配置。以下是我的POM文件
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.kramphub</groupId>
<artifactId>pubsub-template</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>jar</packaging>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.0.2.RELEASE</version>
<relativePath/>
</parent>
<properties>
<java.version>1.8</java.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<google-cloud-bom.version>0.55.1-alpha</google-cloud-bom.version>
<selfdiagnose.version>2.15.2</selfdiagnose.version>
<lombok.version>1.16.22</lombok.version>
<log4j-over-slf4j.version>1.7.25</log4j-over-slf4j.version>
<assertj-core.version>3.10.0</assertj-core.version>
</properties>
<distributionManagement>
<repository>
<id>central</id>
<name>kramphub-releases</name>
<url>https://kramphub.jfrog.io/kramphub/libs-release-local</url>
</repository>
</distributionManagement>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>com.google.cloud</groupId>
<artifactId>google-cloud-bom</artifactId>
<version>${google-cloud-bom.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<dependencies>
<!-- https://mvnrepository.com/artifact/com.google.cloud/google-cloud-pubsub -->
<dependency>
<groupId>com.google.cloud</groupId>
<artifactId>google-cloud-pubsub</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
</dependency>
<dependency>
<groupId>com.philemonworks</groupId>
<artifactId>selfdiagnose</artifactId>
<version>${selfdiagnose.version}</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>log4j-over-slf4j</artifactId>
<version>${log4j-over-slf4j.version}</version>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<scope>provided</scope>
<version>${lombok.version}</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.assertj</groupId>
<artifactId>assertj-core</artifactId>
<version>${assertj-core.version}</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<!-- verify whether necessary -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId>
<version>${maven-source-plugin.version}</version>
<executions>
<execution>
<id>attach-sources</id>
<phase>verify</phase>
<goals>
<goal>jar-no-fork</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<version>${maven-surefire-plugin.version}</version>
<configuration>
<skipTests>true</skipTests>
</configuration>
</plugin>
</plugins>
</build>
<profiles>
<profile>
<id>testwithemulator</id>
<build>
<plugins>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<skipTests>false</skipTests>
</configuration>
</plugin>
</plugins>
</build>
</profile>
</profiles>
<reporting>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<version>${maven-javadoc-plugin.version}</version>
<configuration>
</configuration>
</plugin>
</plugins>
</reporting>
</project>