尝试运行带有 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>
`
下拉向导版本:
<dependency>
<groupId>io.dropwizard</groupId>
<artifactId>dropwizard-core</artifactId>
<version>1.3.0</version>
</dependency>
配置.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