我在尝试运行带有configuration.yaml文件中属性的阴影jar时面临以下问题。(直接运行主类时,没有发生(
运行命令:java -jar target/mlsdata-1.0.jar server configuration.yaml
错误:
io.dropwizard.configuration.ConfigurationParsingException: configuration.yaml has an error:
* Failed to parse configuration at: server.applicationConnectors.[0]; Could not resolve type id 'http' as a subtype of [simple type, class io.dropwizard.jetty.ConnectorFactory]: known type ids = [] (for POJO property 'applicationConnectors')
at [Source: UNKNOWN; line: -1, column: -1] (through reference chain: com.zaplabs.MlsConfiguration["server"]->io.dropwizard.server.DefaultServerFactory["applicationConnectors"]->java.util.ArrayList[0])
从我从各种来源中理解的内容来看,这可能是一个Maven包装问题。解决方案并没有帮助我。
这是我在POM中的构建设置。
`
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>2.2</version>
<configuration>
<archive>
<manifest>
<addClasspath>true</addClasspath>
<classpathPrefix>lib/</classpathPrefix>
<mainClass>com.zaplabs.MlsApplication</mainClass>
</manifest>
</archive>
<createDependencyReducedPom>true</createDependencyReducedPom>
<filters>
<filter>
<artifact>*:*</artifact>
<excludes>
<exclude>META-INF/*.SF</exclude>
<exclude>META-INF/*.DSA</exclude>
<exclude>META-INF/*.RSA</exclude>
</excludes>
</filter>
</filters>
</configuration>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<archive>
<manifest>
<addClasspath>true</addClasspath>
<classpathPrefix>lib/</classpathPrefix>
<mainClass>com.zaplabs.MlsApplication</mainClass>
</manifest>
</archive>
<transformers>
<transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer"/>
<transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
<mainClass>com.zaplabs.MlsApplication</mainClass>
</transformer>
</transformers>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
`
dropwizard版本:
<dependency>
<groupId>io.dropwizard</groupId>
<artifactId>dropwizard-core</artifactId>
<version>1.3.0</version>
</dependency>
configuration.yaml
server:
applicationConnectors:
- type: http
port: 9000
adminConnectors:
- type: http
port: 9001
# Database settings.
database:
# the name of the JDBC driver, mysql in our case
driverClass: com.mysql.jdbc.Driver
# the username
user: xxx
# the password
password: xxx
# the JDBC URL
url: jdbc:mysql://xxx
properties:
charSet: UTF-8
maxWaitForConnection: 1s
validationQuery: "/* MyService Health Check */ SELECT 1"
minSize: 8
maxSize: 32
checkConnectionWhileIdle: false
evictionInterval: 10s
minIdleTime: 1 minute
hibernate.dialect: org.hibernate.dialect.H2Dialect
hibernate.show_sql: true
hibernate.generate_statistics: false
hibernate.hbm2ddl.auto: validate # validates schema when service is started
,所以我遇到了同样的问题,我在这里找到了解决方案
也必须使用以下插件
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>2.3</version>
<configuration>
<createDependencyReducedPom>true</createDependencyReducedPom>
<filters>
<filter>
<artifact>*:*</artifact>
<excludes>
<exclude>META-INF/*.SF</exclude>
<exclude>META-INF/*.DSA</exclude>
<exclude>META-INF/*.RSA</exclude>
</excludes>
</filter>
</filters>
</configuration>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<transformers>
<transformer implementation="org.apache.maven.plugins.shade.resource.ServicesResourceTransformer"/>
<transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
<mainClass>com.example.helloworld.HelloWorldApplication</mainClass>
</transformer>
</transformers>
</configuration>
</execution>
</executions>