当前位置: 首页 > 知识库问答 >
问题:

RestController在SpringBoot中工作得很好,但在Tomcat上抛出404

全昊焜
2023-03-14

我有一个简单的RestController应用程序-

@RestController
public class GreetingController {

    private static final Logger logger = LogManager.getLogger(GreetingController.class);

    @RequestMapping("/greeting")
    public ResponseEntity<GreetingResponse> greeting(@RequestParam(value = "name", defaultValue = "World") String name) throws ServiceException, Exception {
        logger.info("Received Request. Name: " + name);

它在SpringBoot(http://localhost:8080/greeting)上工作得很好,但是当我创建一个WAR并将其部署到Tomcat(9.0.2)上时,它会抛出一个404。

dependencies {
    compile("org.springframework.boot:spring-boot-starter-web")
    providedRuntime 'org.springframework.boot:spring-boot-starter-tomcat'
    testCompile('org.springframework.boot:spring-boot-starter-test')
    testCompile('com.jayway.jsonpath:json-path')
    compile group: 'org.apache.logging.log4j', name: 'log4j-api', version: '2.10.0'
    compile group: 'org.apache.logging.log4j', name: 'log4j-core', version: '2.10.0'    
}

war {

    archiveName = "ROOT.war"
    manifest {attributes "Implementation-Version": "${version}"}
}

共有1个答案

邵伟
2023-03-14

发现问题了。我的应用程序必须扩展SpringBootServletInitializer

@SpringBootApplication
public class Application  extends SpringBootServletInitializer {
 类似资料: