Spring can't find a lib and webapp doesn't start up in tomcat 6
I've this problem using STS: I'm building a simple Spring app, just to try out features like MVC and persistence. Now I've 开发者_StackOverflowcreated something very simple, out of a bunch of tutorials for Spring 3, that I'm using. The application fails with this, during server startup:
Code:
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping#0': Initialization of bean failed; nested exception is org.springframework.beans.factory.CannotLoadBeanClassException: Cannot find class [org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean] for bean with name 'mySessionFactory' defined in ServletContext resource [/WEB-INF/spring/appServlet/servlet-context.xml]; nested exception is java.lang.ClassNotFoundException: org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean
but I've org.springframework.orm
in web-inf/classes
folder (I even tried putting it in web-inf/lib
). As I copied these libs there, the came out in Web App Libraries folder. Building this project in STS works fine as this dependency is set up in build path throught project properties, but how do I transfer the libs to the web app? (I'm using Tomcat 6 as it is the server I'm going to use sometime in the future for production). Is this a config problem of my XML? Or am I just missing the right way to put this lib? (I encountered the same problem before, but adding the needed lib in classes worked it out). More than this I that if I browse inside my workspace to the folder where the working folder of tomcat should be, I can't find any work directory and any commo
Go to the Servers
view and double click on Tomcat Server
which will open up a Tomcat Overview page. This will show you the server path and deploy path which Eclipse is using to publish your webapps to.
For example, mine are:
Server path: .metadata\.plugins\org.eclipse.wst.server.core\tmp0
Deploy path: wtpwebapps
Now in a Command Prompt (or Explorer) browse to %ECLIPSE_HOME%\workspaces\default\.metadata\.plugins\org.eclipse.wst.server.core\tmp0\wtpwebapps
and you should see your webapp. Go into the WEB-INF\lib directory and check if your jar is there.
A few things to try:
If the jar is not in WEB-INF\lib, you might need to republish it. Right-click on the Tomcat in the Servers view and click
Publish
. Does it appear? If not, Right-click on the Tomcat again and this time selectClean...
which will clean out everything and republish. If this doesn't work, the brute force approach would be to delete the files manually and then tell Eclipse to republish them.Clean your work directory, by right-clicking the webapp under Tomcat in the Servers view and selecting
Clean module work directory
. Or do it manually by deleting from%ECLIPSE_HOME%\workspaces\default\.metadata\.plugins\org.eclipse.wst.server.core\tmp0\work\Catalina\localhost
You should also try closing-reopening/cleaning/rebuilding/refreshing your webapp project just in case Eclipse hasn't picked up the changes.
You need to put the various Spring JARs into your WEB-INF/lib
directory (WEB-INF/classes
is no use for JAR files).
You don't just need org.springframework.orm
, you need most of them (see here for dependency diagram).
At least the libary jar files must be located at WEB-INF/lib
within your war file. And you only need to deploy the war file to your productiv web server.
If you use STS but your Project is not a Maven project: then you need to put the files in
<projectRoot>/WebContent/WEB-INF/libs
.(to build the war with Eclipse/STS you need to execute Export/Web/WAR file.)If you use Maven, then you need the specify your dependencies in the pom.xml, and use maven to package the war (run as/Maven package).
精彩评论