I have a simple Spring MVC application that looks up some user details from an LDAP server and prints out a simple HTML page using a JSP. The application works fine on Tomcat 6. It uses Spring LDAP 1.3.1 and LDAPTemplate to do the LDAP lookups.
However, when I deploy this application WAR to Websphere 7, the app doesn't run -- Websphere returns a 500 Internal server error. Looking at Websphere's log file, I see
[14/12/10 14:50:09:169 GMT] 00000022 DispatcherSer E org.springframework.web.servlet.FrameworkServlet initServletBean Context initialization failed
org.springframework.beans.factory.CannotLoadBeanClassException: Error loading class [org.springframework.ldap.core.support.LdapContextSource] for bean with name 'contextSource' defined in ServletContext resource [/WEB-INF/spring-servlet.xml]: problem with class file or dependent class; nested exception is java.lang.NoClassDefFoundError: org.springframework.beans.factory.InitializingBean
at org.springframework.beans.factory.support.AbstractBeanFactory.resolveBeanClass(AbstractBeanFactory.java:1253)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.predictBeanType(AbstractAutowireCapableBeanFactory.java:576)
at org.springframework.beans.factory.support.AbstractBeanFactory.isFactoryBean(AbstractBeanFactory.java:1319)
at org.springframework.beans.factory.support.AbstractBeanFactory.isFactoryBean(AbstractBeanFactory.java:885)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:562)
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:895)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:425)
My web-inf\lib directory has all the JAR files, including org.springframework.beans-3.0.5.RELEASE.jar, which contains InitializingBean. I'm therefore not sure why Websphere is reporting the class as missing.
Contents of my web-inf\lib:
aopalliance.jar
com.springsource.org.apache.commons.logging-1.1.1.jar
com.springsource.org.apache.log4j-1.2.15.jar
commons-lang-2.5.jar
commons-logging-1.1.1.jar
commons-pool-1.5.4.jar
jstl-api-1.2.jar
jstl-impl-1.2.jar
ldapbp-1.0.jar
org.springframework.aop-3.0.5.RELEASE.jar
org.springframework.asm-3.0.5.RELEASE.jar
org.springframework.beans-3.0.5.RELEASE.jar
org.springframework.context-3.0.5.RELEASE.jar
org.springframework.core-3.0.5.RELEASE.jar
org.springframework.expression-3.0.5.RELEASE.jar
org.springframework.jdbc-3.0.5.RELEASE.jar
org.springframework.oxm-3.0.5.RELEASE.jar
org.springframework.transaction-3.0.5.RELEASE.jar
org.springframework.web-3.0.5.RELEASE.jar
org.springframework.web.servlet-3.0.5.RELEASE.jar
spring-ldap-1.3.1.RELEASE-all.jar
And here's the definition of the contextSource bean which Websphere is having trouble loading (the username/password is valid and works with Tomcat):
<bean id="contextSource" class="org.springframework.ldap.core.support.LdapContextSource">
<property name="url" value="ldaps://moo.example.com:1300/" />
<property name="userDn" value="CN=foo,OU=baz,DC=bar,DC=blat,DC=org" />
<property name="password" value="*******" />
</bean>
I'd be very glad if someone could point out why this isn't working on Websphere. I'm not too sure about class-loading rules in Websphere and would appreciate any advice on this.
Turn on Class Loading trace. This would tell you what classes are loaded and from which Jar. As Sajan mentioned chances are that there are duplicate jars in the classpath and the classloader that you expect has not loaded this class (and a parent class loader has likely loaded a class).
NoClassDefFoundError (NCDFE) does mean it could not locate the class that it is looking for. Errors in static initialization would explicitly turn out as a "java.lang.ExceptionInInitializerError" (EIIE)
"
Both NCDFE and EIIE extend from Linkage error.
In general all these errors can easily be troubleshooted by turning on the class loading for the Server. Also use the Class Loader Viewer available in the admin console to aid in your troubleshooting activities.
HTH
Manglu
This is a sticky and common exception. Remember, that NoClassDefFoundError doesn't mean the class was not found, rather it means:
NoClassDefFoundError: The given class
could be found, but something went
wrong when initializing it (an
interface it implemented could not be
found, something went wrong in a
static initializer etc.).
From here.
Please check that you don't have the same class in any other possible jar
Please check if you have added the dependencies in pom.xml file.
Related
I know that this error already appears on stackoverflow and normally it translates to a classpath problem. In my case this is my context:
Application Server: Weblogic 10.3.6
Using Spring 4 + log4j.
Weblogic User domain lib folder:
log4j-1.2.17.jar
commons-logging-1.1.3.jar
spring-beans-4.1.2.RELEASE.jar
spring-core-4.1.2.RELEASE.jar
spring-jdbc-4.1.2.RELEASE.jar
spring-tx-4.1.2.RELEASE.jar
When I try to use the StoredProcedure spring class (in the context of a Custom Weblogic Authenticator) I have this error:
<10/Fev/2015 17H27m GMT> <Error> <org.apache.beehive.netui.pageflow.internal.AdapterManager> <BEA-00
0000> <ServletContainerAdapter manager not initialized correctly.>
org.apache.commons.logging.LogConfigurationException: User-specified log class 'org.apache.commons.logging.impl.Log4JLogger' cannot be found or is not useable.
at org.apache.commons.logging.impl.LogFactoryImpl.discoverLogImplementation(LogFactoryImpl.j
ava:874)
at org.apache.commons.logging.impl.LogFactoryImpl.newInstance(LogFactoryImpl.java:604)
at org.apache.commons.logging.impl.LogFactoryImpl.getInstance(LogFactoryImpl.java:336)
at org.apache.commons.logging.impl.LogFactoryImpl.getInstance(LogFactoryImpl.java:310)
at org.apache.commons.logging.LogFactory.getLog(LogFactory.java:685)
at org.springframework.jdbc.object.RdbmsOperation.<init>(RdbmsOperation.java:59)
at org.springframework.jdbc.object.SqlCall.<init>(SqlCall.java:78)
at org.springframework.jdbc.object.StoredProcedure.<init>(StoredProcedure.java:58)
I believe that this got something to do with the version of log4j or commons-logging (or eventually a dependency of Spring 4 that I'm missing.. like slf4j, althought I don't think this is required).
Does anyone has any ideas about this?
Thanks in advance
Best regards
João Simas
Thanks "Display Name is missing" for the provided link:
[http://docs.oracle.com/cd/E24329_01/web.1211/e24368/classloading.htm#WLPRG282][1]
The solution was creating a dedicated User Domain and redeploying the jars. Everything worked as expected.
João Simas
I am currently trying to start up a server side of an application, built with Maven; the clean install is succesful, but then tomcat7:run fails with the following Spring error message
04:21:19,059 [localhost-startStop-1] ERROR org.springframework.web.context.ContextLoader -
Context initialization failed org.springframework.beans.factory.BeanCreationException:
Error creating bean with name 'properties' defined in class path resource [context.xml]:
Initialization of bean failed; nested exception is java.lang.NoSuchMethodError:
org.springframework.core.convert.Property.<init>(Ljava/lang/Class;Ljava/lang/reflect/Method;
Ljava/lang/reflect/Method;Ljava/lang/String;)V
The concerned bean definition in context.xml is as follows
<bean id="properties" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="location" value="classpath:server.properties"/>
<property name="ignoreUnresolvablePlaceholders" value="true"/>
</bean>
Research shows that these kind of errors are usually related to incorrect JAR versions on the classpath. In this particular application, Spring version 3.2.4.RELEASE dependencies are defined in Maven pom.xml, and checking out the API of the concerned org.springframework.core.convert.Property class it seems that constructor Property(Class objectType, Method readMethod, Method writeMethod, String name) is actually available in this version. Any ideas are appreciated
Try to run your java with -verbose option.
It shows wich jar has been loaded class from.
Looks like there is a spring jar in the bootstrap classloader of your Tomcat - older version of Spring.
I am developing a webapp in cloudbees platform and trying to add functionality for sending mail.
I am following https://wiki.cloudbees.com/bin/view/RUN/SendGrid documentation and as per the document we can get the mail session using below:
Context initCtx = new InitialContext();
Session session = (Session) initCtx.lookup("java:comp/env/mail/SendGrid");
But when running thie code in cloud i am getting:
java.lang.ClassCastException: javax.mail.Session cannot be cast to javax.mail.Session.
the problem seems to be with javax.mail.jar
i have downloaded the latest jar from https://java.net/projects/javamail/pages/Home .
As i understand the version which is required in cloud bees is different from what i am deploying.Can anyone help in getting correct jar for this particular purpose.
Note: I have added send grid to my stack in cloudBees.
I think you have more than one version of the javax.mail.
Indeed, the java mail session jars should be already provided by the container.
You can refer to this, as example: https://github.com/CloudBees-community/tomcat7-sendgrid-clickstart/blob/master/pom.xml
Try to remove your mail jar and if it still does not work and you are using maven try using the dependency plugin with
mvn dependency:tree -Dverbose
to check if you have conflicts with mails dependencies.
Duplicate Problem Resolved with Spring Framework on Cloudbees
I had the same problem only from Spring and can confirm it was from including javax-mail in the Maven dependencies (which also brings in the mail jar). After taking out the dependency/jar file I was having a problem with the constructor for org.springframework.mail.javamail.JavaMailSenderImpl not liking the type of the argument from jndi, however. At least the original error seemed to be objecting to the same class rather than saying it didn't know the type/name/etc. Finally, taking out passing the session to the constructor and putting it in the property (which in theory should do the same thing, I believe) fixed the problem:
<jee:jndi-lookup id="mailSource"
jndi-name="java:comp/env/mail/SendGrid"
expected-type="javax.mail.Session" />
<bean id="mailSender"
class="org.springframework.mail.javamail.JavaMailSenderImpl">
<property name="session" ref="mailSource" />
</bean>
I'm trying to deploy an app on tomcat 7 that uses spring 3.1.1 and weblogic 10.3, but I keep getting a NoClassDef exception:
java.lang.NoClassDefFoundError: Could not initialize class weblogic.jndi.Environment at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:506) ~[spring-beans-3.1.1.RELEASE.jar:3.1.1.RELEASE]
I've double checked and and the weblogic jar is present on WEB-INF/lib and it does contain said class:
jar tf WEB-INF/lib/weblogic.jar | grep /Environment.class
weblogic/cluster/messaging/internal/Environment.class
weblogic/jndi/Environment.class
org/mozilla/javascript/tools/shell/Environment.class
this happens when a spring bean factory tries to build this bean on my root-context.xml
<beans:bean
id="jmsConnectionFactory"
class="org.springframework.jndi.JndiObjectFactoryBean"
p:jndiTemplate-ref="jndiTemplate"
p:jndiName="weblogic.jms.ConnectionFactory" />
I thought it might be some classpath issue, but I have been playing around with the MANIFEST.MF of the webapp and this problematic jars(spring & weblogic) for a while now, without any luck.
Any ideas on what can be causing this?
I believe using weblogic.jar directly in the classpath does not work. You need to create wlfullclient.jar and put it in WEB-INF/lib.
Follow the instructions given here: http://middlewaremagic.com/weblogic/?p=558
I'm having problems deploying a simple WebServices app (like "Hello World" simple) to OC4J. The same code works fine under Jetty, but breaks in OC4J, and I'm wondering if anyone else has faced the same issue. I'm using Enterprise Manager to deploy the app, but the deployment fails with this message:
[Jan 23, 2009 8:46:20 AM] Binding TestWs web-module for application TestWs to site default-web-site under context root /TestWs
[Jan 23, 2009 8:46:22 AM] Operation failed with error: Configuration problem: Unable to locate Spring NamespaceHandler for XML schema namespace [http://cxf.apache.org/jaxws]
Offending resource: ServletContext resource [/WEB-INF/beans.xml]
Looking at the beans.xml, the offending code seems to be the XML namespace declarations:
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:jaxws="http://cxf.apache.org/jaxws"
xsi:schemaLocation="
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://cxf.apache.org/jaxws http://cxf.apache.org/schemas/jaxws.xsd">
<import resource="classpath:META-INF/cxf/cxf.xml" />
<import resource="classpath:META-INF/cxf/cxf-extension-soap.xml" />
<import resource="classpath:META-INF/cxf/cxf-servlet.xml" />
<jaxws:endpoint
id="helloService"
implementor="com.test.endpoint.HelloImpl"
address="/HelloWorld" />
</beans>
The stack trace is not terribly illuminating:
09/01/23 08:57:28 oracle.oc4j.admin.internal.DeployerException: Configuration problem: Unable to locate Spring NamespaceHandler for XML schema namespace [http://cxf.apache.org/jaxws]
Offending resource: ServletContext resource [/WEB-INF/beans.xml]
09/01/23 08:57:28 at org.springframework.beans.factory.parsing.FailFastProblemReporter.error(FailFastProblemReporter.java:68)
09/01/23 08:57:28 at org.springframework.beans.factory.parsing.ReaderContext.error(ReaderContext.java:85)
09/01/23 08:57:28 at org.springframework.beans.factory.parsing.ReaderContext.error(ReaderContext.java:80)
09/01/23 08:57:28 at org.springframework.beans.factory.xml.BeanDefinitionParserDelegate.error(BeanDefinitionParserDelegate.java:261)
09/01/23 08:57:28 at org.springframework.beans.factory.xml.BeanDefinitionParserDelegate.parseCustomElement(BeanDefinitionParserDelegate.java:1120)
...
Has anyone else run into similar problems? And if so, what's the best way to go about fixing it? My XML skills are middling, and I'm a complete noob with WebServices. But this may be an OC4J issue.
Thanks in advance for your help!
EDIT: This is not, as far as I can tell, a classpath issue, unless OC4J is odd about what jars it want to see where (as I know Tomcat can be). My WEB-INF/lib folder has the CXF jar, the Spring jars (beans, context, core, and web), xml-resolver-1.2.jar, and XmlSchema-1.4.2.jar. If I need to list everything in the WEB-INF/lib folder, I will. But again, the program works in Jetty.
Another Edit: Based on what I'm reading here, this appears to be an issue between Spring and the CXF jar -- there's a NamespaceHandler class in the CXF jar (in org.apache.cxf.frontend.spring to be precise), but there seems to be a configuration issue preventing Spring from seeing it.
Last Edit: Thank you everyone for your help. I never ended up getting CXF working in OC4J, because my client is on version 10.1.3.3.0. It's not J2EE 5 compliant, and I'm pretty sure they're not going to go for unpacking their oc4j.jar in order to change the boot.xml. But without the document Daniel pointed me to, I never would have known that.
So I switched to XFire version 1.2.6, and got my test app working after a few hiccups. Along the way I learned some interesting things about OC4J:
When deploying in Enterprise Manager, make sure you choose to load the local classpath first.
OC4J uses non-standard XML files, so make sure your app is not using any of OC4J's native XML files (in the Deployment Settings, uncheck all the currently selected imports -- that way, you can ensure that the app is using only files you provide in WEB-INF/lib)
If you can, use another app server. :P
Thank you all again!
I hate to ask the obvious, but have you looked at all the stuff for configuring OS4J and CXF together from the CXF web site?
http://cwiki.apache.org/CXF20DOC/appserverguide.html#AppServerGuide-OC4J
Looks like a configuration issue with Spring:
Configuration problem: Unable to locate Spring NamespaceHandler for XML schema namespace [http://cxf.apache.org/jaxws]
Offending resource: ServletContext resource [/WEB-INF/beans.xml]
Do you have anything in your web.xml to read that when the app starts up? Do you see a NamespaceHandler declared for that namespace anywhere in your code?
I would think its a CLASSPATH issue.
I'm not that familiar with OC4J, but how are you packaging/deploying your web-application?
You need to ensure that the CXF jar is in the WEB-INF/lib directory of your WAR?
Update: A little confused by your comments - if your spring config is in the META-INF directory of your EAR, then this is not the same classpath as that used by your web-app. So, in fact, sticking the CXF jar in WEB-INF/lib isn't going to work. You will either need to stick the JAR in the top-level of your EAR, or in some lib shared by all classloaders of OC4J. I suggest studying the enterprise-app/web-app classloader hierarchy documentation of OC4J to see if this can give more advice?