我有一个 zuul 代理 ( http://localhost:8765 ) 服务于 angular web 应用程序 ( http://localhost:8080/app )。在 zuul 代理后面还有一个 oauth2 服务器(http://localhost:8899)。
Web 资源代理在http://localhost:8765/web 下,资源代理在http://localhost:8765/api 下。Zuul 代理无需身份验证即可提供静态 Web 资源。因此,第一次身份验证是通过 JSON 调用 (GET /api/user) 完成的,这当然会以 401 失败。
现在我将页面转发到“ http://localhost:8899/uaa/oauth/authorize?response_type=token&client_id=web&redirect_uri=http://localhost:8765/web/index.html ”以进行隐式授权 oauth 2 流程。我现在可以授权 Web 应用程序并转发回我的 Web 应用程序。令牌是 url 的一部分,我可以解析它。
恕我直言,我现在唯一要做的就是将此令牌添加为 Authorization 标头(例如 Authorization:Bearer 2829d5e2-4fbe-4f91-b74d-c99b2fe894a7)。但是 zuul 代理不会按照授权接受这个请求。
我正在使用 spring boot 1.3.2 和 spring cloud Brixton.M4。Zuul 服务器应用程序可以在这里找到,安全配置可以在这里找到。
这是我的请求标头:
Accept:application/json
Accept-Encoding:gzip, deflate, sdch
Accept-Language:de-DE,de;q=0.8,en-US;q=0.6,en;q=0.4
Authorization:Bearer 2829d5e2-4fbe-4f91-b74d-c99b2fe894a7
Connection:keep-alive
Cookie:XSRF-TOKEN=a6ddea36-e3b7-4f22-b80c-b4c8b6fd7760; JSESSIONID=DAE4649D11386D586A0CF739148E505A; …Run Code Online (Sandbox Code Playgroud) 我们已经使用 Spring 云配置外部化了我们的应用程序配置。我们还使用加密 API 在纯文本密码进入 yaml 属性文件之前对其进行加密。
我正在努力为下游系统加密密码,该密码最后具有特殊字符。不知何故,云配置加密 API 忽略了这一点。当您使用解密 API 解密密码时,您会得到纯文本,最后没有特殊字符。
我正在使用 curl 来调用 API -
curl 10.102.82.1:11901/encrypt -d AXIzFDH4XZA=
Run Code Online (Sandbox Code Playgroud)
出于某种原因,纯文本中间的特殊字符可以正常工作,但是如果最后有它,那么它会被忽略。可能这个密码已经被散列了,但我仍然很想知道如何处理这个问题。
我正在努力为我的 spring aws 云 SNS http 端点找到相当于以下 xml 配置的 spring boot java 配置。有人可以帮忙吗?
<mvc:annotation-driven>
<mvc:argument-resolvers>
<ref bean="notificationResolver" />
</mvc:argument-resolvers>
</mvc:annotation-driven>
<aws-messaging:notification-argument-resolver id="notificationResolver" />
Run Code Online (Sandbox Code Playgroud) 我有一个 AWS Elastic Load Balancer,其中包含我的域的证书并终止SSL流量。该ELB有一个监听https端口,并转发为http给Zuul。
当我使用时Spring Boot HATEOAS,Zuul 将用正确的地址替换链接,http而不是https:
"_links": {
"self": {
"href": "http://my.domain.com:80/rest/foo/bar"
}
}
Run Code Online (Sandbox Code Playgroud)
但我想要的是:
"_links": {
"self": {
"href": "https://my.domain.com/rest/foo/bar"
}
}
Run Code Online (Sandbox Code Playgroud)
生成此响应的请求已完成 https
因为Zuul在 ELB 后面,我猜它不知道它应该通过 https 接收流量。
有没有办法告诉Zuul替换链接,https即使它通过 接收未加密的流量http?
我想另一种方法是使用自签名证书进行部署Zuul,https但如果可以的话,我宁愿避免这种复杂情况。
spring amazon-web-services spring-hateoas spring-cloud netflix-zuul
我有一个使用 3 个假客户端的服务。每次启动应用程序时,我都会在第一次调用任何 feign 客户端时收到 TimeoutException。
在一切稳定之前,我必须至少触发每个假客户端一次。在网上环顾四周,问题在于 feign 或 hystrix 内部的某些内容是延迟加载的,解决方案是创建一个覆盖 spring 默认值的配置类。我已经用下面的代码试过了,但它仍然没有帮助。我仍然看到同样的问题。任何人都知道解决这个问题?是通过 hystrix 回调两次调用 feignclient 的唯一解决方案吗?
@FeignClient(value = "SERVICE-NAME", configuration =ServiceFeignConfiguration.class)
@Configuration
public class ServiceFeignConfiguration {
@Value("${service.feign.connectTimeout:60000}")
private int connectTimeout;
@Value("${service.feign.readTimeOut:60000}")
private int readTimeout;
@Bean
public Request.Options options() {
return new Request.Options(connectTimeout, readTimeout);
}
}
Run Code Online (Sandbox Code Playgroud)
Spring Cloud - Brixton.SR4 Spring Boot - 1.4.0.RELEASE
这一切都在 docker Ubuntu - 12.04 Docker - 1.12.1 Docker-Compose - 1.8 中运行
我有以下设置,其中我的 Eureka 服务器正在运行,并且在 Eureka 中创建和注册的服务很少正在运行。所有服务呼叫的服务都在使用已负载平衡的休息模板进行,并且一切正常。
现在,我已经使用以下代码/属性将基于 Zuul 的路由引入到应用程序中 -
@SpringBootApplication
@EnableZuulProxy
public class ApiGatewayApplication {
public static void main(String[] args) {
SpringApplication.run(ApiGatewayApplication.class, args);
}
@Bean
public CorsFilter corsFilter() {
final UrlBasedCorsConfigurationSource urlBasedCorsConfigurationSource= new UrlBasedCorsConfigurationSource();
final CorsConfiguration corsConfig = new CorsConfiguration();
corsConfig.setAllowCredentials(true);
corsConfig.addAllowedOrigin("*");
corsConfig.addAllowedHeader("*");
corsConfig.addAllowedMethod("OPTIONS");
corsConfig.addAllowedMethod("HEAD");
corsConfig.addAllowedMethod("GET");
corsConfig.addAllowedMethod("PUT");
corsConfig.addAllowedMethod("POST");
corsConfig.addAllowedMethod("DELETE");
corsConfig.addAllowedMethod("PATCH");
urlBasedCorsConfigurationSource.registerCorsConfiguration("/**", corsConfig);
return new CorsFilter(urlBasedCorsConfigurationSource);
}
}
Run Code Online (Sandbox Code Playgroud)
有了这个,我的路由工作得非常好,但是现在有一个服务需要接近 12 秒的执行时间,而且我的业务要求禁止打入较小的调用。
这会导致 Zuul 中的超时异常。
下面是我的 .yml 文件 -
ribbon:
ConnectTimeout: 60000
ReadTimeout: 600000
zuul:
host:
socket-timeout-millis: 60000
hystrix:
command:
default:
execution: …Run Code Online (Sandbox Code Playgroud) 我正在尝试使用 Spring Cloud 将一批项目发送到 Amazon SQS。我可以发送单个项目。但是,将它发送到队列的时间往往会乘以我发送的项目数。我基本上遵循参考文档的示例
在AWS 文档中,您可以一次发送最多 10 个项目的批次。所以我的问题是 QueueMessagingTemplate 或其他 Spring Cloud 类是否允许您这样做?
此代码片段显示了我想要做什么。我不想将项目作为对象发送,因为我希望每个项目都单独放置在队列中。
@Service
@EnableConfigurationProperties(SqsConfigMappingProperties.class)
public class SqsServiceImpl implements SqsService {
@Autowired
String queueName;
@Autowired
QueueMessagingTemplate queueMessagingTemplate;
@Override
public void sendSqsMessage(List items) {
//Can't really send a batch size here
int batchSize = 10;
queueMessagingTemplate.convertAndSend(queueName, items, 10);
}
}
Run Code Online (Sandbox Code Playgroud) 与spring-cloud-config集中配置类似,我们是否有集中 i18n 的东西messages.properties?这样做的最佳方法是什么?
我正在从链接开发代码: https: //howtodoinjava.com/spring-cloud/spring-cloud-config-server-git/当我更新Spring Boot版本2.1.2.RELEASE pom.xml 时给了我以下错误。
项目构建错误:org.springframework.cloud:spring-cloud-starter-config:jar 的“dependency.dependency.version”丢失。
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-config</artifactId>
</dependency>
Run Code Online (Sandbox Code Playgroud) 我正在尝试将 Spring Cloud Gateway 与 Spring Security 结合使用。但不幸的是,看起来安全性并不重要,所有请求都经过其目的地,或者至少尝试经过。只是尝试一下,因为我每次都会收到 HTTP 状态 503。我在 Spring 5,并尝试尽可能地“反应”。我究竟做错了什么?当服务尝试使用功能区负载平衡查找目的地时,日志中没有任何有趣的内容,只有常见的行。我还启用了网关服务器上的访问日志,希望能得到一些额外的信息,但什么也没有。
我已经简化了我的代码,这是不起作用的最小配置。
POM依赖和依赖管理:
<dependencies>
<!-- Spring Cloud Gateway service -->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-gateway</artifactId>
</dependency>
<!-- Spring Cloud Eureka client -->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
</dependency>
<!-- Spring Cloud config client -->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-config-client</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-webflux</artifactId>
<exclusions>
<exclusion>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-logging</artifactId>
</exclusion>
</exclusions>
</dependency>
<!-- Spring Security -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
</dependency>
</dependencies>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-dependencies</artifactId>
<version>${spring-cloud.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
Run Code Online (Sandbox Code Playgroud)
bootstrap.yml:
spring:
application:
name: …Run Code Online (Sandbox Code Playgroud) spring-cloud ×10
spring ×5
java ×3
netflix-zuul ×3
hystrix ×2
amazon-sqs ×1
encryption ×1
spring-boot ×1
spring-mvc ×1