使用Spring Cloud Gateway时遇到问题
如果有任何依赖关系直接或递归调用spring-boot-starter-tomcat
它不起作用,因为它将启动嵌入式tomcat服务器而不是Spring Cloud Gateway使用的Netty服务器
我开始通过排除此依存关系来解决此问题
<exclusions>
<exclusion>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
</exclusion>
</exclusions>
Spring Cloud网关成功运行
但是有时候我想使用spring-cloud-starter-oauth2来使用@ EnableOAuth2Sso
我开始使用
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-oauth2</artifactId>
<exclusions>
<exclusion>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
</exclusion>
</exclusions>
</dependency>
当时我面临抛出异常的大问题
原因:java.lang.IllegalStateException:无法对类org.springframework.security.oauth2.config.annotation.web.configuration.OAuth2ClientConfiguration上的带注释的方法进行内省......
原因:java.lang.NoClassDefFoundError:javax / servlet / Filter
dependencies {
implementation 'org.springframework.cloud:spring-cloud-starter-gateway'
implementation 'org.springframework.cloud:spring-cloud-starter-security'
implementation 'org.springframework.boot:spring-boot-starter-oauth2-client'
}
至少对网关应用程序进行如下编码
@SpringBootApplication public class App { @Bean public ForwardedHeaderTransformer forwardedHeaderTransformer() { return new ForwardedHeaderTransformer(); } public static void main(String[] args) { SpringApplication.run(App.class, args); } }
在application.yml中配置
spring: security: oauth2: client: registration: google: client-id: XXX client-secret: YYY
[我正在积极构建将OAuth2与Docker Swarm Discovery https://github.com/trajano/spring-cloud-demo.git结合使用的堆栈,以便您了解它如何工作。
我关注了另一个使用Zuul网关的微服务示例应用程序(https://github.com/piomin/sample-spring-oauth2-microservices)。通过将@EnableResourceServer添加到微服务,致动器端点(/ health)被阻止,无法注册以进行咨询。