0

我正在尝试在 Jboss 7.1 AS 上部署基于 spring 的 rest webservices。部署后,我无法通过休息客户端访问 Web 服务。每次我收到 404 错误。以下是详细信息。

休息-servlet.xml

     <?xml version="1.0" encoding="UTF-8"?>

    <context:component-scan base-package="com.rest.controller"/>

     <!-- To enable @RequestMapping process on type level and method level -->
     <bean class="org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping" />
     <bean class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter">
    <property name="messageConverters">
        <list>

            <ref bean="marshallingConverter" />
            <!-- 
            <ref bean="atomConverter"  />
             -->
            <ref bean="jsonConverter" />
        </list>
    </property>
     </bean>

<bean id="jaxbMarshaller" class="org.springframework.oxm.jaxb.Jaxb2Marshaller">
    <property name="classesToBeBound">
        <list>
            <value>com.rest.Model1</value>
            <value>com.rest.Model1List</value>
        </list>
    </property>
</bean>


<bean class="org.springframework.web.servlet.view.ContentNegotiatingViewResolver">
    <property name="mediaTypes">
        <map>
            <entry key="xml" value="application/xml"/>
            <entry key="html" value="text/html"/>
            <entry key="json" value="application/json" />
        </map>
    </property>
    <property name="defaultContentType" value="application/xml" />
</bean>

 web.xml
 <?xml version="1.0" encoding="UTF-8"?>
  <web-app version="2.4"
     xmlns="http://java.sun.com/xml/ns/j2ee"
     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
     xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee 
     http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd" >

<display-name>TestRestProject</display-name>
<!--
    Beans in these files will makeup the configuration of the root web
    application context
-->
<context-param>
    <param-name>contextConfigLocation</param-name>
    <param-value>/WEB-INF/application-context.xml</param-value>
</context-param>

<!--
    Bootstraps the root web application context before servlet
    initialization
-->
<listener>
             <listener-  class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>

<!--
    Deploys the 'transactions' dispatcher servlet whose configuration resides
    in /WEB-INF/accounts-servlet-config.xml
-->
<servlet>
             <servlet-name>rest</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></param-value>
                   <param-value>/WEB-INF/transactions-servlet-config.xml</param-value> 
    </init-param>  -->

</servlet>


    <!-- Maps all URLs starting with /app to the 'accounts' servlet. -->
<servlet-mapping>
    <servlet-name>rest</servlet-name>
    <url-pattern>/myrest/*</url-pattern>
</servlet-mapping>



      </web-app>

RestController.java

package com.rest.controller;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
  @RequestMapping("/myrest")
  public class RestController {


@RequestMapping(value="/getTestMethod", method=RequestMethod.GET)
       public @ResponseBody String getTestMethod(@PathVariable String param1,@PathVariable   String param2){
    String returnValue = "";
    returnValue = "This is from the Controller" + param1 + param2;

    return returnValue;
}
}
4

0 回答 0