Spring Boot +云| Zuul代理| 404错误

库马尔桑巴夫

我正在使用Spring Cloud和Zuul代理作为我的RESTful服务的网关。

网关应用程序(在端口8080上运行的Spring Boot Web应用程序)相关代码:-

主分类:-

@SpringBootApplication
@EnableZuulProxy
public class WebfrontApplication extends WebMvcConfigurerAdapter {

    /**
     * @param args
     */
    public static void main(String[] args) {
        SpringApplication.run(WebfrontApplication.class, args);
    }
}

Zuul映射:-

zuul:
  routes:
    customer:
      path: /customer/**
      url: http://localhost:9000/

在启动上述UI Gateway应用程序期间,我可以在日志中看到已注册代理映射:-

o.s.c.n.zuul.web.ZuulHandlerMapping      : Mapped URL path [/customer/**] onto handler of type [class org.springframework.cloud.netflix.zuul.web.ZuulController]

REST服务(在端口9000上运行的Spring Boot Web应用)相关代码:-

@RestController
@RequestMapping(value = "/customer")
public class CustomerController {

    @Autowired
    private CustomerService customerService;

    /**
     * Get List of All customers.
     * 
     * @return
     */
    @RequestMapping(value = "/list", method = RequestMethod.GET)
    public List<Customer> list(Principal principal) {
        return customerService.list();
    }
}

使用rest客户端(在我的情况下为POSTMAN),我可以成功地从上述终结点获得响应(在照顾了auth令牌之后)。

我在UI应用程序中使用AngularJS从REST端点获取数据。

相关代码:

angular.module('customerModule').factory('customerService',function($http) {

    return {
        customerList : function(){
            // PROBLEM !!!!!
            // THIS CALL GIVES A 404 ERROR
            return $http.get('/customer/list');
        }
    };
});

上面的调用返回了404错误:-这是我的Chrome调试器显示的内容:-

Remote Address:127.0.0.1:8080
Request URL:http://localhost:8080/customer/list
Request Method:GET
Status Code:404 Not Found

请求标头:-

Accept:application/json, text/plain, */*
Accept-Encoding:gzip, deflate, sdch
Accept-Language:en-US,en;q=0.8,hi;q=0.6,ms;q=0.4
Cache-Control:no-cache
Connection:keep-alive
Cookie:SESSION=2e1ac330-fe41-4ff4-8efb-81eaec12c8d1
Host:localhost:8080
Pragma:no-cache
Referer:http://localhost:8080/
User-Agent:Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/41.0.2272.89 Safari/537.36
X-Auth-Token:2e1ac330-fe41-4ff4-8efb-81eaec12c8d1

响应标题:-

Cache-Control:no-cache, no-store, max-age=0, must-revalidate
Content-Type:application/json; charset=UTF-8
Date:Fri, 20 Mar 2015 04:00:36 GMT
Date:Fri, 20 Mar 2015 04:00:36 GMT
Expires:0
Pragma:no-cache
Pragma:no-cache
Server:Jetty(9.2.9.v20150224)
Transfer-Encoding:chunked
X-Application-Context:bootstrap
X-Content-Type-Options:nosniff
X-Content-Type-Options:nosniff
X-Frame-Options:DENY
X-Frame-Options:DENY
X-XSS-Protection:1; mode=block
X-XSS-Protection:1; mode=block

这是怎么了 映射不正确还是我遗漏了其他东西?

解决了

根据已接受的答案,将Zuul映射更改为:

zuul:
 routes:
  resource:
   path: /customer/**
   url: http://localhost:9000/
   stripPrefix: false
戴夫·瑟

资源服务器上没有“ /列表”的映射(因此是404)。您要么需要在路由声明中设置stripPrefix = false,要么将后端的请求映射更改为“ /”。

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

Spring Boot中的代理设置

来自分类Dev

具有Spring Boot和Netflix Zuul的简单反向代理

来自分类Dev

Spring Boot JSP 404

来自分类Dev

网络代理背后的Spring-Boot

来自分类Dev

Spring Boot EnableJpaRepositories错误

来自分类Dev

Spring Boot +云| Zuul代理| 整合测试

来自分类Dev

Spring Zuul代理不接受承载令牌

来自分类Dev

Zuul代理CORS标头包含多个值,标头重复两次-Java Spring Boot CORS过滤器配置

来自分类Dev

Spring Boot和自定义404错误页面

来自分类Dev

从自定义静态位置提供静态HTML时,Spring Boot抛出404错误

来自分类Dev

在istio sidecar代理下运行的Spring-boot引发HTTP 403错误

来自分类Dev

Spring Boot REST API War文件生成404错误

来自分类Dev

Spring Boot中的代理设置

来自分类Dev

Spring Boot的启动错误

来自分类Dev

Spring Boot +云| Zuul代理| 附加网址/重写

来自分类Dev

云错误

来自分类Dev

本地主机Spring Boot中的错误404

来自分类Dev

spring-boot中的自定义404错误页面

来自分类Dev

Spring Boot 和云部署

来自分类Dev

spring boot 静态资源404错误

来自分类Dev

Spring boot 微服务云部署打包格式

来自分类Dev

Spring Boot:错误:代理抛出的异常:java.net.MalformedURLException:本地主机名未知

来自分类Dev

Dockerized Spring Boot 和 Zuul

来自分类Dev

Spring boot 中的 RestController-404 错误而不是 JSON 对象

来自分类Dev

白标错误页面 404 spring boot angular 6

来自分类Dev

捕获 404 错误 spring boot 以返回自定义 html

来自分类Dev

在 LogBack 中检测 Spring Boot 应用程序的云平台

来自分类Dev

Spring Boot Block country in zuul

来自分类Dev

Spring Boot - 无法通过 Zuul 代理获得 Keycloak 授权 api 的响应

Related 相关文章

热门标签

归档