将petclinic在eclipse中跑起来

代码在此

https://src.springframework.org/svn/spring-samples/petclinic

先svn co到本地

然后打开indigo jee,导入工程,应该会自动编译吧,此时会自动下载依赖的jar包本地maven仓库。。。

不听话的话就在工程上右键Maven>Update Project..

接下来Add and Deploy到Tomat6.0.22上去,尝试启动tomcat。你妹的。。报错:

java.lang.ClassNotFoundException: org.springframework.web.context.ContextLoaderListener

解决方法在此,太详细了:

http://stackoverflow.com/questions/6210757/java-lang-classnotfoundexception-org-springframework-web-context-contextloaderl

粘贴到此处以防不测:

I had a similar problem when running a spring web application in an Eclipse managed tomcat. I solved this problem by adding maven dependencies in the project's web deployment assembly.

1) Open the project's properties (e.g., right-click on the project's name in the project explorer and select "Properties")
2) select "Deployment Assembly"
3) Click the "Add..." button on the right margin
4) Select "Java Build Path Entries" from the menu of Directive Type and click "Next"
5) Select "Maven Dependencies" from the Java Build Path Entries menu and click "Finish".

You should see "Maven Dependencies" added to the Web Deployment Assembly definition.

然后重启,访问http://localhost:8080/petclinic/

继续报错:
严重: Servlet.service() for servlet jsp threw exception
org.apache.jasper.JasperException: /WEB-INF/jsp/welcome.jsp(1,1) /WEB-INF/jsp/includes.jsp(3,62) Unable to read TLD "META-INF/c.tld" from JAR file "file:/D:/workspaces/cyper_read_source_code/.metadata/.plugins/org.eclipse.wst.server.core/tmp0/wtpwebapps/org.springframework.samples.petclinic/WEB-INF/lib/com.springsource.javax.servlet.jsp.jstl-1.2.0.jar": org.apache.jasper.JasperException: Failed to load or instantiate TagLibraryValidator class: org.apache.taglibs.standard.tlv.JstlCoreTLV

参考这里:
http://stackoverflow.com/questions/3452403/unable-to-read-tld-meta-inf-c-tld

据说是m2eclipse的bug,把scope为provided的东西也扔到了lib目录下。

所以先进入这个目录,

D:\workspaces\cyper_read_source_code\.metadata\.plugins\org.eclipse.wst.server.core\tmp0\wtpwebapps\org.springframework.samples.petclinic\WEB-INF\lib,删除下面两个文件

com.springsource.javax.servlet.jsp-2.1.0.jar

com.springsource.javax.servlet-2.5.0.jar

或者注释掉pom.xml中的如下部分

        <!--
        <dependency>
            <groupId>javax.servlet</groupId>
            <artifactId>com.springsource.javax.servlet</artifactId>
            <version>2.5.0</version>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>javax.servlet</groupId>
            <artifactId>com.springsource.javax.servlet.jsp</artifactId>
            <version>2.1.0</version>
            <scope>provided</scope>
        </dependency> -->

 

再次启动,首页打开了,但是css样式没有取到。
 <link rel="stylesheet" href="/petclinic/static/styles/petclinic.css;jsessionid=4A0FEFF0029D321F71C0147DB505BDA5" type="text/css"/>

你妹的

http://stackoverflow.com/questions/3822524/tomcat-serving-static-content

http://stackoverflow.com/questions/12357101/spring-petclinic-failed-to-load-resource

这里有解决方案:
http://stackoverflow.com/questions/1483063/spring-mvc-3-and-handling-static-content-am-i-missing-something

 

原来petclinic这个例子有些过时了。。我也是这么认为的

 

 

posted @ 2012-09-20 23:10  松柏长青  阅读(479)  评论(0)    收藏  举报