[已解决] Dropwizard – 无法解析配置(无法将类型 ID “http”解析为子类型)
如果您使用 dropwizard 构建 REST API,并且在启动 Jetty 服务器时遇到此错误,则给定的解决方案可能会对您有所帮助。
问题
启动服务器时,您会收到此错误。
>java -jar target\DropWizardExample-0.0.1-SNAPSHOT.jar server
default configuration has an error:
* Failed to parse configuration at: server.applicationConnectors.[0]; Could not resolve type id 'http' into a subtype of [simple type, class io.dropwizard.jetty.ConnectorFactory]: known type ids = [ConnectorFactory]
at [Source: N/A; line: -1, column: -1] (through reference chain: io.dropwizard.Configuration["server"]->io.dropwizard.server.DefaultServerFactory["applicationConnectors"]->java.util.ArrayList[0])
解决方案
上面的异常是因为您在 Maven shade 插件中没有使用 ServicesResourceTransformer
。 它将META-INF/services
中的类重新放置,并将META-INF/services
资源中的条目追加到单个资源中。
请更正 shade 插件,您会感觉很好。
我的pom.xml
非常适合我。
<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.howtodoinjava.demo</groupId>
<artifactId>DropWizardExample</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<name>DropWizardExample</name>
<url>http://maven.apache.org</url>
<properties>
<dropwizard.version>1.0.0</dropwizard.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<dependency>
<groupId>io.dropwizard</groupId>
<artifactId>dropwizard-core</artifactId>
<version>${dropwizard.version}</version>
</dependency>
<dependency>
<groupId>io.dropwizard</groupId>
<artifactId>dropwizard-client</artifactId>
<version>${dropwizard.version}</version>
</dependency>
</dependencies>
<build>
<finalName>DropWizardExample-${version}</finalName>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>2.1</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<transformers>
<transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
<mainClass>com.howtodoinjava.rest.App</mainClass>
</transformer>
</transformers>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
让我知道它是否可以解决您的问题。
学习愉快!