java - 使用 <mvc :annotation-driven/> application is not deploy by tomcat in netbeans 时出错

标签 java spring validation netbeans-7

我正在netbeans中使用spring mvc框架构建一个项目 当我使用<mvc:annotation-driven\>时在project-servlet.xml中项目部署失败

我的代码是

i_am_alive-servlet.xml

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:jee="http://www.springframework.org/schema/jee"
xmlns:lang="http://www.springframework.org/schema/lang"
xmlns:p="http://www.springframework.org/schema/p"
xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:util="http://www.springframework.org/schema/util"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
    http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsd
    http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd
    http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee.xsd
    http://www.springframework.org/schema/lang http://www.springframework.org/schema/lang/spring-lang.xsd
    http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd
    http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util.xsd">

<context:annotation-config />    
<!--<mvc:annotation-driven/>-->
<context:component-scan base-package="i_am_alive.web" />                
<bean id="viewResolver2"
      class="org.springframework.web.servlet.view.UrlBasedViewResolver"
      p:viewClass="org.springframework.web.servlet.view.JstlView"
      p:prefix="/WEB-INF/jsp/"
      p:suffix=".jsp" />

<bean id="viewResolver"
      class="org.springframework.web.servlet.view.InternalResourceViewResolver"
      p:viewClass="org.springframework.web.servlet.view.JstlView"
      p:prefix="/WEB-INF/jsp/"
      p:suffix=".jsp" />

<bean id="messageSource"        class="org.springframework.context.support.ResourceBundleMessageSource">
    <property name="basename" value="messages"/>
</bean>        
</beans>

当我评论时<mvc:annotation-driven\>项目部署成功,但没有进行验证,如果我取消注释 <mvc:annotation-driven\>项目部署失败 添加用户表单.jsp

<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@ include file="/WEB-INF/jsp/include.jsp" %>
<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form" %> 
<!DOCTYPE html>
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>JSP Page</title>
</head>
<body>
    <h1>Hello World!</h1>
    <form:form  action="adduser.htm" modelattribute="user" commandName="user" method="post" >
                        <table>
                            <tr>
                                <td>Username</td>
                                <td><form:input path="username"/></td>
                                <td><form:errors path="username"/></td>
                             </tr>
                             <tr>
                                <td>Email</td>
                                <td><form:input path="email"/></td>
                                <td><form:errors path="email"/></td>
                             </tr>
                             <tr>
                                <td>Password</td>
                                <td><form:input path="password"/></td>
                                <td><form:errors path="password"/></td>
                             </tr>                                 
                        </table>
                             <input type="submit" value="Sign Up" id="btn_sigup"/>
                    </form:form>
</body>
</html>

AddUserFormController.java 包 i_am_alive.web;

import i_am_alive.models.user_account_info;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
@Controller
public class AddUserFomController {

@RequestMapping(value="/adduserform" , method=RequestMethod.GET)    
public String showAddUserForm(ModelMap map){
    map.addAttribute("user",new user_account_info());        
    return "adduserform";
}

@RequestMapping(value="/adduser" , method=RequestMethod.POST)
public String addUserDetail(@ModelAttribute(value="user") user_account_info user,BindingResult result){
    if(result.hasErrors()){
        return "adduserform";
    }
    return "redirect:/welcome.htm";
}

@RequestMapping(value="/welcome" , method=RequestMethod.GET)
public String welcomeUser(){        
    return "welcome";
}
}

欢迎.jsp

<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@ page session="false"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<!DOCTYPE html>
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>JSP Page</title>
</head>
<body>
    <h1>Hello World!</h1>

    <c:out value="${username}"/>
    <c:out value="${user.email}"/>
    <c:out value="${user.password}"/>
</body>
</html>

applicationcontext.xml

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:jee="http://www.springframework.org/schema/jee"
xmlns:lang="http://www.springframework.org/schema/lang"
xmlns:p="http://www.springframework.org/schema/p"
xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:util="http://www.springframework.org/schema/util"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xsi:schemaLocation="
    http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd
    http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
    http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.0.xsd
    http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd
    http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-3.0.xsd
    http://www.springframework.org/schema/lang http://www.springframework.org/schema/lang/spring-lang-3.0.xsd
    http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd
    http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-3.0.xsd">


<bean id="propertyConfigurer"
      class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"
      p:location="/WEB-INF/classes/jdbc.properties" />

<bean id="dataSource"
class="org.springframework.jdbc.datasource.DriverManagerDataSource"
p:driverClassName="${jdbc.driverClassName}"
p:url="${jdbc.url}"
p:username="${jdbc.username}"
p:password="${jdbc.password}"   />
</beans>

web.xml

<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
<context-param>
    <param-name>contextConfigLocation</param-name>
    <param-value>/WEB-INF/i_am_alive-servlet.xml</param-value>
</context-param>
<listener>
    <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<servlet>
    <servlet-name>i_am_alive</servlet-name>
    <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
    <load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
    <servlet-name>i_am_alive</servlet-name>
    <url-pattern>*.htm</url-pattern>
</servlet-mapping>
<session-config>
    <session-timeout>
        30
    </session-timeout>
</session-config>
<welcome-file-list>
    <welcome-file>/index.jsp</welcome-file>
</welcome-file-list>
 <jsp-config>
<taglib>
  <taglib-uri>/spring</taglib-uri>
  <taglib-location>/WEB-INF/tld/spring-form.tld</taglib-location>
</taglib>

user_account_info.java

package i_am_alive.models;

import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.GenerationType;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
import org.hibernate.validator.constraints.Email;
@Entity
public class user_account_info implements java.io.Serializable{    
private long user_account_info_id;
@NotNull @Size(min=6,max=20)
private String username;
@NotNull @Email
private String email;
@NotNull
private String password;
private int role_id;
private String activation_link;
private int account_act_dact;
private String account_dor;
private int account_dirty;

@Id
@GeneratedValue(strategy= GenerationType.IDENTITY)
public long getUser_account_info_id() {
    return user_account_info_id;
}

public void setUser_account_info_id(long user_account_info_id) {
    this.user_account_info_id = user_account_info_id;
}

public String getUsername() {
    return username;
}

public void setUsername(String username) {
    this.username = username;
}

public String getEmail() {
    return email;
}

public void setEmail(String email) {
    this.email = email;
}

public String getPassword() {
    return password;
}

public void setPassword(String password) {
    this.password = password;
}

public int getRole_id() {
    return role_id;
}

public void setRole_id(int role_id) {
    this.role_id = role_id;
}

public String getActivation_link() {
    return activation_link;
}

public void setActivation_link(String activation_link) {
    this.activation_link = activation_link;
}

public int getAccount_act_dact() {
    return account_act_dact;
}

public void setAccount_act_dact(int account_act_dact) {
    this.account_act_dact = account_act_dact;
}

public String getAccount_dor() {
    return account_dor;
}

public void setAccount_dor(String account_dor) {
    this.account_dor = account_dor;
}

public int getAccount_dirty() {
    return account_dirty;
}

public void setAccount_dirty(int account_dirty) {
    this.account_dirty = account_dirty;
}

@Override
public int hashCode() {
    int hash = 7;
    hash = 97 * hash + (int) (this.user_account_info_id ^ (this.user_account_info_id >>> 32));
    hash = 97 * hash + (this.username != null ? this.username.hashCode() : 0);
    hash = 97 * hash + (this.email != null ? this.email.hashCode() : 0);
    hash = 97 * hash + (this.password != null ? this.password.hashCode() : 0);
    return hash;
}

@Override
public boolean equals(Object obj) {
    if (obj == null) {
        return false;
    }
    if (getClass() != obj.getClass()) {
        return false;
    }
    final user_account_info other = (user_account_info) obj;
    if (this.user_account_info_id != other.user_account_info_id) {
        return false;
    }
    if ((this.username == null) ? (other.username != null) : !this.username.equals(other.username)) {
        return false;
    }
    if ((this.email == null) ? (other.email != null) : !this.email.equals(other.email)) {
        return false;
    }
    if ((this.password == null) ? (other.password != null) : !this.password.equals(other.password)) {
        return false;
    }
    return true;
}            
}

消息.属性

NotNull.username=Username cannot be left blank;
NotNull.email=Username cannot be left blank;
NotNull.password=Username cannot be left blank;

错误信息

Incrementally deploying `http://localhost:9090/i_am_alive`
Completed incremental distribution of `http://localhost:9090/i_am_alive`
Incrementally redeploying `http://localhost:9090/i_am_alive`
Start is in progress...
start?path=/i_am_alive
FAIL - Application at context path /i_am_alive could not be started
K:\Advance_Java_Program\i_am_alive\nbproject\build-impl.xml:1039: The module has not been deployed.
See the server log for details.
    BUILD FAILED (total time: 4 seconds)

error log


    Jan 13, 2014 11:12:12 AM org.springframework.context.support.AbstractApplicationContext doClose
INFO: Closing WebApplicationContext for namespace 'i_am_alive-servlet': startup date [Mon    Jan 13 10:19:00 IST 2014]; parent: Root WebApplicationContext
Jan 13, 2014 11:12:12 AM org.springframework.beans.factory.support.DefaultSingletonBeanRegistry destroySingletons
INFO: Destroying singletons in org.springframework.beans.factory.support.DefaultListableBeanFactory@e81070: defining beans [org.springframework.context.annotation.internalConfigurationAnnotationProcessor,org.springframework.context.annotation.internalAutowiredAnnotationProcessor,org.springframework.context.annotation.internalRequiredAnnotationProcessor,org.springframework.context.annotation.internalCommonAnnotationProcessor,org.springframework.context.annotation.internalPersistenceAnnotationProcessor,addUserFomController,loginController,viewResolver2,viewResolver,messageSource,org.springframework.context.annotation.ConfigurationClassPostProcessor$ImportAwareBeanPostProcessor#0]; parent: org.springframework.beans.factory.support.DefaultListableBeanFactory@1da137e
Jan 13, 2014 11:12:12 AM org.springframework.context.support.AbstractApplicationContext doClose
INFO: Closing Root WebApplicationContext: startup date [Mon Jan 13 10:18:58 IST 2014]; root of context hierarchy
Jan 13, 2014 11:12:12 AM org.springframework.beans.factory.support.DefaultSingletonBeanRegistry destroySingletons
INFO: Destroying singletons in org.springframework.beans.factory.support.DefaultListableBeanFactory@1da137e: defining beans [org.springframework.context.annotation.internalConfigurationAnnotationProcessor,org.springframework.context.annotation.internalAutowiredAnnotationProcessor,org.springframework.context.annotation.internalRequiredAnnotationProcessor,org.springframework.context.annotation.internalCommonAnnotationProcessor,org.springframework.context.annotation.internalPersistenceAnnotationProcessor,addUserFomController,loginController,viewResolver2,viewResolver,messageSource,org.springframework.context.annotation.ConfigurationClassPostProcessor$ImportAwareBeanPostProcessor#0]; root of factory hierarchy
Jan 13, 2014 11:12:13 AM org.apache.catalina.startup.TaglibUriRule body
INFO: TLD skipped. URI: http://www.springframework.org/tags/form is already defined
Jan 13, 2014 11:12:13 AM org.apache.catalina.startup.TaglibUriRule body
INFO: TLD skipped. URI: http://www.springframework.org/tags/form is already defined
Jan 13, 2014 11:12:13 AM org.springframework.web.context.ContextLoader initWebApplicationContext
INFO: Root WebApplicationContext: initialization started
Jan 13, 2014 11:12:13 AM org.springframework.context.support.AbstractApplicationContext prepareRefresh
INFO: Refreshing Root WebApplicationContext: startup date [Mon Jan 13 11:12:13 IST 2014]; root of context hierarchy
Jan 13, 2014 11:12:13 AM org.springframework.beans.factory.xml.XmlBeanDefinitionReader loadBeanDefinitions
INFO: Loading XML bean definitions from ServletContext resource [/WEB-INF/i_am_alive-servlet.xml]
Jan 13, 2014 11:12:14 AM org.springframework.web.context.ContextLoader initWebApplicationContext
SEVERE: Context initialization failed
org.springframework.beans.factory.xml.XmlBeanDefinitionStoreException: Line 21 in XML document from ServletContext resource [/WEB-INF/i_am_alive-servlet.xml] is invalid; nested exception is org.xml.sax.SAXParseException; lineNumber: 21; columnNumber: 29; cvc-complex-type.2.4.c: The matching wildcard is strict, but no declaration can be found for element 'mvc:annotation-driven'.
    at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.doLoadBeanDefinitions(XmlBeanDefinitionReader.java:396)
    at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:334)
    at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:302)
    at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:174)
    at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:209)
    at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:180)
    at org.springframework.web.context.support.XmlWebApplicationContext.loadBeanDefinitions(XmlWebApplicationContext.java:125)
    at org.springframework.web.context.support.XmlWebApplicationContext.loadBeanDefinitions(XmlWebApplicationContext.java:94)
    at org.springframework.context.support.AbstractRefreshableApplicationContext.refreshBeanFactory(AbstractRefreshableApplicationContext.java:131)
    at org.springframework.context.support.AbstractApplicationContext.obtainFreshBeanFactory(AbstractApplicationContext.java:522)
    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:436)
    at org.springframework.web.context.ContextLoader.configureAndRefreshWebApplicationContext(ContextLoader.java:385)
    at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:284)
    at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:111)
    at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4723)
    at org.apache.catalina.core.StandardContext$1.call(StandardContext.java:5226)
    at org.apache.catalina.core.StandardContext$1.call(StandardContext.java:5221)
    at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:334)
    at java.util.concurrent.FutureTask.run(FutureTask.java:166)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1110)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603)
    at java.lang.Thread.run(Thread.java:722)
Caused by: org.xml.sax.SAXParseException; lineNumber: 21; columnNumber: 29; cvc-complex-type.2.4.c: The matching wildcard is strict, but no declaration can be found for element 'mvc:annotation-driven'.
    at com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.createSAXParseException(ErrorHandlerWrapper.java:198)
    at com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.error(ErrorHandlerWrapper.java:134)
    at com.sun.org.apache.xerces.internal.impl.XMLErrorReporter.reportError(XMLErrorReporter.java:437)
    at com.sun.org.apache.xerces.internal.impl.XMLErrorReporter.reportError(XMLErrorReporter.java:368)
    at com.sun.org.apache.xerces.internal.impl.XMLErrorReporter.reportError(XMLErrorReporter.java:325)
    at com.sun.org.apache.xerces.internal.impl.xs.XMLSchemaValidator$XSIErrorReporter.reportError(XMLSchemaValidator.java:449)
    at com.sun.org.apache.xerces.internal.impl.xs.XMLSchemaValidator.reportSchemaError(XMLSchemaValidator.java:3228)
    at com.sun.org.apache.xerces.internal.impl.xs.XMLSchemaValidator.handleStartElement(XMLSchemaValidator.java:1908)
    at com.sun.org.apache.xerces.internal.impl.xs.XMLSchemaValidator.emptyElement(XMLSchemaValidator.java:757)
    at com.sun.org.apache.xerces.internal.impl.XMLNSDocumentScannerImpl.scanStartElement(XMLNSDocumentScannerImpl.java:353)
    at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl$FragmentContentDriver.next(XMLDocumentFragmentScannerImpl.java:2715)
    at com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl.next(XMLDocumentScannerImpl.java:607)
    at com.sun.org.apache.xerces.internal.impl.XMLNSDocumentScannerImpl.next(XMLNSDocumentScannerImpl.java:116)
    at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanDocument(XMLDocumentFragmentScannerImpl.java:488)
    at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:835)
    at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:764)
    at com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(XMLParser.java:123)
    at com.sun.org.apache.xerces.internal.parsers.DOMParser.parse(DOMParser.java:240)
    at com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderImpl.parse(DocumentBuilderImpl.java:300)
    at org.springframework.beans.factory.xml.DefaultDocumentLoader.loadDocument(DefaultDocumentLoader.java:75)
    at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.doLoadBeanDefinitions(XmlBeanDefinitionReader.java:388)
    ... 21 more

最佳答案

您尚未在 i_am_alive-servlet.xml 文件中指定 MVC 架构的 XML 命名空间位置,这就是验证失败的原因。

<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:jee="http://www.springframework.org/schema/jee"
xmlns:lang="http://www.springframework.org/schema/lang"
xmlns:p="http://www.springframework.org/schema/p"
xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:util="http://www.springframework.org/schema/util"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
    http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsd
    http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd
    http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee.xsd
    http://www.springframework.org/schema/lang http://www.springframework.org/schema/lang/spring-lang.xsd
    http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd
    http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util.xsd">

这只是您的i_am_alive-servlet.xml的片段

您需要将其添加到 xmlSchemaDefinition

http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc.xsd

我认为它应该有效。 话虽如此,您不想用版本来限定您的模式定义吗?

我发现您的applicationContext.xml使用了3.0版本。但是您的 i_am_alive-servlet.xml (即 WebAppContext)将使用 4.0 xml 架构进行验证。

我建议您在 i_am_alive-servlet.xml 中也使用相同的架构定义。

这将是

xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:jee="http://www.springframework.org/schema/jee"
xmlns:lang="http://www.springframework.org/schema/lang"
xmlns:p="http://www.springframework.org/schema/p"
xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:util="http://www.springframework.org/schema/util"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xsi:schemaLocation="
    http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd
    http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
    http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.0.xsd
    http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd
    http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-3.0.xsd
    http://www.springframework.org/schema/lang http://www.springframework.org/schema/lang/spring-lang-3.0.xsd
    http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd
    http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-3.0.xsd">

编辑:

我指出的另一点是,您有一个 applicationContext.xml 文件,在我看来,该文件从未加载,因为您指定了 context-param 标记,该标记会覆盖并查找 i_am_alive-servlet.xml 文件作为应用程序语境。 在您当前的情况下,您不需要 web.xml 中的以下标记片段

<context-param>
    <param-name>contextConfigLocation</param-name>
    <param-value>/WEB-INF/i_am_alive-servlet.xml</param-value>
</context-param>

如果您确实想维护自定义文件,那么也可以,但是您也有一个 applicationContext.xml,因此不需要加载根上下文。 另外,还有一个拼写错误,您需要的文件是 application*C*ontext.xml。没有小C我还没试过。

如果您希望调度程序 servlet 加载 WebApplicationContext,则默认位置为/WEB-INF,默认文件名为 -servlet.xml。这是 i_am_alive-servlet.xml。 因此,您也不需要指定自定义 Web 应用程序上下文文件。

如果您确实必须这样做,则上下文参数不是执行此操作的正确位置。 应该是这样的

<servlet>
    <servlet-name>i_am_alive</servlet-name>
    <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
    <load-on-startup>1</load-on-startup>

    <init-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>/WEB-INF/i_am_alive-servlet.xml</param-value>
    </init-param>
</servlet>

但是,就像我提到的,您的 i_am_alive-servlet.xml 会被自动检测到,因为它是 Spring 容器将搜索的默认名称和位置。

关于java - 使用 <mvc :annotation-driven/> application is not deploy by tomcat in netbeans 时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21084225/

相关文章:

java - Gradle:构建与 Java 8 兼容的模块化库

java - 当我运行 Java 程序时,我的 intellij-idea-ultimate-edition 总是转储

java - GraphStream 中更好的图形可视化 - JAVA

java - 如何使用对象的属性作为@CachePut 的键?

java - Struts 2 中 Java 类内部的验证

java - Weblogic 12c数据库连接错误

java - 为什么@ExceptionHandler(MethodArgumentNotValidException.class) 被忽略以支持@ExceptionHandler(Exception.class)

spring - 带有 Spring+REST Web 服务的 @RequestBody 或 @ModelAttribute

php - Laravel 表单验证问题( session 大小限制?)

asp.net - 文本框的正则表达式最大和最小长度字符