Java 如何在tomcat上启动rest-spring应用程序?
我尝试使用rest控制器在spring上创建应用程序。 项目结构如下: applcationContext.xml:Java 如何在tomcat上启动rest-spring应用程序?,java,spring,Java,Spring,我尝试使用rest控制器在spring上创建应用程序。 项目结构如下: applcationContext.xml: <?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=
<?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"
xmlns:util="http://www.springframework.org/schema/util"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.2.xsd
http://www.springframework.org/schema/util
http://www.springframework.org/schema/util/spring-util.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.2.xsd
">
<context:annotation-config/>
</beans>
因此,我将此应用程序部署在apache-tomcat-8.5.29上,但尝试调用rest时出现404错误
我尝试的url是localhost:8080/test和localhost:8080/appName/test
你有什么想法吗?首先,你应该使用不需要外部应用程序或web服务器的springboot,而不是裸spring应用程序,在成功运行springboot应用程序后,你可以搜索如何将springboot应用程序转换为能够在tomcat上运行 以下是一些链接:
首先,您应该使用不需要外部应用程序或web服务器的springboot,而不是裸spring应用程序。成功运行springboot应用程序后,您可以搜索如何将springboot应用程序转换为能够在tomcat上运行 以下是一些链接:
尝试查看tomcat在您的机器上的位置,您如何确保它知道此webapp?您是否检查了服务器是否以8080端口运行?您是否使用上下文路径
spring mvc配置在哪里?看看这里的各种例子,试着找出tomcat在您的机器上的位置,您如何确保它知道这个webapp?您是否检查了服务器是否在8080端口上运行?您是否使用上下文路径spring mvc配置在哪里?看看这里的各种例子
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee
http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"
version="3.1">
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:WEB-INF/applicationContext.xml</param-value>
</context-param>
<session-config>
<session-timeout>30</session-timeout>
</session-config>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<listener>
<listener-class>org.springframework.web.context.request.RequestContextListener</listener-class>
</listener>
</web-app>
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
@RestController
public class TestController {
@RequestMapping(value="/test", method= RequestMethod.GET)
public void getTest(){
int i = 1;
}
}