Spring REST应用程序无法在Eclipse和Postman上运行

当我实现简单的Spring REST应用程序时,我无法获取输出,而是获取HTTP Status 404请求的资源不可用。请帮助我解决这个错误 我的tomcat端口:9999

这是我的春季代码...

package com.chenna.springrest.config;

import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
@Configuration
@EnableWebMvc
@ComponentScan("com.chenna.springrest")
public class DemoAppConfig implements WebMvcConfigurer{
}

这是我的配置类

public class MySpringMvcDispatcherServletInitializer extends AbstractAnnotationconfigDispatcherServletInitializer{
@Override
protected Class<?>[] getRootConfigClasses() {
    // TODO Auto-generated method stub
    return null;
}
@Override
protected Class<?>[] getServletConfigClasses() {
    return new Class[] { DemoAppConfig.class };
}
@Override
protected String[] getServletMappings() {

    return new String[] { "/" };
}

}

这是我的控制器

import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
@RestController
@RequestMapping("/test")
public class DemoRestController {

//add code for the "/hello" endpoint

@GetMapping("/hello")
public String sayHello() {
    return "Hello World !!";
}

}

当我运行程序时 http://localhost:9999/springrestapp/test/hello

HTTP状态404-/ springrestapp / test / hello 说明所请求的资源不可用。

jikjikjik1 回答:Spring REST应用程序无法在Eclipse和Postman上运行

暂时没有好的解决方案,如果你有好的解决方案,请发邮件至:iooj@foxmail.com
本文链接:https://www.f2er.com/2981220.html

大家都在问