请求映射POST但PUT映射

时间:2013-08-04 11:51:47

标签: spring-mvc angularjs

我正在开发一个带有angularjs的spring mvc应用程序。 我有一个简单的休息服务,使用post方法进行用户注册(电子邮件)。 当我在tomcat 7上启动应用程序时,我在控制台上有这一行:

INFO: Mapped "{[/mail/registration],methods=[PUT],params=[],headers=[],consumes=[],produces=[application/json],custom=[]}" onto public void com.xtapps.schoolme.controllers.HomeController.emailReception(java.lang.String)

我的代码:

@Controller

public class HomeController {

@RequestMapping(value = "/mail/registration", method = RequestMethod.POST, consumes = MediaType.APPLICATION_JSON_VALUE)
public @ResponseBody void emailReception(@RequestBody String email) {
    prepareAndSendMail(email);
}

我的web.xml:

<?xml version="1.0" encoding="UTF-8"?>
<web-app 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_3_0.xsd"
     version="3.0">

<listener>
    <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>

<servlet>
    <servlet-name>Spring</servlet-name>
    <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
    <init-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>/WEB-INF/applicationContext.xml</param-value>
    </init-param>
    <load-on-startup>1</load-on-startup>
</servlet>

<servlet-mapping>
    <servlet-name>Spring</servlet-name>
    <url-pattern>/rest/*</url-pattern>
</servlet-mapping>


<filter>
    <filter-name>httpPutFormFilter</filter-name>
    <filter-class>org.springframework.web.filter.HttpPutFormContentFilter</filter-class>
</filter>

<filter-mapping>
    <filter-name>httpPutFormFilter</filter-name>
    <servlet-name>Spring</servlet-name>
</filter-mapping>

<welcome-file-list>
    <welcome-file>/index.html</welcome-file>
</welcome-file-list>

和我在pom.xml中的依赖项:

<spring.version>3.2.3.RELEASE</spring.version>
<javax.mail.version>1.4.7</javax.mail.version>
<jstl.version>1.2</jstl.version>

 <!-- JSTL -->
    <dependency>
        <groupId>jstl</groupId>
        <artifactId>jstl</artifactId>
        <version>${jstl.version}</version>
    </dependency>

    <!-- Spring 3 dependencies -->
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-core</artifactId>
        <version>${spring.version}</version>
    </dependency>
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-beans</artifactId>
        <version>${spring.version}</version>
    </dependency>
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-expression</artifactId>
        <version>${spring.version}</version>
    </dependency>
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-web</artifactId>
        <version>${spring.version}</version>
        <scope>provided</scope>
    </dependency>

    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-webmvc</artifactId>
        <version>${spring.version}</version>
        <scope>provided</scope>
    </dependency>
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-context</artifactId>
        <version>${spring.version}</version>
        <scope>provided</scope>
    </dependency>
    <dependency>
        <groupId>javax.mail</groupId>
        <artifactId>mail</artifactId>
        <version>${javax.mail.version}</version>
    </dependency>

在前面我打电话给我的休息服务:

$http({
        url: '/rest/mail/registration',
        method: "POST",
        data: $scope.email,
        headers: {'Content-Type': 'application/json'}
    }).success(function (data, status, headers, config) {

或者像这样(它是一样的):

    $http.post('/rest/mail/registration', $scope.email)...;

我有这个警告:

WARNING: Request method 'POST' not supported

你对这个问题有什么看法吗?

提前谢谢

0 个答案:

没有答案