【发布时间】:2015-08-09 09:20:41
【问题描述】:
我正在运行一个 Spring Boot 和 Spring Security 应用程序,它现在应该获得多租户支持。
我想让事情尽可能简单。虽然我想通过路径变量或请求参数来确定数据库。 (Spring Boot 应用程序前面的 Apache Web 服务器将处理这个问题,即它从子域映射到路径变量或请求参数)。
现在我需要一种在 Spring 调用控制器之前获取第一个路径变量(或特定请求参数)的方法,当然该值必须存储在某个地方,以便在需要选择正确的数据库时访问它.
所以要么(取决于可能/更容易)
-
http://localhost:8080/customer1(我更喜欢)或 http://localhost:8080?_customer=customer1
应该简单地用@RequestMapping("") 调用@Controller 并且值customer1 应该存储在某个地方以用于该请求。
我知道2. 可能更简单,因为它已经正确地命中了@Controller,但我更喜欢1.。
谢谢!
编辑:
我刚刚意识到,HandlerInterceptor 没有按预期工作,因为 Spring Security 总是首先处理请求。虽然我需要一个拦截器在 Spring Security 启动之前处理它。
【问题讨论】:
标签: spring spring-mvc spring-security spring-boot spring-4