网关用Gateway不用zuul,加了@EnableResourceServer配置无法启动问题
来源:6-3 JWT改造之网关和服务改造
Bigger_Xu
2020-11-09
网关尝试用Gateway,然后添加配置以后,发现项目无法启动,麻烦帮我看下
cloud 是H版
boot是对应的2.2.2
pom依赖
<!--SpringCloud openfeign -->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-openfeign</artifactId>
</dependency>
<!--oauth2-->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-oauth2</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-gateway</artifactId>
</dependency>
config
@Configuration
@EnableResourceServer
public class SecurityConfig extends ResourceServerConfigurerAdapter {
@Override
public void configure(HttpSecurity http) throws Exception {
http
.authorizeRequests()
.antMatchers("/token/**").permitAll();
}
}
这是错误信息
2020-11-09 23:22:33.357 ERROR 6266 --- [ main] o.s.boot.SpringApplication : Application run failed
java.lang.TypeNotPresentException: Type javax.servlet.Filter not present
at sun.reflect.generics.factory.CoreReflectionFactory.makeNamedType(CoreReflectionFactory.java:117) ~[na:1.8.0_241]
at sun.reflect.generics.visitor.Reifier.visitClassTypeSignature(Reifier.java:125) ~[na:1.8.0_241]
at sun.reflect.generics.tree.ClassTypeSignature.accept(ClassTypeSignature.java:49) ~[na:1.8.0_241]
at sun.reflect.generics.visitor.Reifier.reifyTypeArguments(Reifier.java:68) ~[na:1.8.0_241]
at sun.reflect.generics.visitor.Reifier.visitClassTypeSignature(Reifier.java:138) ~[na:1.8.0_241]
at sun.reflect.generics.tree.ClassTypeSignature.accept(ClassTypeSignature.java:49) ~[na:1.8.0_241]
at sun.reflect.generics.repository.ClassRepository.getSuperInterfaces(ClassRepository.java:108) ~[na:1.8.0_241]
at java.lang.Class.getGenericInterfaces(Class.java:913) ~[na:1.8.0_241]
at org.springframework.core.ResolvableType.getInterfaces(ResolvableType.java:492) ~[spring-core-5.2.2.RELEASE.jar:5.2.2.RELEASE]
at org.springframework.core.ResolvableType.as(ResolvableType.java:450) ~[spring-core-5.2.2.RELEASE.jar:5.2.2.RELEASE]
at org.springframework.core.ResolvableType.as(ResolvableType.java:451) ~[spring-core-5.2.2.RELEASE.jar:5.2.2.RELEASE]
at org.springframework.core.ResolvableType.forMethodParameter(ResolvableType.java:1320) ~[spring-core-5.2.2.RELEASE.jar:5.2.2.RELEASE]
at org.springframework.core.ResolvableType.forMethodParameter(ResolvableType.java:1303) ~[spring-core-5.2.2.RELEASE.jar:5.2.2.RELEASE]
at org.springframework.core.ResolvableType.forMethodParameter(ResolvableType.java:1270) ~[spring-core-5.2.2.RELEASE.jar:5.2.2.RELEASE]
at org.springframework.core.ResolvableType.forMethodParameter(ResolvableType.java:1260) ~[spring-core-5.2.2.RELEASE.jar:5.2.2.RELEASE]
at org.springframework.core.BridgeMethodResolver.isResolvedTypeMatch(BridgeMethodResolver.java:157) ~[spring-core-5.2.2.RELEASE.jar:5.2.2.RELEASE]
at org.springframework.core.BridgeMethodResolver.isBridgeMethodFor(BridgeMethodResolver.java:141) ~[spring-core-5.2.2.RELEASE.jar:5.2.2.RELEASE]
at org.springframework.core.BridgeMethodResolver.searchCandidates(BridgeMethodResolver.java:120) ~[spring-core-5.2.2.RELEASE.jar:5.2.2.RELEASE]
at org.springframework.core.BridgeMethodResolver.findBridgedMethod(BridgeMethodResolver.java:82) ~[spring-core-5.2.2.RELEASE.jar:5.2.2.RELEASE]
at org.springframework.core.annotation.AnnotationsScanner.processMethodAnnotations(AnnotationsScanner.java:408) ~[spring-core-5.2.2.RELEASE.jar:5.2.2.RELEASE]
at org.springframework.core.annotation.AnnotationsScanner.processMethodHierarchy(AnnotationsScanner.java:288) ~[spring-core-5.2.2.RELEASE.jar:5.2.2.RELEASE]
at org.springframework.core.annotation.AnnotationsScanner.processMethod(AnnotationsScanner.java:258) ~[spring-core-5.2.2.RELEASE.jar:5.2.2.RELEASE]
at org.springframework.core.annotation.AnnotationsScanner.process(AnnotationsScanner.java:110) ~[spring-core-5.2.2.RELEASE.jar:5.2.2.RELEASE]
at org.springframework.core.annotation.AnnotationsScanner.scan(AnnotationsScanner.java:97) ~[spring-core-5.2.2.RELEASE.jar:5.2.2.RELEASE]
at org.springframework.core.annotation.AnnotationsScanner.scan(AnnotationsScanner.java:78) ~[spring-core-5.2.2.RELEASE.jar:5.2.2.RELEASE]
at org.springframework.core.annotation.TypeMappedAnnotations.scan(TypeMappedAnnotations.java:242) ~[spring-core-5.2.2.RELEASE.jar:5.2.2.RELEASE]
at org.springframework.core.annotation.TypeMappedAnnotations.isPresent(TypeMappedAnnotations.java:98) ~[spring-core-5.2.2.RELEASE.jar:5.2.2.RELEASE]
at org.springframework.core.annotation.AnnotatedElementUtils.hasAnnotation(AnnotatedElementUtils.java:531) ~[spring-core-5.2.2.RELEASE.jar:5.2.2.RELEASE]
at org.springframework.context.annotation.BeanAnnotationHelper.isBeanAnnotated(BeanAnnotationHelper.java:41) ~[spring-context-5.2.2.RELEASE.jar:5.2.2.RELEASE]
at org.springframework.context.annotation.ConfigurationClassEnhancer$BeanMethodInterceptor.isMatch(ConfigurationClassEnhancer.java:439) ~[spring-context-5.2.2.RELEASE.jar:5.2.2.RELEASE]
at org.springframework.context.annotation.ConfigurationClassEnhancer$ConditionalCallbackFilter.accept(ConfigurationClassEnhancer.java:192) ~[spring-context-5.2.2.RELEASE.jar:5.2.2.RELEASE]
at org.springframework.cglib.proxy.Enhancer.emitMethods(Enhancer.java:1214) ~[spring-core-5.2.2.RELEASE.jar:5.2.2.RELEASE]
at org.springframework.cglib.proxy.Enhancer.generateClass(Enhancer.java:723) ~[spring-core-5.2.2.RELEASE.jar:5.2.2.RELEASE]
at org.springframework.cglib.transform.TransformingClassGenerator.generateClass(TransformingClassGenerator.java:33) ~[spring-core-5.2.2.RELEASE.jar:5.2.2.RELEASE]
at org.springframework.cglib.core.DefaultGeneratorStrategy.generate(DefaultGeneratorStrategy.java:25) ~[spring-core-5.2.2.RELEASE.jar:5.2.2.RELEASE]
at org.springframework.context.annotation.ConfigurationClassEnhancer$BeanFactoryAwareGeneratorStrategy.generate(ConfigurationClassEnhancer.java:252) ~[spring-context-5.2.2.RELEASE.jar:5.2.2.RELEASE]
at org.springframework.cglib.core.AbstractClassGenerator.generate(AbstractClassGenerator.java:358) ~[spring-core-5.2.2.RELEASE.jar:5.2.2.RELEASE]
at org.springframework.cglib.proxy.Enhancer.generate(Enhancer.java:582) ~[spring-core-5.2.2.RELEASE.jar:5.2.2.RELEASE]
at org.springframework.cglib.core.AbstractClassGenerator$ClassLoaderData$3.apply(AbstractClassGenerator.java:110) ~[spring-core-5.2.2.RELEASE.jar:5.2.2.RELEASE]
at org.springframework.cglib.core.AbstractClassGenerator$ClassLoaderData$3.apply(AbstractClassGenerator.java:108) ~[spring-core-5.2.2.RELEASE.jar:5.2.2.RELEASE]
at org.springframework.cglib.core.internal.LoadingCache$2.call(LoadingCache.java:54) ~[spring-core-5.2.2.RELEASE.jar:5.2.2.RELEASE]
at java.util.concurrent.FutureTask.run$$$capture(FutureTask.java:266) ~[na:1.8.0_241]
at java.util.concurrent.FutureTask.run(FutureTask.java) ~[na:1.8.0_241]
at org.springframework.cglib.core.internal.LoadingCache.createEntry(LoadingCache.java:61) ~[spring-core-5.2.2.RELEASE.jar:5.2.2.RELEASE]
at org.springframework.cglib.core.internal.LoadingCache.get(LoadingCache.java:34) ~[spring-core-5.2.2.RELEASE.jar:5.2.2.RELEASE]
at org.springframework.cglib.core.AbstractClassGenerator$ClassLoaderData.get(AbstractClassGenerator.java:134) ~[spring-core-5.2.2.RELEASE.jar:5.2.2.RELEASE]
at org.springframework.cglib.core.AbstractClassGenerator.create(AbstractClassGenerator.java:319) ~[spring-core-5.2.2.RELEASE.jar:5.2.2.RELEASE]
at org.springframework.cglib.proxy.Enhancer.createHelper(Enhancer.java:569) ~[spring-core-5.2.2.RELEASE.jar:5.2.2.RELEASE]
at org.springframework.cglib.proxy.Enhancer.createClass(Enhancer.java:416) ~[spring-core-5.2.2.RELEASE.jar:5.2.2.RELEASE]
at org.springframework.context.annotation.ConfigurationClassEnhancer.createClass(ConfigurationClassEnhancer.java:137) ~[spring-context-5.2.2.RELEASE.jar:5.2.2.RELEASE]
at org.springframework.context.annotation.ConfigurationClassEnhancer.enhance(ConfigurationClassEnhancer.java:109) ~[spring-context-5.2.2.RELEASE.jar:5.2.2.RELEASE]
at org.springframework.context.annotation.ConfigurationClassPostProcessor.enhanceConfigurationClasses(ConfigurationClassPostProcessor.java:429) ~[spring-context-5.2.2.RELEASE.jar:5.2.2.RELEASE]
at org.springframework.context.annotation.ConfigurationClassPostProcessor.postProcessBeanFactory(ConfigurationClassPostProcessor.java:263) ~[spring-context-5.2.2.RELEASE.jar:5.2.2.RELEASE]
at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanFactoryPostProcessors(PostProcessorRegistrationDelegate.java:286) ~[spring-context-5.2.2.RELEASE.jar:5.2.2.RELEASE]
at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanFactoryPostProcessors(PostProcessorRegistrationDelegate.java:130) ~[spring-context-5.2.2.RELEASE.jar:5.2.2.RELEASE]
at org.springframework.context.support.AbstractApplicationContext.invokeBeanFactoryPostProcessors(AbstractApplicationContext.java:706) ~[spring-context-5.2.2.RELEASE.jar:5.2.2.RELEASE]
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:532) ~[spring-context-5.2.2.RELEASE.jar:5.2.2.RELEASE]
at org.springframework.boot.web.reactive.context.ReactiveWebServerApplicationContext.refresh(ReactiveWebServerApplicationContext.java:66) ~[spring-boot-2.2.2.RELEASE.jar:2.2.2.RELEASE]
at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:747) [spring-boot-2.2.2.RELEASE.jar:2.2.2.RELEASE]
at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:397) [spring-boot-2.2.2.RELEASE.jar:2.2.2.RELEASE]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:315) [spring-boot-2.2.2.RELEASE.jar:2.2.2.RELEASE]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1226) [spring-boot-2.2.2.RELEASE.jar:2.2.2.RELEASE]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1215) [spring-boot-2.2.2.RELEASE.jar:2.2.2.RELEASE]
at com.cto.cloud.GatewayApplication.main(GatewayApplication.java:20) [classes/:na]
Caused by: java.lang.ClassNotFoundException: javax.servlet.Filter
at java.net.URLClassLoader.findClass(URLClassLoader.java:382) ~[na:1.8.0_241]
at java.lang.ClassLoader.loadClass(ClassLoader.java:418) ~[na:1.8.0_241]
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:355) ~[na:1.8.0_241]
at java.lang.ClassLoader.loadClass(ClassLoader.java:351) ~[na:1.8.0_241]
at java.lang.Class.forName0(Native Method) ~[na:1.8.0_241]
at java.lang.Class.forName(Class.java:348) ~[na:1.8.0_241]
at sun.reflect.generics.factory.CoreReflectionFactory.makeNamedType(CoreReflectionFactory.java:114) ~[na:1.8.0_241]
... 63 common frames omitted
写回答
1回答
-
JoJo
2020-11-30
用gateway的配置是不一样的,因为gateway是异步的。我讲课时security还不支持gateway,现在已经支持了,要自己看下文档。
10
相似问题