class org.hibernate.validator.internal.engine.ValidatorImpl cannot be cast to class javax.validation.Validator

Viewed 69

Using the Eclipse IDE, I am trying to develop components of an application, so it may be deployed on various operating platforms. My main goal is to get a login interface to render on the server side. I have added the config.yml file in my project, and now I am getting a runtime error that says:

INFO  [2022-05-27 21:02:54,981] 
io.dropwizard.core.server.DefaultServerFactory: Registering 
jersey handler with root path prefix: /
java.lang.ClassCastException: class 
org.hibernate.validator.internal.engine.ValidatorImpl cannot be 
cast to class javax.validation.Validator 
(org.hibernate.validator.internal.engine.ValidatorImpl and 
javax.validation.Validator are in unnamed module of loader 'app')
INFO  [2022-05-27 21:02:54,983] 
io.dropwizard.core.server.DefaultServerFactory: Registering admin 
handler with root path prefix: /
INFO  [2022-05-27 21:02:54,983] 
com.dropwizard.gameauth2.GameAuthApplication: Registering REST 
resources
at com.dropwizard.gameauth2.GameAuthApplication.run(GameAuthApplication.java:41)
at io.dropwizard.core.cli.EnvironmentCommand.run(EnvironmentCommand.java:67)
at io.dropwizard.core.cli.ConfiguredCommand.run(ConfiguredCommand.java:98)
at io.dropwizard.core.cli.Cli.run(Cli.java:78)
at io.dropwizard.core.Application.run(Application.java:94)
at com.dropwizard.gameauth2.GameAuthApplication.main(GameAuthApplication.java:63)

Here is my my GameAuthApplication file:

package com.dropwizard.gameauth2;

import javax.validation.Validator;
import javax.ws.rs.client.Client;

import org.glassfish.jersey.client.JerseyClientBuilder;
import org.glassfish.jersey.server.filter.RolesAllowedDynamicFeature;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.dropwizard.gameauth2.auth.GameAuthenticator;
import com.dropwizard.gameauth2.auth.GameAuthorizer;
import com.dropwizard.gameauth2.auth.GameUser;
import com.dropwizard.gameauth2.controllers.GameUserRESTController;
import com.dropwizard.gameauth2.controllers.RESTClientController;
import com.dropwizard.gameauth2.healthcheck.AppHealthCheck;
import com.dropwizard.gameauth2.healthcheck.HealthCheckController;

import io.dropwizard.auth.AuthDynamicFeature;
import io.dropwizard.auth.AuthValueFactoryProvider;
import io.dropwizard.auth.basic.BasicCredentialAuthFilter;
import io.dropwizard.core.Application;
import io.dropwizard.core.Configuration;
import io.dropwizard.core.setup.Bootstrap;
import io.dropwizard.core.setup.Environment;

public class GameAuthApplication extends Application<Configuration> {
    private static final Logger LOGGER = LoggerFactory.getLogger(GameAuthApplication.class);

@Override
public void initialize(Bootstrap<Configuration> b) {
}

@Override
public void run(Configuration c, Environment e) throws Exception 
{
    
    LOGGER.info("Registering REST resources");

    // FIXME: register GameUserRESTController (based on BasicAuth Security Example)
    e.jersey().register(new GameUserRESTController((Validator) e.getValidator()));
    // FIXME: Create io.dropwizard.client.JerseyClientBuilder instance and give it io.dropwizard.setup.Environment reference (based on BasicAuth Security Example)
    final Client client = (Client) new JerseyClientBuilder().build();
    e.jersey().register(new RESTClientController(client));

    // Application health check
    e.healthChecks().register("APIHealthCheck", new AppHealthCheck(client));

    // Run multiple health checks
    e.jersey().register(new HealthCheckController(e.healthChecks()));
    
    //Setup Basic Security
    e.jersey().register(new AuthDynamicFeature(new 
BasicCredentialAuthFilter.Builder<GameUser>()
            .setAuthenticator(new GameAuthenticator())
            .setAuthorizer(new GameAuthorizer())
            .setRealm("App Security")
            .buildAuthFilter()));
    e.jersey().register(new AuthValueFactoryProvider.Binder<>(GameUser.class));
    e.jersey().register(RolesAllowedDynamicFeature.class);
}

public static void main(String[] args) throws Exception {
    new GameAuthApplication().run(args);
}

Is there something in my GameAuthApplication file that I need to change?

0 Answers
Related