How to solve NoSuchMethodError for javax.validation when deploying a spring boot application in weblogic server?

拜拜、爱过 提交于 2019-12-03 21:14:20
Zobayer Hasan

Finally I was able to solve the problem. I wasn't aware of the fact that if prefer-web-inf-classes is disabled from Weblogic admin console, then weblogic ignores the directive specified in weblogic.xml file.

From Oracle's documentation:

The prefer-web-inf-classes element, if set to true, will cause classes located in the WEB-INF directory of a Web application to be loaded in preference to classes loaded in the application or system classloader. The default value is false. A value specified in the Administration Console will take precedence over a value set manually.

So, instead, I had to specify prefer-application-packages in weblogic.xml file. Here is the updated content of the file:

<?xml version="1.0" encoding="UTF-8"?>
<weblogic-web-app xmlns:wls="http://xmlns.oracle.com/weblogic/weblogic-web-app"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
    http://java.sun.com/xml/ns/javaee/ejb-jar_3_0.xsd
    http://xmlns.oracle.com/weblogic/weblogic-web-app
    http://xmlns.oracle.com/weblogic/weblogic-web-app/1.4/weblogic-web-app.xsd">

<wls:container-descriptor>
    <wls:prefer-application-packages>
        <package-name>org.springframework.*</package-name>
        <package-name>org.hibernate.*</package-name>
        <package-name>javax.validation.*</package-name>
        <package-name>javax.validation.spi.*</package-name>
        <package-name>org.slf4j.*</package-name>
    </wls:prefer-application-packages>
    <wls:show-archived-real-path-enabled>true</wls:show-archived-real-path-enabled>
</wls:container-descriptor>

</weblogic-web-app>

This stackoverflow post was quite helpful.

Thanks to everyone who tried to help.

My guess is that Weblogic is using Bean Validation 1.0 which aligns with Hibernate Validator 4.x. I am not sure how to get Weblogic to use Bean Validation as bundled in your app (maybe that's what you try to do with prefer-web-inf-classes) or how to upgrade the whole app server to Bean Validation 1.1. Unless you are using method validation, you could try to use the latest 4.x release (4.3.2.Final). You would then remove the validation-api dependency from the pom (will be pulled in transitively anyways) or you set it to 1.0.0.GA.

addition of below in wblogic-application worked out

<package-name>org.hibernate.*</package-name>
<package-name>javax.validation.*</package-name>
<package-name>javax.validation.spi.*</package-name>

if using Hibernate 5.x and above, add the above in weblogic-application.xml

Thanks,

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!