Why Spring4.1.3 webmvc internally calling hibernate-validator in weblogic12c - java

I am deploying a application in weblogic12c.It is spring4.1.3 build rest service. Earlier all jars were inside war file and I set
<prefer-web-inf-classes>true</prefer-web-inf-classes>
Now we removed the supporting jars from war file and deploying the application in weblogic 12c. But now it's throwing below exception. I don't understand how SpringMVC calls the hibernate validator. I see hibernate.validator_4_0_1.jar is available in the wlserver/modules folder of weblogic.
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.validation.beanvalidation.OptionalValidatorFactoryBean#0': Invocation of init method failed; nested exception is java.lang.AbstractMethodError: org.hibernate.validator.engine.ConfigurationImpl.getDefaultParameterNameProvider()Ljavax/validation/ParameterNameProvider;
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1566)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:539)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:476)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:302)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230)
Truncated. see log file for complete stacktrace
Caused By: java.lang.AbstractMethodError: org.hibernate.validator.engine.ConfigurationImpl.getDefaultParameterNameProvider()Ljavax/validation/ParameterNameProvider;
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

I fixed this. I got that weblogic has a weblogic.server.merged.jar which is inside weblogic/12c/wlserver/modules/features and It has javax.validation and hibernate.validator packages and causing the mess. I just updated these packages here manually by latest validation-api.jar and hibernate-validator-5.2.2.jar. It worked. Weblogic does not really cares jars under wlserver/modules but It has combined all these jars to weblogic.server.merged.jar and I needed to update the packages of the same.

Related

Eclipse tomcat on web application start java.lang.ClassNotFoundException: org.mockito.Mockito

I can not start web app in eclipse embedded tomcat, but if I deploy war file in standalone tomcat then it works.
The exception I get is:
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name defined in class path resource Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Factory method threw exception; nested exception is java.lang.NoClassDefFoundError: org/mockito/Mockito
The file exception is referring to is annotated with #Configuration and is located in src/test/java;
purpose of the file is to create mock beans for test cases.
The fix to the problem is this link:
How to prevent eclipse from deploying test classes on Tomcat?
The cause of the problem was, when eclipse was assembling a war file it would include src/test/java dir in it, and the dependencies were missing for test cases.
because in pom dependencies for test had test which means that maven will not include those jar files in final bucked product meaning war file.

All beans fail autowire on startup because of a NoSuchMethodError

After upgrading my project to Spring AOP 4.3.7 I get this error trace on every bean auto-wire at Spring Boot startup:
Caused by: java.lang.NoSuchMethodError: org.springframework.aop.framework.AopProxyUtils.getSingletonTarget(Ljava/lang/Object;)Ljava/lang/Object;
at org.springframework.context.event.AbstractApplicationEventMulticaster.addApplicationListener(AbstractApplicationEventMulticaster.java:105)
at org.springframework.context.support.AbstractApplicationContext.addApplicationListener(AbstractApplicationContext.java:494)
at org.springframework.context.support.ApplicationListenerDetector.postProcessAfterInitialization(ApplicationListenerDetector.java:78)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyBeanPostProcessorsAfterInitialization(AbstractAutowireCapableBeanFactory.java:423)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1633)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:555)
...Stack truncated here for privacy reasons...
I get the sense this is a mismatch in a Spring AOP Jar somewhere in the stack, but cannot find anything that references an actual object to trace.
I was able to resolve this by upgrading to Spring AOP 4.3.13
See these links for the old and new versions of these libraries in the API.

Jadira dependency causes AbstractMethodError

Adding a Jadira dependency with Maven causes AbstractMethodError when trying to launch SpringApplication. There is nothing helpful in the stack trace; it is not referencing any of my own classes. What is causing this error and how can I fix it?
Here is the dependency:
<dependency>
<groupId>org.jadira.usertype</groupId>
<artifactId>usertype.core</artifactId>
<version>3.1.0.CR1</version>
</dependency>
Here is part of the stacktrace:
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory' defined in class path resource [org/springframework/boot/autoconfigure/orm/jpa/HibernateJpaAutoConfiguration.class]: Invocation of init method failed; nested exception is java.lang.AbstractMethodError
...
at sec.project.CyberSecurityBaseProjectApplication.main(CyberSecurityBaseProjectApplication.java:17) [classes/:na] // this is simply the line that launches the Spring app
...
at org.springframework.boot.devtools.restart.RestartLauncher.run(RestartLauncher.java:49) [spring-boot-devtools-1.4.2.RELEASE.jar:1.4.2.RELEASE]
Caused by: java.lang.AbstractMethodError: null
at org.hibernate.internal.SessionFactoryImpl.<init>(SessionFactoryImpl.java:280) ~[hibernate-core-5.0.11.Final.jar:5.0.11.Final]
...
FWIW, I was trying to do this.
The article you are referring to says that
The code works with Spring Boot 1.2.2 and Hibernate 4.5
From your log it looks like you are using Spring Boot 1.4.2 which will fetch Hibernate 5 jars. There are some issues with Hibernate 5 and the old version of jadira (you are using 3.1.0.CR1). This issue has been fixed since 5.0.0.GA release of jadira usertype. Can you please try with new version available at https://mvnrepository.com/artifact/org.jadira.usertype/usertype.core

Java EE Exception: Name java:comp is not bound in this Context

I have the Java EE app in Netbeans 7.2.1. Trying to deploy it (building ends OK), I get the error in Tomcat log:
Caused by: javax.naming.NameNotFoundException: Name java:comp is not bound in this Context
at org.apache.naming.NamingContext.lookup(NamingContext.java:770)
at org.apache.naming.NamingContext.lookup(NamingContext.java:153)
at javax.naming.InitialContext.lookup(InitialContext.java:392)
at org.springframework.jndi.JndiTemplate$1.doInContext(JndiTemplate.java:154)
at org.springframework.jndi.JndiTemplate.execute(JndiTemplate.java:87)
at org.springframework.jndi.JndiTemplate.lookup(JndiTemplate.java:152)
at org.springframework.jndi.JndiTemplate.lookup(JndiTemplate.java:178)
at org.springframework.jndi.JndiLocatorSupport.lookup(JndiLocatorSupport.java:95)
at org.springframework.jndi.JndiObjectLocator.lookup(JndiObjectLocator.java:105)
at org.springframework.jndi.JndiObjectFactoryBean.lookupWithFallback(JndiObjectFactoryBean.java:201)
at org.springframework.jndi.JndiObjectFactoryBean.afterPropertiesSet(JndiObjectFactoryBean.java:187)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1514)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1454)
Looking for code, that causes this error I found the follow:
public Object lookup(String name) throws NamingException {
return getURLOrDefaultInitCtx(name).lookup(name);
}
How is this caused and how can I solve it?
That will in case of Tomcat happen when you have for some reason dropped arbitrary servletcontainer-specific JARs such as jsp-api.jar, servlet-api.jar, catalina.jar, etc in webapp's /WEB-INF/lib. You should remove all servletcontainer-specific JARs from there, they do not belong there. Also, make sure those JARs are not nested within other JARs you have inside WEB-INF/lib.
This is a common starter's mistake in order to "fix" compilation errors on JSP/Servlet libraries which should have been solved differently; namely by configuring the IDE project to be associated with a "Target server" in Netbeans or "Target runtime" in Eclipse. The IDE will then automagically include the server's libraries during compiletime.

Jar dependency exceptions on weblogic servers for an application

I am getting an exception while deploying on Weblogic Server:
[2012-01-13 01:17:11,496] ERROR [org.springframework.web.servlet.DispatcherServlet] Context
initialization failed
org.springframework.beans.factory.BeanCreationException: Error creating bean with name
'org.springframework.validation.beanvalidation.LocalValidatorFactoryBean#0': Invocation of init method
failed; nested exception is java.lang.NoClassDefFoundError: javax/xml/bind/JAXBException
at
org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.at
org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.at
org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.at
org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:291)
at
org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222)
at
org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:288)
at
org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:190)
at
org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.at
org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.
I have some jars as below:
log4j-1.2.14.jar
spring-asm-3.0.3.RELEASE.jar
spring-beans-3.0.3.RELEASE.jar
spring-context-3.0.3.RELEASE.jar
spring-core-3.0.3.RELEASE.jar
spring-expression-3.0.3.RELEASE.jar
spring-web-3.0.3.RELEASE.jar
spring-webmvc-3.0.3.RELEASE.jar
servlet-2.3.jar
validation-api-1.0.0.GA.jar
commons-logging-1.1.1.jar
hibernate-validator-4.0.2.GA.jar
slf4j-api-1.5.6.jar
slf4j-log4j12-1.5.6.jar
standard.jar
commons-fileupload-1.1.1.jar
ESAPI-1.4.4.jar
I am guessing the issues can be but need guidance to solve it:
After researching the issue, 2 likely scenarios came to the forefront:
Hibernate Validator Library has a bug resulting in a dependency on JDK 6
Hibernate Validator has a dependency on the JAXBException Class, and the class is not present in the existing Weblogic Environment
Upon further research, the hibernate-validator-4.0.2.jar build states a clear dependency on JDK 5.
Digging deeper into the Hibernate Validator code, it appears that version 4.0.2 relies on JAXB API 2.1.
Weblogic servers are on java 1.5 and code is also compiled on java 1.5 then why the exceptions seems to pop up??
You're being bitten by JAr incompatibilities. Your project has one version of the JAR, but WebLogic has another. The two don't match. (This is what OSGi was born to solve.)
You'll need to tell WebLogic which JAR you prefer. There's a setting in the weblogic.xml for "prefer WAR file JARs." I'm sorry, I can't recall the exact tag name; please Google for it.

Categories