在非HAL / REST世界中,这非常简单:
似乎JPA / REST模块的作者已经“不知道如何在Spring中完成任务。”似乎没有办法以有意义的方式挂钩处理链。
我希望我只是缺少一些东西而且有人可以解决问题,但是在看了几天的例子并检查代码并尝试使用RestResource处理程序调用我自己的代码之后,我'我没有看到框架的设计是为了实际允许它。
指针欢迎。
答案 0 :(得分:0)
首先,我创建了自己的OpenEntityManagerInViewFilter自定义子类。这有助于系统多租户支持。
然后我使用Spring配置连接自定义子类:
@Configuration
public class WebFilterConfig {
private final Collection<String> urlPatterns;
@Autowired
@SuppressWarnings("SpringJavaAutowiringInspection")
public WebFilterConfig(@Nonnull RepositoryRestConfiguration rrconfig) {
String basePath = rrconfig.getBasePath().toString();
if (!basePath.endsWith("/")) {
basePath = basePath + "/";
}
urlPatterns = Collections.singletonList(basePath + "*");
}
@Bean
public FilterRegistrationBean openEntityManagerInViewFilterRegistration() {
FilterRegistrationBean filterRegistration = new FilterRegistrationBean(new OpenEntityManagerInViewFilter());
// Consider leaving this unset and having this filter active on all requests
filterRegistration.setUrlPatterns(urlPatterns);
// Sometimes good to have this ordered before security...
filterRegistration.setOrder(-1);
return filterRegistration;
}
// Now add out custom filter to add multi-tenant support
@Bean
public FilterRegistrationBean tenancyFilterRegistration() {
FilterRegistrationBean filterRegistration = new FilterRegistrationBean(new MultiTenantFilter());
filterRegistration.setName("tenancyDatabaseFilter");
filterRegistration.setUrlPatterns(urlPatterns);
// filterRegistration.setDispatcherTypes(EnumSet.allOf(DispatcherType.class));
// This MUST be ordered after the OpenEntityManagerInViewFilter
filterRegistration.setOrder(Ordered.LOWEST_PRECEDENCE);
// filterRegistration.setOrder(100);
return filterRegistration;
}
}