Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why does dropwizard configuration is not working?

Recently I ported the HVDF project's dropwizard version from 0.6.2 to 0.8.2.Once I try to run the application I get the following error.I provide the config class and yml file below:

Config class:

package com.mongodb.hvdf;

import io.dropwizard.Configuration;

import java.util.LinkedHashMap;
import java.util.Map;

import com.mongodb.hvdf.configuration.MongoGeneralConfiguration;

public class HVDFConfiguration extends Configuration {

    public MongoGeneralConfiguration mongodb = new MongoGeneralConfiguration();
    public Map<String, Object> services = new LinkedHashMap<String, Object>();
}

Yaml file:

server:
  applicationConnectors:
    - type: http
      port: 8080

I get the following error at runtime:

config.yml 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]
 at [Source: N/A; line: -1, column: -1] (through reference chain: com.mongodb.hvdf.HVDFConfiguration["server"]->io.dropwizard.server.DefaultServerFactory["applicationConnectors"]->java.util.ArrayList[0])
like image 826
armin Avatar asked Jan 26 '26 17:01

armin


2 Answers

If you are using maven shade plugin, use necessary transformers.

adding ServicesResourceTransformer to your shade plugin configuration may solve the problem. read more about transformers (here).

<configuration>
<transformers>
    <transformer implementation="org.apache.maven.plugins.shade.resource.ServicesResourceTransformer"/>
    <transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
        <mainClass>com.yb.exercise.dw.App</mainClass>
    </transformer>
</transformers>

like image 81
Dhanushka Avatar answered Jan 28 '26 07:01

Dhanushka


The problem was that DiscoverableSubtypeResolver class which jackson uses to dynamically load the class types and set their configuration could not find the src/main/resource folder due to some Build Path problems.But when I added this resource folder to my build path everything worked fine.

like image 39
armin Avatar answered Jan 28 '26 05:01

armin



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!