ClassNotFoundException DispatcherServlet(Tomcat 7.0.32,Spring 3.1.1,web-app 3.0,JSP,AWS,maven)

时间:2012-10-12 13:01:54

标签: spring maven web-applications tomcat7

我在创建web-app 3.0应用程序时遇到了很多问题。我设法使用google和stackoverflow以及其他论坛解决了很多问题...但现在我不仅仅是困惑。我对Web应用程序和Spring完全不熟悉。我想使用Spring 3.1库在Tomcat 7 localhost(之后是AWS的Tomcat 7)上创建我的第一个WORKING App(web-app 3.0)。在安装了大量的eclipse插件之后(AWS Toolkit for Eclipse,Maven Integration for Eclipse,Maven Integration for Eclipse WTP,APT M2E Con​​nector ......)我在Eclipse上与Spring有足够的争执。现在我不想用taglib来解决我的问题:

  

PA? 12,2012 1:24:58 PM org.apache.catalina.startup.TaglibUriRule body   信息:TLD被跳过。 URI:http://java.sun.com/jstl/core_rt已定义)

但我提到它,因为可能与案件有某种联系。

我在使用冲突的Spring库之前遇到了一些问题 - 我已经从AWS SDK for Java库中删除了那些(版本3.0.7.RELEASE),所以现在项目启动并且正在显示index.jsp,但是我可以在控制台日志中看到:

  

pa? 12, 2012 1:25:00 PM org.apache.catalina.core.StandardContext loadOnStartup SEVERE: Servlet /HL_WMS threw load() exception java.lang.ClassNotFoundException: com.springframework.web.servlet.DispatcherServlet at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1714) at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1559) at org.apache.catalina.core.DefaultInstanceManager.loadClass(DefaultInstanceManager.java:532) at org.apache.catalina.core.DefaultInstanceManager.loadClassMaybePrivileged(DefaultInstanceManager.java:514) at org.apache.catalina.core.DefaultInstanceManager.newInstance(DefaultInstanceManager.java:133) at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1136) at org.apache.catalina.core.StandardWrapper.load(StandardWrapper.java:1080) at org.apache.catalina.core.StandardContext.loadOnStartup(StandardContext.java:5027) at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5314) at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150) at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1559) at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1549) at java.util.concurrent.FutureTask$Sync.innerRun(Unknown Source) at java.util.concurrent.FutureTask.run(Unknown Source) at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source) at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source) at java.lang.Thread.run(Unknown Source) pa? 12, 2012 1:25:00 PM org.apache.coyote.AbstractProtocol start INFO: Starting ProtocolHandler ["http-bio-8080"] pa? 12, 2012 1:25:00 PM org.apache.coyote.AbstractProtocol start INFO: Starting protocolHandler ["ajp-bio-8009"] pa? 12, 2012 1:25:00 PM org.apache.catalina.startup.Catalina start INFO: Server startup in 3748 ms

我不明白,因为正在加载页面并且库被部署到WEB-INF / lib目录中(workspace.metadata.plugins \ org.eclipse.wst.server.core \ tmp0 \ wtpwebapps \ myexample \ WEB-INF \ lib)。我已经阅读了一个stackoverflows线程,手动将缺少的库添加到eclipse项目/ WEB-INF / lib目录中,但它没有帮助。 我究竟做错了什么?您可以在下面找到我的pom.xml,web.xml,myexample-servlet.xml,控制器源,控制器源,home.jsp ...以及我的文件夹结构。

的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>myexample</groupId>
<artifactId>myexample</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>war</packaging>

<properties>
    <org.springframework.version>3.1.1.RELEASE</org.springframework.version>
    <org.springframework.security.version>3.1.1.RELEASE</org.springframework.security.version>
    <org.apache.tiles>3.0.0</org.apache.tiles>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>


<build>
    <sourceDirectory>src</sourceDirectory>
    <resources>
        <resource>
            <directory>src</directory>
            <excludes>
                <exclude>**/*.java</exclude>
            </excludes>
        </resource>
    </resources>
    <plugins>
        <plugin>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>2.3.2</version>
            <configuration>
                <source>1.7</source>
                <target>1.7</target>
            </configuration>
        </plugin>
        <plugin>
            <artifactId>maven-war-plugin</artifactId>
            <version>2.2</version>
            <configuration>
                <warSourceDirectory>WebContent</warSourceDirectory>
                <failOnMissingWebXml>false</failOnMissingWebXml>
            </configuration>
        </plugin>
    </plugins>
</build>

<repositories>
    <repository>
        <id>repository.springframework.maven.release</id>
        <name>Spring Framework Maven Release Repository</name>
        <url>http://maven.springframework.org/release</url>
    </repository>
    <repository>
        <id>java.net2</id>
        <name>Repository hosting the jee6 artifacts</name>
        <url>http://download.java.net/maven/2</url>
    </repository>
</repositories>

<dependencies>

    <dependency>
        <groupId>javax.servlet</groupId>
        <artifactId>javax.servlet-api</artifactId>
        <version>3.0.1</version>
        <!-- scope>provided</scope-->
    </dependency>
    <dependency>
        <groupId>javax.servlet</groupId>
        <artifactId>jstl</artifactId>
        <version>1.2</version>
    </dependency>
    <!--dependency> <groupId>org.glassfish.web</groupId> <artifactId>javax.servlet.jsp.jstl</artifactId> 
        <version>1.2.1</version> </dependency> <dependency> <groupId>javax.servlet.jsp.jstl</groupId> 
        <artifactId>javax.servlet.jsp.jstl-api</artifactId> <version>1.2.1</version> 
        </dependency -->
    <dependency>
        <groupId>org.glassfish.web</groupId>
        <artifactId>jstl-impl</artifactId>
        <version>1.2</version>
        <exclusions>
            <exclusion>
                <artifactId>servlet-api</artifactId>
                <groupId>javax.servlet</groupId>
            </exclusion>
            <exclusion>
                <artifactId>jsp-api</artifactId>
                <groupId>javax.servlet.jsp</groupId>
            </exclusion>
            <exclusion>
                <artifactId>jstl-api</artifactId>
                <groupId>javax.servlet.jsp.jstl</groupId>
            </exclusion>
        </exclusions>
    </dependency>
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-core</artifactId>
        <version>${org.springframework.version}</version>
        <exclusions>
            <exclusion>
                <artifactId>commons-logging</artifactId>
                <groupId>commons-logging</groupId>
            </exclusion>
        </exclusions>
    </dependency>
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-beans</artifactId>
        <version>${org.springframework.version}</version>
    </dependency>
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-context</artifactId>
        <version>${org.springframework.version}</version>
    </dependency>
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-web</artifactId>
        <version>${org.springframework.version}</version>
    </dependency>
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-webmvc</artifactId>
        <version>${org.springframework.version}</version>
    </dependency>
    <dependency>
        <groupId>org.springframework.security</groupId>
        <artifactId>spring-security-web</artifactId>
        <version>${org.springframework.security.version}</version>
    </dependency>
    <dependency>
        <groupId>org.springframework.security</groupId>
        <artifactId>spring-security-config</artifactId>
        <version>${org.springframework.security.version}</version>
    </dependency>
</dependencies>

的web.xml

<?xml version="1.0" encoding="UTF-8"?><web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
id="WebApp_ID" version="3.0">
<display-name>myexample</display-name>
<welcome-file-list>
    <!-- welcome-file>index.html</welcome-file>
    <welcome-file>index.htm</welcome-file-->
    <welcome-file>index.jsp</welcome-file>
    <!-- welcome-file>default.html</welcome-file>
    <welcome-file>default.htm</welcome-file>
    <welcome-file>default.jsp</welcome-file-->
</welcome-file-list>
<listener>
    <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<context-param>
    <param-name>contextConfigLocation</param-name>
    <param-value>
        /WEB-INF/spring-security.xml
    </param-value>
</context-param>
<filter>
    <filter-name>springSecurityFilterChain</filter-name>
    <filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class>
</filter>
<filter-mapping>
    <filter-name>springSecurityFilterChain</filter-name>
    <url-pattern>/*</url-pattern>
</filter-mapping>
<servlet>
    <servlet-name>myexample</servlet-name>
    <servlet-class>com.springframework.web.servlet.DispatcherServlet</servlet-class>
    <load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
    <servlet-name>wms</servlet-name>
    <url-pattern>*.html</url-pattern>
</servlet-mapping>
<!-- servlet-mapping> <servlet-name>default</servlet-name> <url-pattern>*.js</url-pattern> 
    </servlet-mapping> <servlet-mapping> <servlet-name>default</servlet-name> 
    <url-pattern>*.css</url-pattern> </servlet-mapping --></web-app>

myexample中-servlet.xml中

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:context="http://www.springframework.org/schema/context" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.springframework.org/schema/beans  
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd    
http://www.springframework.org/schema/context   
http://www.springframework.org/schema/context/spring-context-3.0.xsd "> 
<context:component-scan base-package="com.hldisplay.wms.controller"/>   
<bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver">  
    <property name="viewClass"
        value="org.springframework.web.servlet.view.JstlView" />
    <property name="prefix" value="/WEB-INF/jsp/"/> 
    <property name="suffix" value=".jsp"/>  
</bean>
<!--bean name="/home.jsp" class="com.hldisplay.wms.controller.HomePageController"/--></beans>   

HomePageController.java

package com.myexample.controller;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.AbstractController;
@Controller
public class HomePageController extends AbstractController {    
@RequestMapping("/home")
protected ModelAndView handleRequestInternal(
        HttpServletRequest httpServletRequest,
        HttpServletResponse httpServletResponse) throws Exception {
    ModelAndView mv = new ModelAndView();
    mv.setViewName("home");
    return mv;
}
}

针对home.jsp

<%@ page language="java" contentType="text/html; charset=utf-8" pageEncoding="utf-8"%>
<%@ page import="org.springframework.web.context.*" %>
<%@ page import="org.springframework.asm.*" %>
<!--%@ taglib prefix="sec" uri="http://www.springframework.org/security/tags" %-->
<%
 * Here, we report success as long as the app server is up, but skip
 * generating the whole page since this is a HEAD request only. You
 * can employ more sophisticated health checks in your application.
 */
if (request.getMethod().equals("HEAD")) return;
%>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-type" content="text/html; charset=utf-8">
<title>myexample</title>
<link rel="stylesheet" href="styles/styles.css" type="text/css" media="screen">
</head>
<body>
<div id="content" class="container">
<div class="public">
    <h2>Public:</h2>
        <ul>
        public text
    </ul>
</div>
<sec:authorize> <!-- ifAllGranted="ROLE_ADMIN"-->
    <div class="private">
    <h2>Private:</h2>
    <ul>
        private text
    </ul>
</div>
</sec:authorize>
</div>
</body>
</html>

我不是专家,但不应该使用该配置吗?我错过了什么吗?当然我已经让maven干净了(项目[右键单击] - &gt;运行 - &gt; maven清理)并重新启动eclipse ...请告诉我(对不起那篇长篇文章)。

0 个答案:

没有答案