Java Spring MVC RESTful接口

Java Spring MVC RESTful接口,java,spring,rest,tomcat,spring-mvc,Java,Spring,Rest,Tomcat,Spring Mvc,我是spring新手,我想创建RESTful接口。我无法让简单的示例代码正常工作,也无法找出问题所在 以下代码触发错误: 从http://localhost:8080/myTestApp/test:清单可能无效或无法打开文件 来源:System.Deployment 守则: @RequestMapping(method=RequestMethod.GET, value="/test") @ResponseBody public String test(@RequestBody String

我是spring新手,我想创建RESTful接口。我无法让简单的示例代码正常工作,也无法找出问题所在

以下代码触发错误:

  • http://localhost:8080/myTestApp/test
    :清单可能无效或无法打开文件
  • 来源:System.Deployment
守则:

@RequestMapping(method=RequestMethod.GET, value="/test")
@ResponseBody
public String test(@RequestBody String body){
    String testString = test.CreateXml();
    return testString;
    //return "home";
}
如果我第一次用下面的代码在服务器中启动项目

@RequestMapping(method=RequestMethod.GET, value="/test")
//@ResponseBody
public String test(@RequestBody String body){
    String testString = test.CreateXml();
    //return testString;
    return "home";
}
然后我取消注释“@ResponseBody”和“returnteststring”,并在服务器启动和运行时为“return“home”行添加注释。 因此,代码看起来与前面的代码完全相同,但没有起作用。对代码进行更改后,我按Save,新代码将被动态地传递到服务器。 在这些更改之后,“测试”界面工作。若我重新启动服务器,我再次收到错误

我使用的是“Spring工具套件3.4.0”,服务器尝试了“VMware Fabric tc Server Developer Edition v2.9”和“Tomcat v7”。两台服务器都存在相同的问题,因此原因应该在spring配置的某个地方。 有人能帮忙吗

下面我附上了错误日志

PLATFORM VERSION INFO
    Windows             : 6.1.7601.65536 (Win32NT)
    Common Language Runtime     : 4.0.30319.18444
    System.Deployment.dll       : 4.0.30319.18408 built by: FX451RTMGREL
    clr.dll             : 4.0.30319.18444 built by: FX451RTMGDR
    dfdll.dll           : 4.0.30319.18408 built by: FX451RTMGREL
    dfshim.dll          : 4.0.41209.0 (Main.041209-0000)

SOURCES
    Deployment url          : http://localhost:8080/myTestApp/test

ERROR SUMMARY
    Below is a summary of the errors, details of these errors are listed later in the log.
    * Activation of http://localhost:8080/myTestApp/test resulted in exception. Following failure messages were detected:
        + Exception reading manifest from http://localhost:8080/myTestApp/test: the manifest may not be valid or the file could not be opened.
        + Parsing and DOM creation of the manifest resulted in error. Following parsing errors were noticed: 
            -HRESULT:   0x8007001f
             Start line:    0
             Start column:  0
             Host file:     
        + A device attached to the system is not functioning. (Exception from HRESULT: 0x8007001F)

COMPONENT STORE TRANSACTION FAILURE SUMMARY
    No transaction error was detected.

WARNINGS
    There were no warnings during this operation.

OPERATION PROGRESS STATUS
    * [3/30/2014 8:21:24 PM] : Activation of http://localhost:8080/myTestApp/test has started.

ERROR DETAILS
    Following errors were detected during this operation.
    * [3/30/2014 8:21:35 PM] System.Deployment.Application.InvalidDeploymentException (ManifestParse)
        - Exception reading manifest from http://localhost:8080/myTestApp/test: the manifest may not be valid or the file could not be opened.
        - Source: System.Deployment
        - Stack trace:
            at System.Deployment.Application.ManifestReader.FromDocument(String localPath, ManifestType manifestType, Uri sourceUri)
            at System.Deployment.Application.DownloadManager.DownloadDeploymentManifestDirectBypass(SubscriptionStore subStore, Uri& sourceUri, TempFile& tempFile, SubscriptionState& subState, IDownloadNotification notification, DownloadOptions options, ServerInformation& serverInformation)
            at System.Deployment.Application.DownloadManager.DownloadDeploymentManifestBypass(SubscriptionStore subStore, Uri& sourceUri, TempFile& tempFile, SubscriptionState& subState, IDownloadNotification notification, DownloadOptions options)
            at System.Deployment.Application.ApplicationActivator.PerformDeploymentActivation(Uri activationUri, Boolean isShortcut, String textualSubId, String deploymentProviderUrlFromExtension, BrowserSettings browserSettings, String& errorPageUrl)
            at System.Deployment.Application.ApplicationActivator.ActivateDeploymentWorker(Object state)
        --- Inner Exception ---
        System.Deployment.Application.InvalidDeploymentException (ManifestParse)
        - Parsing and DOM creation of the manifest resulted in error. Following parsing errors were noticed: 
            -HRESULT:   0x8007001f
             Start line:    0
             Start column:  0
             Host file:     
        - Source: System.Deployment
        - Stack trace:
            at System.Deployment.Application.Manifest.AssemblyManifest.LoadCMSFromStream(Stream stream)
            at System.Deployment.Application.Manifest.AssemblyManifest..ctor(FileStream fileStream)
            at System.Deployment.Application.ManifestReader.FromDocument(String localPath, ManifestType manifestType, Uri sourceUri)
        --- Inner Exception ---
        System.Runtime.InteropServices.COMException
        - A device attached to the system is not functioning. (Exception from HRESULT: 0x8007001F)
        - Source: System.Deployment
        - Stack trace:
            at System.Deployment.Internal.Isolation.IsolationInterop.CreateCMSFromXml(Byte[] buffer, UInt32 bufferSize, IManifestParseErrorCallback Callback, Guid& riid)
            at System.Deployment.Application.Manifest.AssemblyManifest.LoadCMSFromStream(Stream stream)

COMPONENT STORE TRANSACTION DETAILS
    No transaction information is available.
“测试”是REST接口的示例代码。目前,它生成“虚拟”xml。下面是生成的伪xml

<root>
<!--This is a comment-->
<test name="value">My node value</test>
</root>
我没有涉及上下文xml,它是自动生成的。下面是servlet-context.xml

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

    <!-- DispatcherServlet Context: defines this servlet's request-processing infrastructure -->

    <!-- Enables the Spring MVC @Controller programming model -->
    <annotation-driven />

    <!-- Handles HTTP GET requests for /resources/** by efficiently serving up static resources in the ${webappRoot}/resources directory -->
    <resources mapping="/resources/**" location="/resources/" />

    <!-- Resolves views selected for rendering by @Controllers to .jsp resources in the /WEB-INF/views directory -->
    <beans:bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
        <beans:property name="prefix" value="/WEB-INF/views/" />
        <beans:property name="suffix" value=".jsp" />
    </beans:bean>

    <context:component-scan base-package="com.mobile.myTestApp" />



</beans:beans>


stacktrace和/或日志。还有什么是
测试
,你能分享它的声明和
CreateXml
方法的代码吗?也包括你的应用程序上下文xml,这样我们就可以了解你是如何配置所有内容的。我用你提出的所有内容更新了这个问题。据我所知,所有内容都应该有效,所以我认为问题可能存在于自动生成的配置文件中。奇怪的是,如果我在服务器启动和运行时更改代码,那么一切都会正常运行。。。
<?xml version="1.0" encoding="UTF-8"?>
<beans:beans xmlns="http://www.springframework.org/schema/mvc"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:beans="http://www.springframework.org/schema/beans"
    xmlns:context="http://www.springframework.org/schema/context"
    xsi:schemaLocation="http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc.xsd
        http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
        http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd">

    <!-- DispatcherServlet Context: defines this servlet's request-processing infrastructure -->

    <!-- Enables the Spring MVC @Controller programming model -->
    <annotation-driven />

    <!-- Handles HTTP GET requests for /resources/** by efficiently serving up static resources in the ${webappRoot}/resources directory -->
    <resources mapping="/resources/**" location="/resources/" />

    <!-- Resolves views selected for rendering by @Controllers to .jsp resources in the /WEB-INF/views directory -->
    <beans:bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
        <beans:property name="prefix" value="/WEB-INF/views/" />
        <beans:property name="suffix" value=".jsp" />
    </beans:bean>

    <context:component-scan base-package="com.mobile.myTestApp" />



</beans:beans>