I have a Spring framework based Java web application, which has been built in SpringSource Tool Suite ("STS"), and a local copy of Apache Tomcat. We also have a internal production server, again running Tomcat.
When I run the application on my development machine, and carry out a specific action in the web application, everything works correctly. However, when I deploy the web application to Tomcat on the server (via a war file produced by maven), and repeat those aforementioned specific actions, I'm presented with some unexpected behaviour. When I checked the server tomcat log file, I found this...
2011-11-16 19:36:45,090 [http-8280-Processor1] ERROR [attachments] invoke - Servlet.service() for servlet attachments threw exception java.lang.NoSuchMethodError: net.wmfs.coalesce.aa.dao.MediaDao.updateAlfrescoNodeRef(Ljava/lang/Long;Ljava/lang/String;)V
at net.wmfs.coalesce.aa.service.impl.MediaServiceImpl.doFileUpload(MediaServiceImpl.java:102)
at net.wmfs.coalesce.aa.servlet.MediaServlet.doFileUpload(MediaServlet.java:83)
at net.wmfs.coalesce.aa.servlet.MediaServlet.doPost(MediaServlet.java:55)
Now, the updateAlfrescoNodeRef method definitly exists in the MediaDao class - otherwise my code would not compile in STS...
package net.wmfs.coalesce.aa.dao;
public class MediaDao extends JdbcDaoSupport {
public void updateAlfrescoNodeRef(final Long recordId, final String nodeRef) {
// java code
}
}
As you can see, the method signature is correct.
I suspected that there may have been a problem when maven produced the war file, so I extracted the war files contents. In the WEB-INF/lib folder, I found the jar file which holds the MediaDao class, and extracted its contents. I then did a...
cat ./MediaDao.class
Now, as class files are binary files, I mostly saw gobledegook. However, I was able to clearly make out references to the updateAlfrescoNodeRef method, as well as the contents of a String in that method. So, this means that the method is definitely there.
The bean configuration in the Spring framework XML files is definitely correct, or the code would not run when I execute it on my development machine.
Googling suggested a library conflict on the server, but all the referenced classes - MediaServlet, MediaServiceImpl, MediaDao - are in the main project (the one with the WEB-INF folder in it). While its conceivable there may be multiple copies of the dependencies on the server, there is definitely only one copy of the main project jar.
Does anyone have any ideas why this is happening?
javap -classpath <your-jar-file> net.wmfs.coalesce.aa.dao.MediaDao
and it should list the method signatures. docs – ModalMediaServiceImpl.doFileUpload(MediaServiceImpl.java:102)
. Also the declaration ofMediaDao
, whether it isMediaDao mediaDao
orJdbcDaoSupport MediaDao
? – BautzenMediaServiceImpl
class has aprivate
property namedmediaDao
of typeMediaDao
. The class has a standard setter method so that Spring can inject the dependency using the bean definition xml files. Those files have a<bean id="mediaDao" class="net.wmfs.coalesce.aa.dao.MediaDao">
(with the required properties). It also has a<bean id="mediaProcessor" class="net.wmfs.coalesce.aa.service.impl.MediaServiceImpl">
, which has a<property name="mediaDao" ref="mediaDao"/>
line. The method calling line ismediaDao.updateAlfrescoNodeRef(upload.getId(), nodeRef);
– MonodramamediaDao.updateAlfrescoNodeRef(upload.getId(), nodeRef);
passes two parameters. Theupload.getId()
method returns a java.lang.Long, andnodeRef
is a java.lang.String. – Monodramapublic void updateAlfrescoNodeRef(Long recordId, String nodeRef)
method. Thanks for your efforts Kowser. – Monodrama