【发布时间】:2016-06-24 06:46:32
【问题描述】:
我正在尝试使用 Spring Cloud 设置几个服务,在我将 Eureka 客户端服务部署到 Tomcat 之前,一切似乎都运行良好。当我通过网关应用调用服务时,出现以下错误:
o.s.c.n.z.filters.post.SendErrorFilter : Error during filtering
com.netflix.zuul.exception.ZuulException: Forwarding error
...
Caused by: com.netflix.hystrix.exception.HystrixRuntimeException: hello timed-out and no fallback available.
...
Caused by: java.util.concurrent.TimeoutException: null
然而,它在 Eclipse 中完美运行。当我从 Tomcat 运行发现和网关服务并从 eclipse 运行 Eureka 客户端服务时,它甚至可以工作。但是一旦我在 tomcat 上运行相同的服务,我就会得到错误。
我正在使用 Brixton.M5、Java 8 和 Tomcat 8。
再次,代码似乎可以工作,问题是它在部署到 Tomcat 后无法工作。
我有一个用于发现和网关服务的 Tomcat 实例,还有一个用于 Eureka 客户端服务的 Tomcat 实例。
这是一些代码和配置..
DiscoveryServerApp
@SpringBootApplication
@EnableEurekaServer
public class DiscoveryServerApp extends SpringBootServletInitializer
{
public static void main(String[] args)
{
SpringApplication.run(DiscoveryServerApp.class, args);
}
}
DiscoveryServer - application.yml
# Configure this Discovery Server
eureka:
instance:
hostname: discovery
client: # Not a client, don't register with yourself
registerWithEureka: false
fetchRegistry: false
serviceUrl:
defaultZone: http://localhost:1111/discovery/eureka/
server:
port: 1111 # HTTP (Tomcat) port
context-path: /discovery
DiscoveryServer - bootstrap.yml
spring:
application:
name: discovery
jmx:
default-domain: com.example.cloud.discovery
网关应用程序
@SpringCloudApplication
@EnableZuulProxy
public class GatewayApplication extends SpringBootServletInitializer
{
public static void main(String[] args)
{
SpringApplication.run(GatewayApplication.class, args);
}
}
GatewayApplication - application.yml
# Discovery Server Access
eureka:
client:
serviceUrl:
defaultZone: http://localhost:1111/discovery/eureka/
instance:
instanceId: ${spring.application.name}:${spring.application.instance_id:${random.value}}
# HTTP Server
server:
port: 4444 # HTTP (Tomcat) port
context-path: /api
GatewayApplication - bootstrap.yml
# Spring properties
spring:
application:
name: gateway-service # Identify this application
jmx:
default-domain: com.example.cloud.gateway
encrypt:
failOnError: false
虚拟应用程序
@SpringCloudApplication
@RestController
public class DummyApplication extends SpringBootServletInitializer
{
public static void main(String[] args)
{
SpringApplication.run(DummyApplication.class, args);
}
@RequestMapping( path = "/hello-resource", method = RequestMethod.GET )
public String hello()
{
return "hello";
}
}
DummyApplication - application.yml
# Discovery Server Access
eureka:
client:
serviceUrl:
defaultZone: http://localhost:1111/discovery/eureka/
instance:
instanceId: ${spring.application.name}:${spring.application.instance_id:${random.value}} # Unique id for multiple instances
# HTTP Server
server:
port: 3333 # HTTP (Tomcat) port
context-path: /hello-context
DummyApplication - bootstrap.yml
# Spring properties
spring:
application:
name: hello-service # Service registers under this name
jmx:
default-domain: com.example.cloud.hello
encrypt:
failOnError: false
【问题讨论】:
-
您从客户端/浏览器调用什么 URL?
-
GET localhost:1111/api/hello/hello/hello 是的,我知道,我只是喜欢问候......感谢您的快速回复!
标签: spring-cloud