我有三个微型服务。
1.discoveryserver 2.api网关(使用spring cloud api),端口号为8081 3.userservice
我在usermicroservice中为用户登录操作编码。然后我用“http://localhost:8081/login“用于登录,工作正常
当我更改登录的自定义url时(http://localhost:8081/user/login),我得到404错误。如果我使用usermicroservice端口号登录,它工作正常。如果我使用api网关端口号,则它不工作。
如果我删除“spring.cloud.gateway.routes[1].filters[0]=removerequestheader=cookie”,它将正常工作。
我想知道为什么会这样。
usermicroservice中的AuthenticationFilter.java
private AuthenticationFilter getAuthenticationFilter() throws Exception
{
AuthenticationFilter authenticationFilter = new AuthenticationFilter(userService,environment,authenticationManager());
//authenticationFilter.setAuthenticationManager(authenticationManager());
authenticationFilter.setFilterProcessesUrl("/user/login");
return authenticationFilter;
}
应用程序属性(api网关)
server.port=8081
spring.application.name=apiGateway
eureka.client.service-url.defaultZone=http://localhost:8261/eureka
spring.cloud.gateway.routes[0].id=user-check
spring.cloud.gateway.routes[0].uri=lb://user-ws
spring.cloud.gateway.routes[0].predicates[0]=Path=/users/check
spring.cloud.gateway.routes[0].predicates[1]=Method=GET
spring.cloud.gateway.routes[0].filters[0]=RemoveRequestHeader=cookie
spring.cloud.gateway.routes[1].id=user-create
spring.cloud.gateway.routes[1].uri=lb://user-ws
spring.cloud.gateway.routes[1].predicates[0]=Path=/users
spring.cloud.gateway.routes[1].predicates[1]=Method=POST
spring.cloud.gateway.routes[1].filters[0]=RemoveRequestHeader=cookie
spring.cloud.gateway.routes[2].id=user-login
spring.cloud.gateway.routes[2].uri=lb://user-ws
spring.cloud.gateway.routes[2].predicates[0]=Path=/user/login
spring.cloud.gateway.routes[2].predicates[1]=Method=POST
spring.cloud.gateway.routes[2].filters[0]=RemoveRequestHeader=cookie
application.properties(usermicroservice)
server.port=${PORT:0}
spring.application.name=user-ws
eureka.client.service-url.defaultZone=http://localhost:8261/eureka
spring.devtools.restart.enabled=true
eureka.instance.instance-id=${spring.application.name}:${spring.application.instance_id:${random.value}}
spring.h2.console.enabled=true
spring.jpa.show-sql=true
spring.h2.console.settings.web-allow-others=true
spring.h2.console.path=/h2
spring.datasource.url=jdbc:h2:mem:testdb
spring.datasource.driver-class-name=org.h2.Driver
spring.jpa.hibernate.ddl-auto=update
token.expiration.date=8765400000
token.secret=hgftyt757687686868
提前谢谢
暂无答案!
目前还没有任何答案,快来回答吧!