0

我正在开发一个前面带有 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

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

先感谢您

4

0 回答 0