无法通过浏览器访问控制器

时间:2018-12-18 12:29:07

标签: java spring-boot url

我遇到这种情况:执行http://localhost:8080/customer/system/ipaddr应该访问控制器中的方法时,我收到以下错误消息:

  

此应用程序没有针对/ error的显式映射,因此您将其视为备用。

对于其他没有问题的类,我得到了非常相似的结构。在找了一段时间的错误,我不知道为什么它不起作用。

如果您需要其他任何信息,请告诉我。

控制器:

@Controller
@RequestMapping(CUSTOMER_SERVICE)
public class CustomerController {

    private CustomerProviderComponent customerProviderComponent;
    private CartRequestComponent cartRequestComponent;

    @Autowired
    public CustomerController(CustomerProviderComponent customerProviderComponent, CartRequestComponent cartRequestComponent) {
        this.customerProviderComponent = checkNotNull(customerProviderComponent);
        this.cartRequestComponent = checkNotNull(cartRequestComponent);
    }

    @ResponseBody
    @GetMapping(GET_IP_ADDR)
    public String getIpAddr() {
        List<String> response;
        response = runSystemCommandAndGetResponse(IP_ADDR);
        return new Gson().toJson(response);
    }

常量:

public static final String CUSTOMER_SERVICE = "/customer";
public static final String GET_IP_ADDR = "/system/ipaddr";

3 个答案:

答案 0 :(得分:1)

好的,很抱歉。问题完全不同。我正在将这些应用程序部署在kubernetes集群中。在部署脚本中,由于大量复制/粘贴,我只是从docker hub提取了错误的映像。

所以错误是部署脚本中的这一行: image: myrepo/articleservice:1.0.4

在部署脚本中添加image: myrepo/catalogservice:1.0.4可以解决此问题。

最糟糕的是,我没有错误日志,但是@Praveen E让我再次靠近了,所以谢谢!

答案 1 :(得分:0)

在此链接上看不到您的应用程序上下文:

http://localhost:8080/customer/system/ipaddr

通常,您会遇到类似这样的情况:

http://localhost:8080/MYAPP/customer/system/ipaddr

除非您将应用程序部署到服务器的根目录。

答案 2 :(得分:0)

是的,您可以调用它。确保代码在本地运行,并且您要调用的方法名称没有重复