-
Notifications
You must be signed in to change notification settings - Fork 28
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
jakarta.validation.Validator can't be registered #156
Comments
Hi @stefanvettiger can you please provide a code snippet / example of what are you doing. |
This pom.xml is working
This WebserverVerticle.java is working package swiss.avm.cma.backend.rest.config;
import com.zandero.rest.RestRouter;
import io.vertx.core.AbstractVerticle;
import io.vertx.core.Promise;
import io.vertx.core.http.HttpMethod;
import io.vertx.core.http.HttpServer;
import io.vertx.ext.web.Router;
import io.vertx.ext.web.handler.BodyHandler;
import org.hibernate.validator.HibernateValidator;
import org.hibernate.validator.HibernateValidatorConfiguration;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import swiss.avm.cma.backend.CmaBackendApplication;
import swiss.avm.common.rest.controller.IRestController;
import javax.validation.Validation;
import javax.validation.Validator;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
public class WebserverVerticle extends AbstractVerticle {
private static final Logger LOGGER = LoggerFactory.getLogger(CmaBackendApplication.class);
private final int serverPort;
private final List<IRestController> restControllers;
public WebserverVerticle(int serverPort) {
this.serverPort = serverPort;
this.restControllers = new ArrayList<>();
}
public WebserverVerticle with(List<IRestController> restControllers) {
this.restControllers.addAll(restControllers);
return this;
}
@Override
public void start(Promise<Void> startPromise) throws Exception {
super.start();
Router router = Router.router(vertx);
Set<String> allowedHeaders = new HashSet<>();
allowedHeaders.add("Content-Type");
allowedHeaders.add("Accept");
allowedHeaders.add("Accept-Language");
allowedHeaders.add("Authorization");
RestRouter.enableCors(router,
".+",
false,
600,
allowedHeaders,
HttpMethod.GET,
HttpMethod.POST,
HttpMethod.PUT,
HttpMethod.PATCH,
HttpMethod.DELETE,
HttpMethod.OPTIONS);
HibernateValidatorConfiguration configuration = Validation
.byProvider(HibernateValidator.class)
.configure();
Validator validator = configuration.buildValidatorFactory().getValidator();
RestRouter.validateWith(validator);
BodyHandler bodyHandler = BodyHandler.create("upload-folder")
.setDeleteUploadedFilesOnEnd(true);
RestRouter.setBodyHandler(bodyHandler);
for (IRestController controller : restControllers) {
RestRouter.register(router, controller);
}
HttpServer httpServer = vertx.createHttpServer().requestHandler(router);
httpServer.listen(serverPort);
System.out.println("Server Started");
startPromise.complete();
LOGGER.info("Webserver Verticle Started");
}
} This pom.xml is NOT working
This WebserverVerticle.java is NOT working package swiss.avm.cma.backend.rest.config;
import com.zandero.rest.RestRouter;
import io.vertx.core.AbstractVerticle;
import io.vertx.core.Promise;
import io.vertx.core.http.HttpMethod;
import io.vertx.core.http.HttpServer;
import io.vertx.ext.web.Router;
import io.vertx.ext.web.handler.BodyHandler;
import org.hibernate.validator.HibernateValidator;
import org.hibernate.validator.HibernateValidatorConfiguration;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import swiss.avm.cma.backend.CmaBackendApplication;
import swiss.avm.common.rest.controller.IRestController;
import jakarta.validation.Validation;
import jakarta.validation.Validator;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
public class WebserverVerticle extends AbstractVerticle {
private static final Logger LOGGER = LoggerFactory.getLogger(CmaBackendApplication.class);
private final int serverPort;
private final List<IRestController> restControllers;
public WebserverVerticle(int serverPort) {
this.serverPort = serverPort;
this.restControllers = new ArrayList<>();
}
public WebserverVerticle with(List<IRestController> restControllers) {
this.restControllers.addAll(restControllers);
return this;
}
@Override
public void start(Promise<Void> startPromise) throws Exception {
super.start();
Router router = Router.router(vertx);
Set<String> allowedHeaders = new HashSet<>();
allowedHeaders.add("Content-Type");
allowedHeaders.add("Accept");
allowedHeaders.add("Accept-Language");
allowedHeaders.add("Authorization");
RestRouter.enableCors(router,
".+",
false,
600,
allowedHeaders,
HttpMethod.GET,
HttpMethod.POST,
HttpMethod.PUT,
HttpMethod.PATCH,
HttpMethod.DELETE,
HttpMethod.OPTIONS);
HibernateValidatorConfiguration configuration = Validation
.byProvider(HibernateValidator.class)
.configure();
Validator validator = configuration.buildValidatorFactory().getValidator();
RestRouter.validateWith(validator); // javax.validation.Validator needed but jakarta.validation.Validator provided
BodyHandler bodyHandler = BodyHandler.create("upload-folder")
.setDeleteUploadedFilesOnEnd(true);
RestRouter.setBodyHandler(bodyHandler);
for (IRestController controller : restControllers) {
RestRouter.register(router, controller);
}
HttpServer httpServer = vertx.createHttpServer().requestHandler(router);
httpServer.listen(serverPort);
System.out.println("Server Started");
startPromise.complete();
LOGGER.info("Webserver Verticle Started");
}
} |
We have a few more libraries that we use in the pom.xml, but they are the same in the old and new pom.xml. |
At a fast glance I think it is a problem / conflict between jakarta and javax lib. |
Thank you! Would be nice if you can provide an update within the next 6 months 😉 |
I have an instance of a jakarta Validator and I want to register it with the RestRouter.validateWith() method. It's not compatible with the javax Validator class. Is there a way to handle this?
I'm using Spring 3.3.2, Hibernate Core 6.5.2.Final and Hibernate Validator 8.0.1.Final.
The text was updated successfully, but these errors were encountered: