gpt4 book ai didi

java - Spring-Rest 应用程序中出现 404 错误

转载 作者:太空宇宙 更新时间:2023-11-04 06:24:05 27 4
gpt4 key购买 nike

我有一个显示rest+spring的简单应用程序。但是收到404错误:运行时它应该给出 jeresey+spring 作为输出网页 xml 文件

<web-app id="WebApp_ID" 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>Restful Web Application</display-name>

<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:applicationContext.xml</param-value>
</context-param>

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

<servlet>
<servlet-name>jersey-serlvet</servlet-name>
<servlet-class>
com.sun.jersey.spi.spring.container.servlet.SpringServlet
</servlet-class>
<init-param>
<param-name>
com.sun.jersey.config.property.packages
</param-name>
<param-value>com.mtv.rest</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>

<servlet-mapping>
<servlet-name>jersey-serlvet</servlet-name>
<url-pattern>/rest/*</url-pattern>
</servlet-mapping>

</web-app>

应用程序上下文文件是

<?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:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.0.xsd">

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

<bean id="transactionBo"
class="com.mtv.rest.TransactionBoImpl" />

</beans>

支付类别

package com.mtv.rest;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.core.Response;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import com.mtv.rest.TransactionBo;

@Component
@Path("/payment")
public class PaymentService {

@Autowired
TransactionBo transactionBo;

@GET
@Path("/mtv")
public Response savePayment() {

String result = transactionBo.save();

return Response.status(200).entity(result).build();

}

}

界面是

package com.mtv.rest;

public class TransactionBoImpl implements TransactionBo {

public String save() {

return "Jersey + Spring example";

}


}

有时 tomcat 端口也会出错。

最佳答案

  • 正确检查您是否已正确添加所有JAR 文件/依赖项
  • 检查 applicationContext.xml 是否位于正确的位置,即 src 文件夹中。

这是一些最常见的错误。

关于java - Spring-Rest 应用程序中出现 404 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27038812/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com