Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/spring/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 如何在Zuul筛选器中发送RestTemplate/请求?_Java_Spring_Spring Boot_Netflix Zuul - Fatal编程技术网

Java 如何在Zuul筛选器中发送RestTemplate/请求?

Java 如何在Zuul筛选器中发送RestTemplate/请求?,java,spring,spring-boot,netflix-zuul,Java,Spring,Spring Boot,Netflix Zuul,我有一个核心MS,它只是一个passthrough,并向所有传入请求添加头。我试图在Zuul过滤器中调用Validate会话API,以便在添加所有请求的头之前首先调用它,如果出现错误,事务将不会继续。然而,我似乎无法在过滤器内发送基本的rest模板请求。那我做错了什么,还是错过了什么?。下面是代码片段 public class WebFilter extends ZuulFilter { @Override public String filterType() {

我有一个核心MS,它只是一个passthrough,并向所有传入请求添加头。我试图在Zuul过滤器中调用Validate会话API,以便在添加所有请求的头之前首先调用它,如果出现错误,事务将不会继续。然而,我似乎无法在过滤器内发送基本的rest模板请求。那我做错了什么,还是错过了什么?。下面是代码片段

public class WebFilter extends ZuulFilter {

 @Override
    public String filterType() {

        RestTemplate restTemplate = new RestTemplate(new HttpComponentsClientHttpRequestFactory());
        restTemplate.getForEntity(this.loginService.validateCache(hostUrl,validateSessionUrl, ctx.getRequest().getParameter("SessionId")).toUriString(),String.class

         ctx.addZuulRequestHeader("clientid", clientId);
        ctx.addZuulRequestHeader("clientsecret", clientSecret);
        return "pre";
    }
}
resttemplate部分给出了ff。错误。然而,删除它将使应用程序工作,但是我需要rest模板来调用验证API。我应该把这个放在别的地方还是别的什么地方

2019-12-20 10:11:50.337错误4224---[main] o、 s.boot.SpringApplication:应用程序启动失败

org.springframework.context.ApplicationContextException:无法 启动嵌入式容器;嵌套异常是 org.springframework.boot.context.embedded.EmbeddedServletContainerException: 无法在上启动嵌入式Tomcat org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.onRefresh(EmbeddedWebApplicationContext.java:137) ~[spring-boot-1.4.0.RELEASE.jar:1.4.0.RELEASE]at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:535) ~[spring-context-4.3.2.RELEASE.jar:4.3.2.RELEASE]位于 org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.refresh(EmbeddedWebApplicationContext.java:122) ~[spring-boot-1.4.0.RELEASE.jar:1.4.0.RELEASE]at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:759) ~[spring-boot-1.4.0.RELEASE.jar:1.4.0.RELEASE]at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:369) ~[spring-boot-1.4.0.RELEASE.jar:1.4.0.RELEASE]at org.springframework.boot.SpringApplication.run(SpringApplication.java:313) ~[spring-boot-1.4.0.RELEASE.jar:1.4.0.RELEASE]at org.springframework.boot.SpringApplication.run(SpringApplication.java:1185) ~[spring-boot-1.4.0.RELEASE.jar:1.4.0.RELEASE]at org.springframework.boot.SpringApplication.run(SpringApplication.java:1174) ~[spring-boot-1.4.0.RELEASE.jar:1.4.0.RELEASE]at com.bdo.fintech.web.core.Application.main(Application.java:26) ~[classes/:na]由以下原因引起: org.springframework.boot.context.embedded.EmbeddedServletContainerException: 无法在上启动嵌入式Tomcat org.springframework.boot.context.embedded.tomcat.TomcatEmbeddedServletContainer.initialize(TomcatEmbeddedServletContainer.java:116) ~[spring-boot-1.4.0.RELEASE.jar:1.4.0.RELEASE]at org.springframework.boot.context.embedded.tomcat.TomcatEmbeddedServletContainer.(TomcatEmbeddedServletContainer.java:83) ~[spring-boot-1.4.0.RELEASE.jar:1.4.0.RELEASE]at org.springframework.boot.context.embedded.tomcat.TomcatEmbeddedServletContainerFactory.gettomcatembeddedservletContainerContainer(TomcatEmbeddedServletContainerFactory.java:530) ~[spring-boot-1.4.0.RELEASE.jar:1.4.0.RELEASE]at org.springframework.boot.context.embedded.tomcat.TomcatEmbeddedServletContainerFactory.GetEmbeddedServletContainerFactory(TomcatEmbeddedServletContainerFactory.java:176) ~[spring-boot-1.4.0.RELEASE.jar:1.4.0.RELEASE]at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.createEmbeddedServletContainer(EmbeddedWebApplicationContext.java:164) ~[spring-boot-1.4.0.RELEASE.jar:1.4.0.RELEASE]at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.onRefresh(EmbeddedWebApplicationContext.java:134) ~[spring-boot-1.4.0.RELEASE.jar:1.4.0.RELEASE]。。。8通用框架 由于以下原因而忽略: org.springframework.beans.factory.unsatifiedDependencyException: 创建名为的bean时出错 'org.springframework.cloud.netflix.zuul.ZuulConfiguration$ZuulFilterConfiguration': 通过字段“筛选器”表示的未满足的依赖项:错误 正在创建中定义了名称为“webFilter”的bean com.bdo.fintech.web.core.Application:通过工厂进行Bean实例化 方法失败;嵌套异常是 org.springframework.beans.BeanInstantiationException:未能 实例化[com.bdo.fintech.web.core.WebFilter]:工厂方法 “webFilter”引发异常;嵌套异常是 java.lang.NullPointerException;嵌套异常是 org.springframework.beans.factory.BeanCreationException:错误 正在创建中定义了名称为“webFilter”的bean com.bdo.fintech.web.core.Application:通过工厂进行Bean实例化 方法失败;嵌套异常是 org.springframework.beans.BeanInstantiationException:未能 实例化[com.bdo.fintech.web.core.WebFilter]:工厂方法 “webFilter”引发异常;嵌套异常是 位于的java.lang.NullPointerException org.springframework.beans.factory.annotation.AutoWiredNotationBeanPostProcessor$AutoWiredFeldElement.inject(AutoWiredNotationBeanPostProcessor.java:569) ~[spring-beans-4.3.2.RELEASE.jar:4.3.2.RELEASE]at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:88) ~[spring-beans-4.3.2.RELEASE.jar:4.3.2.RELEASE]at org.springframework.beans.factory.annotation.AutoWiredNotationBeanPostProcessor.PostProcessPropertyValue(AutoWiredNotationBeanPostProcessor.java:349) ~[spring-beans-4.3.2.RELEASE.jar:4.3.2.RELEASE]at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1214) ~[spring-beans-4.3.2.RELEASE.jar:4.3.2.RELEASE]at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:543) ~[spring-beans-4.3.2.RELEASE.jar:4.3.2.RELEASE]at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:482) [spring-beans-4.3.2.RELEAS]
if(ctx.getRequest() != null) {
 // Put Rest template code here
} else {
// Some more code that will handle when the request is null
}