I'm working on a webapp in Spring using Spring Tool Suite. If I build and deploy the application there using the IDE onto the provided Pivotal tc Server, it works just fine. However, if I do a manual "mvn clean package" build and attempt to deploy it to a standalone Tomcat server (using newest Tomcat 7), it throws the following exception:
2017-08-23 15:24:13 WARN AnnotationConfigWebApplicationContext:551 - Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'requestMappingHandlerAdapter' defined in org.springframework.web.servlet.config.annotation.DelegatingWebMvcConfiguration: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter]: Factory method 'requestMappingHandlerAdapter' threw exception; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'mvcValidator' defined in org.springframework.web.servlet.config.annotation.DelegatingWebMvcConfiguration: Invocation of init method failed; nested exception is java.lang.NoClassDefFoundError: javax/el/ELManager
2017-08-23 15:24:13 ERROR DispatcherServlet:502 - Context initialization failed
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'requestMappingHandlerAdapter' defined in org.springframework.web.servlet.config.annotation.DelegatingWebMvcConfiguration: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter]: Factory method 'requestMappingHandlerAdapter' threw exception; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'mvcValidator' defined in org.springframework.web.servlet.config.annotation.DelegatingWebMvcConfiguration: Invocation of init method failed; nested exception is java.lang.NoClassDefFoundError: javax/el/ELManager
Upon further inspection, it does complain few lines higher above about not loading jars:
sie 23, 2017 3:24:12 PM org.apache.catalina.startup.HostConfig deployWAR
INFO: Deploying web application archive D:\Apache-Tomcat-7.0\webapps\TestApp-0.0.1-SNAPSHOT.war
sie 23, 2017 3:24:12 PM org.apache.catalina.loader.WebappClassLoader validateJarFile
INFO: validateJarFile(D:\Apache-Tomcat-7.0\webapps\TestApp-0.0.1-SNAPSHOT\WEB-INF\lib\el-api-2.2.jar) - jar not loaded. See Servlet Spec 2.3, section 9.7.2. Offending class: javax/el/Expression.class
sie 23, 2017 3:24:12 PM org.apache.catalina.loader.WebappClassLoader validateJarFile
INFO: validateJarFile(D:\Apache-Tomcat-7.0\webapps\TestApp-0.0.1-SNAPSHOT\WEB-INF\lib\javax.servlet-api-3.1.0.jar) - jar not loaded. See Servlet Spec 2.3, section 9.7.2. Offending class: javax/servlet/Servlet.class
sie 23, 2017 3:24:12 PM org.apache.catalina.loader.WebappClassLoader validateJarFile
INFO: validateJarFile(D:\Apache-Tomcat-7.0\webapps\TestApp-0.0.1-SNAPSHOT\WEB-INF\lib\tomcat-el-api-8.0.21.jar) - jar not loaded. See Servlet Spec 2.3, section 9.7.2. Offending class: javax/el/Expression.class
2017-08-23 15:24:13 INFO ContextLoader:304 - Root WebApplicationContext: initialization started
My pom.xml:
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.exmaple.mvc</groupId>
<artifactId>TestApp</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>war</packaging>
<dependencies>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
<version>4.3.10.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
<version>4.3.10.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
<version>4.3.10.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-test</artifactId>
<version>4.3.10.RELEASE</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
<version>1.6.6</version>
</dependency>
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.17</version>
<exclusions>
<exclusion>
<artifactId>jms</artifactId>
<groupId>javax.jms</groupId>
</exclusion>
<exclusion>
<artifactId>jmxri</artifactId>
<groupId>com.sun.jmx</groupId>
</exclusion>
<exclusion>
<artifactId>jmxtools</artifactId>
<groupId>com.sun.jdmk</groupId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>jstl</groupId>
<artifactId>jstl</artifactId>
<version>1.2</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<scope>test</scope>
</dependency>
<!-- https://mvnrepository.com/artifact/org.mockito/mockito-all -->
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-all</artifactId>
<version>1.9.5</version>
<scope>test</scope>
</dependency>
<!-- https://mvnrepository.com/artifact/commons-lang/commons-lang -->
<dependency>
<groupId>commons-lang</groupId>
<artifactId>commons-lang</artifactId>
<version>2.3</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.hibernate/hibernate-validator -->
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-validator</artifactId>
<version>6.0.1.Final</version>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>3.1.0</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
</plugins>
</build>
</project>
What's the reason for this behavior and how can I solve this?
EDIT More information:
Adding <scope>provided</scope> to javax.servlet-api seems to fix the warning about javax.servlet-api not being loaded at the start. Problem with el-api still remains.
I've checked the tomcat/lib directory and it already contains el-api.jar in it, which is likely why it tells me it's not going to load the one I list in pom.xml. The thing is, adding <scope>provided</scope> doesn't fix it either. Whatever I do, it still complains gives me the same java.lang.NoClassDefFoundError: javax/el/ELManager error.
SOLUTION
In addition to the part in the edit above regarding javax.servlet-api the problem with el-api was that I was running a Tomcat 7 with provided el-api jar in version 2.2. The missing class was introduced in el-api 3.0. Running the same webapp in Tomcat 8 (with el-api 3.0 jar) works properly.
You miss the javax.el-api as dependency. Add:
<dependency>
<groupId>javax.el</groupId>
<artifactId>javax.el-api</artifactId>
<version>3.0.0</version>
</dependency>
to your pom.xml
Hibernate Validator 6.x -> Bean Validation 2.0 (JSR 380) -> EL3.0
Hibernate Validator 5.x -> Bean Validation 1.1 (JSR 349) -> EL2.2
Bean Validation 1.0 (JSR 303) -> (I'm not sure)
so,it also influence others version (tomcat,jdk,jsp,servlet)
such as tomcat7, if you want to use Hibernate Validator, should use Hibernate Validator 5.x, el 2.2 (and servlet 3.0, jsp 2.2 and jdk 6+)
Downgrade hibernate-validator to version 5 and it will work fine with Tomcat 7.
In my case I add next dependency to my pom:
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-validator</artifactId>
<version>5.4.3.Final</version>
</dependency>
Or you can add newer el-api.jat to tomcat lib folder.
Please refer to Hibernate validation "Unable to initialize javax.el.ExpressionFactory" error
use
<dependency>
<groupId>org.glassfish</groupId>
<artifactId>javax.el</artifactId>
<version>3.0.1-b08</version>
</dependency>
I'm using Tomcat 7.0.9 and couldn't change to any newer one due my company bureaucracy. Importing EL as a dependency didn't solve it either.
At Tomcat's root folder -> lib I replaced old el-api (2.2 version of it) with a new 3.0 (from local .m2\repository\javax\el\javax.el-api\3.0.0). Then, isolating tomcat's dependencies correctly (as shown here) made my WAR be correctly deployed at Tomcat 7.0.9
Adding my answer for those having Tomcat 7 and trying to apply selected answer.
If adding dependency does not help you and you continue getting
java.lang.NoClassDefFoundError: javax/el/ELManager
that's because Tomcat 7 will not allow you to load a more modern jar with objects from javax.* package. It will print to the log:
jakarta.el-3.0.3.jar - jar not loaded. See Servlet Spec 3.0, section 10.7.2. Offending class: javax/el/Expression.class
The solution will be to either upgrade your Tomcat or downgrade hibernate-validator to the latest 5.x version. Another (less preferred from my POV) option would be to try to replace jars in your tomcat7/lib folder.
In my case,
Commented out this dependency,
<!-- <dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-validator</artifactId>
<version>6.0.8.Final</version>
</dependency> -->
and added
<dependency>
<groupId>javax.el</groupId>
<artifactId>javax.el-api</artifactId>
<version>3.0.0</version>
<scope>provided</scope>
</dependency>
This solved my issue
Try the following:
Add javax.eland javax.el-api to the pom.xml as others mention
If you have different classloaders - as often the case when using OSGi - you need to temporarily set the context to the one holding the implementation. Wrap your call with:
ClassLoader originalClassLoader = Thread.currentThread().getContextClassLoader();
try {
Class<?> currentClass = this.getClass(); // or any class that is in a bundle with the dependency
Thread.currentThread().setContextClassLoader(currentClass.getClassLoader());
// execute library call
} finally {
Thread.currentThread().setContextClassLoader(originalClassLoader); // back to original context
}
Add a service to META-INF/services/
Add a property to $java.home/lib/el.properties
Use the system property with the factoryId
When the library is instantiating the ExpressionFactory via > ELManager.newInstance(..) > FactoryFinder.find(..) it has several strategies to find an implementation. The call is hardcoded like this:
public static ExpressionFactory newInstance(Properties properties) {
return (ExpressionFactory) FactoryFinder.find(
"javax.el.ExpressionFactory", "com.sun.el.ExpressionFactoryImpl", properties);
}
See source of javax.el.FactoryFinder.find(..) for further information
Related
Since upgrading to MacOS 12, when I run owlapi-dependent projects that are compiled with Maven, the Guice library which owlapi depends on, throws several different types of exceptions at start time. What can I do to resolve this?
For example:
Exception in thread "main" java.lang.NoSuchMethodError: com.google.inject.internal.BytecodeGen.getClassLoader(Ljava/lang/Class;)Ljava/lang/ClassLoader;
com.google.inject.internal.MessageProcessor visit
INFO: An exception was caught and reported. Message: java.lang.NoSuchMethodException: uk.ac.manchester.cs.owl.owlapi.OWLOntologyFactoryImpl.<init>()
com.google.inject.CreationException: Unable to create injector, see the following errors:
1) An exception was caught and reported. Message: Injection failed for interface OWLOntologyFactory
at [unknown source]
1 error
======================
Full classname legend:
======================
OWLOntologyFactory: "org.semanticweb.owlapi.model.OWLOntologyFactory"
========================
End of classname legend:
========================
at com.google.inject.internal.Errors.throwCreationExceptionIfErrorsExist(Errors.java:576)
at com.google.inject.internal.InternalInjectorCreator.initializeStatically(InternalInjectorCreator.java:163)
at com.google.inject.internal.InternalInjectorCreator.build(InternalInjectorCreator.java:110)
at com.google.inject.Guice.createInjector(Guice.java:87)
at com.google.inject.Guice.createInjector(Guice.java:69)
at com.google.inject.Guice.createInjector(Guice.java:59)
at org.semanticweb.owlapi.apibinding.OWLManager.<clinit>(OWLManager.java:42)
... 2 more
Here are the dependencies in the pom file I'm using:
<dependencies>
<dependency>
<groupId>net.sourceforge.owlapi</groupId>
<artifactId>jfact</artifactId>
<version>5.0.0</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-simple</artifactId>
<version>1.7.7</version>
</dependency>
<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<version>7.6.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>net.sourceforge.owlapi</groupId>
<artifactId>owlapi-rio</artifactId>
<version>5.1.0</version>
</dependency>
<dependency>
<groupId>com.google.inject</groupId>
<artifactId>guice</artifactId>
<version>5.1.0</version>
</dependency>
<dependency>
<groupId>net.sourceforge.owlapi</groupId>
<artifactId>owlapi-distribution</artifactId>
<version>5.1.0</version>
</dependency>
<dependency>
<groupId>ch.securityvision</groupId>
<artifactId>xattrj</artifactId>
<version>1.3</version>
</dependency>
</dependencies>
Thr guice dependency was removed from the 5.x branch of owlapi a few years ago. Try updating owlapi to 5.1.20 and removing the explicit guice dependency in your pom. This should exclude all guice references. If necessary, exclude it from the jfact dependency as well (I have not tried jfact with any java version past 8 but i would expect it to work, it doesn't have any features that are known to be incompatible with newer jdks.
I'm doing a simple spring boot project with a thread pool and MySQL in order to connect to MySQL whenever I'm adding spring-boot-starter-jdbc I'm getting below error.
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dataSource' defined in class path resource [org/springframework/boot/autoconfigure/jdbc/DataSourceConfiguration$Tomcat.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.apache.tomcat.jdbc.pool.DataSource]: Factory method 'dataSource' threw exception; nested exception is java.lang.IllegalStateException: Cannot load driver class: com.mysql.jdbc.Driver
at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:599) ~[spring-beans-4.3.14.RELEASE.jar:4.3.14.RELEASE]
at org.s
Update 1:
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-jdbc</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>com.opencsv</groupId>
<artifactId>opencsv</artifactId>
<version>3.3</version>
</dependency>
</dependencies>
It seems like you are missing mysql-connector dependency,
Add these to your pom.
Maven:
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
</dependency>
or gradle:
compile "mysql:mysql-connector-java:*"
Looks like you forget to add dependency to MySQL (Spring Boot is using H2 database by default), you should add next lines to your pom.xml:
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
</dependency>
First include this in your pom file.
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
</dependency>
Second, clean install the maven project.
If you are using eclipse check your JDK version and maven (Sometime jre is used instead of jdk, so, though in console everything looks fine but acutally the jar is not downloaded)
in short .m2 repo should have this jar file when maven build is done.
Scope "runtime" is good for unit test and container as tomcat etc. when container provide jdbc driver. When run standalone apps (spring-boot) you should remove it or set to "compile".
org.apache.catalina.core.StandardContext listenerStart
SEVERE: Exception sending context initialized event to listener instance of
class org.springframework.web.context.ContextLoaderListener
java.lang.NoClassDefFoundError: org/hibernate/cfg/Configuration
I've goggled my problem but all were giving the same solution to add the hibernate jars in the webapp libraries in the build path which I have done in the first place. Still it is not solved. I have tried different versions of jars. But the problem persists.
please find the webapp library screen shot here
WebApp library
Adding the updated Deployment Assembly
Updated Deployment Assembly
you need to add hibernate dependencies, you can find it below:
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>ejb3-persistence</artifactId>
<version>1.0.2.GA</version>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-annotations</artifactId>
<version>3.5.6-Final</version>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-commons-annotations</artifactId>
<version>3.2.0.Final</version>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-entitymanager</artifactId>
<version>5.1.0.Final</version>
</dependency>
I'm migrating a project that was running on Tomcat 8 to Weblogic.
I am using Hibernate + JPA 2. When I deploy in weblogic got the following error:
Failure occurred in the execution of deployment request with ID "26012160125422" for task "114". Error is: "weblogic.application.ModuleException: java.lang.NoSuchMethodError: javax.persistence.JoinTable.indexes()[Ljavax/persistence/Index;"
weblogic.application.ModuleException: java.lang.NoSuchMethodError: javax.persistence.JoinTable.indexes()[Ljavax/persistence/Index
Environment
- Java: jdk1.8.0_60
- Weblogic: 12.1.3
- hibernate-entitymanager: 4.3.1.Final
- hibernate-core: 4.3.1.Final
- javaee-api: 7.0
pom.xml
<dependencies>
<dependency>
<groupId>javax</groupId>
<artifactId>javaee-api</artifactId>
<version>7.0</version>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-core</artifactId>
<version>4.3.1.Final</version>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-entitymanager</artifactId>
<version>4.3.1.Final</version>
</dependency>
<dependency>
<groupId>com.microsoft.sqlserver</groupId>
<artifactId>sqljdbc4</artifactId>
<version>4.0</version>
</dependency>
</dependencies>
It is strange that you use javaee-api-7.0.jar, Hibernate 4 has hibernate-jpa-2.1-api-1.0.0.Final.jar as a dependency. But it is not a reason of the error.
JoinTable.indexes() was added with Java Persistence 2.1. So you just have an old jar with JoinTable annotation in the classpath (in the Weblogic default lib folders).
To check where is this jar, run this code before the Hibernate configuration code
URL joinTableUrl = Thread.currentThread().getContextClassLoader()
.getResource(
"javax/persistence/JoinTable.class");
System.out.println(joinTableUrl);
To check JoinTable has indexes() method
Class<?> joinTable = Thread.currentThread().getContextClassLoader()
.loadClass(JoinTable.class.getName());
System.out.println(Arrays.asList(joinTable.getDeclaredMethods()));
I wrote a Client that uses a Webservice.
Works well in a seperate project. But when I try to use it in my maven project, it fails.
The dependencies are correct:
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-rt-frontend-jaxws</artifactId>
<version>2.2.8</version>
</dependency>
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-rt-transports-http</artifactId>
<version>2.2.8</version>
</dependency>
<!-- Jetty is needed if you're are not using the CXFServlet -->
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-rt-transports-http-jetty</artifactId>
<version>2.2.8</version>
</dependency>
But the error seems to occur calling this method:
JaxWsProxyFactoryBean.create();
This is what I get:
10.06.2010 12:50:59 org.apache.cxf.service.factory.ReflectionServiceFactoryBean buildServiceFromClass
INFO: Creating Service {http://tempuri.org/}BMWebServiceSoapService from class net.myClassPath.BMWebServiceSoap
2010-06-10 12:51:00.992::WARN: Nested in org.springframework.web.util.NestedServletException: Handler processing failed; nested exception is java.lang.NoClassDefFoundError: javax/wsdl/extensions/soap12/SOAP12Address:
java.lang.NoClassDefFoundError: javax/wsdl/extensions/soap12/SOAP12Address
Does anyone have a clue?
Thanks!
Do a maven dependncy:tree or similar. It LOOKS like you are picking up an old or bad version of wsdl4j.
Dan